Nije pametno raditi, prvo sto je nesigurno, a drugo sto je nestabilno, ne znas sta ce sve wifi ruteri da blokiraju.
HTTP ce da radi svugde tako da je njega najbolje koristiti.
Mozes i da napises svoj jednostavan API koji ce da se spaja na bazu i tebi prosledjuje te podatke.
U principu svede se na to da napravis web stranu u script jeziku po izboru( php, .NET, python.. )
Prihvatas POST/GET parametre a na izlaz saljes xml ili JSON, kako ti je lakse.
Sto se slika tice, njih samo posaljes link pa dohvatis, evo ti moja funkcija koju koristim u jednoj aplikaciju da dohvatim Bitmap objekat iz URL-a. Samo sto ova funkcija radi kesiranje na karticu slike, malo je specifican slucaj ali mozes da izbacis sto ti ne treba. Ova funkcija prvo proveri da li je slika na kartici, pa ako nije onda je tek skida sa inerneta. Ti mozes da izbacis sve to.
Code:
public static Bitmap getBitmapFromUrl(String url, String imageName, int module, int topic) {
if (url == null) {
return null;
}
File SDCardRoot = Environment.getExternalStorageDirectory();
Bitmap bm = BitmapFactory.decodeFile(SDCardRoot.toString()+SDCARD_PHOTOS_FOLDER+"/"+module+"/"+topic+"/"+imageName);
if(bm!=null) {
return bm;
}
HttpGet httpGet = null;
httpGet = new HttpGet(URI.create(url + imageName));
HttpClient httpClient = getThreadSafeClient();
try {
HttpResponse response = (HttpResponse) httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream inputStream = bufHttpEntity.getContent();
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
if (bitmap == null) {
return null;
}
File dir = new File(SDCardRoot.toString()+SDCARD_PHOTOS_FOLDER+"/"+module+"/"+topic);
dir.mkdirs();
File file = new File(dir,imageName);
FileOutputStream fileOutput = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, fileOutput);
//close the output stream when done
fileOutput.flush();
fileOutput.close();
getDatabaseUtilities().setPhotoDownlaoded(imageName, true);
return bitmap;
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
A ovde i funkcija getThreadSafeClient(); koja vraca Thread safe http client.
Code:
public static DefaultHttpClient getThreadSafeClient() {
DefaultHttpClient client = new DefaultHttpClient();
ClientConnectionManager mgr = client.getConnectionManager();
HttpParams params = client.getParams();
client = new DefaultHttpClient(new ThreadSafeClientConnManager(params,
mgr.getSchemeRegistry()), params);
return client;
}