Reputation: 171
I want to open the default Gallery in Android device, but when I used the following code it opens "Photos" if user preference that.
Code I used,
Intent in = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
in.putExtra("crop", "true");
startActivityForResult(in, RESULT_LOAD_IMAGE);
Upvotes: 0
Views: 1752
Reputation: 109
You should have to use this code.
by this you can switch to Gallery.
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("content://media/internal/images/media"));
startActivity(intent);
Upvotes: 4
Reputation: 11
You can use the following:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"));
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
Upvotes: 0
Reputation: 10342
You can do it in a similar way I used below. You have to set Class Name
manually. This will probably won't work on older devices and future devices. The class name will definitely change.
I think they will get rid of Gallery application and just use Photos at some point.
in.setClassName("com.android.gallery3d", "com.android.gallery3d.app.Gallery");
if(isAvailable(context, in)) {
//Open it.
}
else {
//Do it the old way
}
And the isAvailable
function is
public static boolean isAvailable(Context ctx, Intent intent) {
if(ctx == null)
return false;
final PackageManager mgr = ctx.getPackageManager();
List<ResolveInfo> list =
mgr.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
Upvotes: 0
Reputation: 82948
I think setPackage(String packageName) do your task.
Example
Intent in = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
in.putExtra("crop", "true");
in.setPackage(PACKAGE_NAME_OF_GALLERY); // Make sure if it is com.android.gallery3d
startActivityForResult(in, RESULT_LOAD_IMAGE);
Upvotes: 0