Reputation: 121
Is there has a way to know which app(packageName or label) user use to capture,when I call capture intent
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE)
for example: com.google.camera
Upvotes: 0
Views: 70
Reputation: 96
You can obtain the answer only if there are 1 such app or the user selected the default app for this intent.
For obtain list of apps which support this intent:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, 0);
So if this list contains only 1 app then you will have the required ResolveInfo.
For obtain app which was selected as default by the user:
ResolveInfo defaultInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
This can be null if nothing selected.
If you have ResolveInfo then you can obtain the packageName and app name:
String packageName = resolveInfo.activityInfo.packageName;
String appName = resolveInfo.loadLabel(getPackageManager()).toString();
Upvotes: 0
Reputation: 431
Photos taken by the ACTION_IMAGE_CAPTURE are not registered in the MediaStore automatically on all devices.
The official Android guide gives that example: http://developer.android.com/guide/topics/media/camera.html#intent-receive But that does not work either on all devices.
The only reliable method I am aware of consists in saving the path to the picture in a local variable. Beware that your app may get killed while in background (while the camera app is running), so you must save the path during onSaveInstanceState.
Edit after comment:
Create a temporary file name where the photo will be stored when starting the intent.
File tempFile = File.createTempFile("my_app", ".jpg");
fileName = tempFile.getAbsolutePath();
Uri uri = Uri.fromFile(tempFile);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, PICTURE_REQUEST_CODE);
fileName is a String, a field of your activity. You must save it that way:
@Override
public void onSaveInstanceState(Bundle bundle)
{
super.onSaveInstanceState(bundle);
bundle.putString("fileName", fileName);
}
and recover it in onCreate():
public void onCreate(Bundle savedInstanceState)
{
if (savedInstanceState != null)
fileName = savedInstanceState.getString("fileName");
// ...
}
Upvotes: 1
Reputation:
Here it is
Intent intent = getPackageManager().getLaunchIntentForPackage("package name") // package name, e.g : com.google.camera
startActivity(intent)
You can open another application this way
Upvotes: 0