I have to select a file and send to server. The following code I am using
Gallery Intent to pick a file.
Intent intent = new Intent();
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Select Image"), REQUEST_CODE);
OnActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
if (data != null) {
Uri selectedImageUri = data.getData();
// GET IMAGE PATH
imagePath = getPath(selectedImageUri);
Log.d("", "Image path : " + imagePath);
// IMAGE NAME
imageName = imagePath.substring(imagePath.lastIndexOf("/"));
imageSize = this.getFileSize(imagePath);
// DECODE TO BITMAP
// Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
// DISPLAY IMAGE
// imageView.setImageBitmap(bitmap);
imageLocationTextView.setText("File path :" + imagePath);
}
}
}
If i change this line to
intent.setType("image/*");
To this
intent.setType("*/*");
I get error at onActivityResult
11-30 14:45:24.389: E/AndroidRuntime(3126): java.lang.RuntimeException: Failure delivering result
ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.externalstorage.documents/document/0BEE-381E:splash.jpg flg=0x1 }}
to activity {shane.atom/shane.atom.MainActivity}: java.lang.NullPointerException:
Attempt to invoke virtual method 'int java.lang.String.lastIndexOf(java.lang.String)'
on a null object reference
I upload image scussefully to the server but when i try to upload file to server i failed. Please help suggest any solution.
Thanks in Advance.