2013-07-12 7 views
2

Je voudrais ajouter un serveur web à mon application Android pour télécharger de petits fichiers sur le téléphone.serveur web pour le téléchargement de fichiers sur android

L'utilisateur démarrerait le serveur Web à partir du téléphone en appuyant sur un bouton. Il verrait alors une adresse IP qui peut être accessible par n'importe quel navigateur à partir d'un PC. Le site Web derrière cette adresse IP doit afficher une opportunité de téléchargement de fichier.

Ma question est: Existe-t-il un projet open source similaire à mes besoins? Ou comment recommanderiez-vous de faire cela?

+1

isnt que ce WebDAV fait déjà? .. Pourquoi auriez-vous besoin d'une autre copie. – Doomsknight

+0

a vissé quelque chose là-haut. Je vous remercie. – Gizmo

+0

besoin de votre aide pour sortir de question interdire upvote ce http://www.stackoverflow.com/questions/18403488/cannot-connect-to-my-android-phone s'il vous plaît – Prakhar

Répondre

2

vous pouvez utiliser NanoHttpd link il est très poids serveur web android qui est bien embbedible ..

package .....; 

import java.io.IOException; 
import java.util.Map.Entry; 
import java.util.Properties; 

import android.app.Activity; 
import android.net.wifi.WifiManager; 
import android.os.Bundle; 
import android.os.Handler; 
import android.widget.TextView; 

public class AndroidWebServerActivity extends Activity { 
private static final int PORT = 8765; 
private TextView hello; 
private MyHTTPD server; 
private Handler handler = new Handler(); 

@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 

} 

@Override 
protected void onResume() { 
super.onResume(); 

try { 
server = new MyHTTPD(); 
} catch (IOException e) { 
e.printStackTrace(); 
} 
} 

@Override 
protected void onPause() { 
super.onPause(); 
if (server != null) 
server.stop(); 
} 

private class MyHTTPD extends NanoHTTPD { 
public MyHTTPD() throws IOException { 
super(PORT, null); 
} 

@Override 
public Response serve(String uri, String method, Properties header, Properties parms, Properties files) { 
final StringBuilder buf = new StringBuilder(); 
for (Entry<Object, Object> kv : header.entrySet()) 
buf.append(kv.getKey() + " : " + kv.getValue() + "\n"); 
handler.post(new Runnable() { 
@Override 
public void run() { 

} 
}); 

final String html = "<html><head><head><body><h1>Hello, World</h1></body></html>"; 
return new NanoHTTPD.Response(HTTP_OK, MIME_HTML, html); 
} 
} 
} 
Questions connexes