Greetings,
I'm trying to upload an image on my Android device.
I have the following code which causes the image picker to come up and examine the SD card (which is what I want).
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
But what do I do next? Is there some class I can override to handle the image that was clicked on? I've tried googling but can't find anything. I hope someone can point me in the right direction.
Tried taking willytate's advice, but now I keep getting the following error:
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): FATAL EXCEPTION: WebViewCoreThread
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): java.lang.NullPointerException
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): at android.app.Activity.startActivityForResult(Activity.java:2890)
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): at prestocab.driver.Main$Uploader.upload(Main.java:172)
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): at android.webkit.WebViewCore.nativeTouchUp(Native Method)
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): at android.webkit.WebViewCore.access$3300(WebViewCore.java:66)
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1226)
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): at android.os.Looper.loop(Looper.java:143)
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:642)
02-08 16:58:01.574: ERROR/AndroidRuntime(16962): at java.lang.Thread.run(Thread.java:1102)
Here is my class:
public class Uploader extends Activity{ //uploader
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
public void upload(){
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent,0);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
String selectedImagePath = data.getDataString();
Toast.makeText(Main.this, selectedImagePath, 2000);
}
}
}
Many thanks in advance,