, . startActivityForResult , ,
public void onClick(View v) {
Intent pickPhoto = new Intent(Intent.ACTION_GET_CONTENT);
pickPhoto.setType("*/*");
String[] mimetypes = {"image/*", "video/*"};
pickPhoto.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(pickPhoto, 1);
it's the same as yours
and in OnActivityResult I did not add any conditions. Easiest is
public void onActivityResult(int i,int j, Intent intent) {
super.onActivityResult(i, j, intent);
}
and when I debug the value in intention, I got the following: when the image is selected
Intent { dat=content://com.android.providers.media.documents/document/image:211660 flg=0x1 }
and when choosing a video
Intent { dat=content://com.android.providers.media.documents/document/video:169729 flg=0x1 }
Here you can see that it is easy to identify what is selected. No work required for this.
source
share