Still new to android/java dev but getting there, I have created a class that uploads an image to a php server but the image is currently hardcoded, I want to take it a step further now by selecting an image from gallery and then uploading it.
I am not sure how to use onActivityResult() and pass the results to a class? Hope you can help.
The onClick event is on profile.java and the upload script is on ImageUpload.java, so need to get the result from profile to ImageUpload
Also, how would I change the below to the correct code?
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream); //compress to which format you want.
byte [] byte_arr = stream.toByteArray();
String image_str = Base64.encodeBytes(byte_arr);
final ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",image_str));
nameValuePairs.add(new BasicNameValuePair("username",IMService.USERNAME));
Thread t = new Thread(new Runnable() {
public void run() {
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://127.0.0.1/upimage.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
final String the_string_response = convertResponseToString(response);
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(UserProfile.this, "Response " + the_string_response, Toast.LENGTH_LONG).show();
}
});
}catch(final Exception e){
System.out.println("Error in http connection "+e.toString());
}
}