我希望用户能够在我的应用中快速打开默认的相机应用(或他们设置为默认设置)。但是,我不想使用android.media.action.IMAGE_CAPTURE,因为这只会显示应用程序的拍照部分。我只想打开相机应用程序而不使用它。我知道这是可能的,因为我使用的几个画廊应用程序(大多数notibale:Focus)只能简单地打开相机应用程序而没有问题,并且没有使用IMAGE_CAPTURE。
答案 0 :(得分:3)
这可以通过PackageManager#resolveActivity(Intent)
在Kotlin:
val info: ResolveInfo? = packageManager
.resolveActivity(cameraIntent);
if (info == null) {
// No camera app installed.
return
}
// Documentation says at least one of the three infos is not-null:
val app: ApplicationInfo = info.activityInfo?.applicationInfo
?: info.serviceInfo?.applicationInfo
?: info.providerInfo!!.applicationInfo
val launch: Intent? = packageManager
.getLaunchIntentForPackage(app.packageName)
if (launch == null) {
// Camera app has no default intent.
return
}
// Launch the camera intent's
// resolved app's default activity.
context.startActivity(launch)
(其中cameraIntent
是使用android.media.action.IMAGE_CAPTURE
过滤器创建的意图,context
是当前应用上下文,packageManager
是上下文PackageManager
实例。)
答案 1 :(得分:1)
如果您只想打开默认相机应用,请使用以下代码
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivity(
getPackageManager().getLaunchIntentForPackage(
intent.resolveActivity(getPackageManager()).getPackageName()));
答案 2 :(得分:0)
String intentpackage;
List<ApplicationInfo> list = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
for (int a=0;a<list.size();a++) {
if((list.get(n).flags & ApplicationInfo.FLAG_SYSTEM)==1)
{
Log.d("TAG", "Installed Applications : " + list.get(a).loadLabel(packageManager).toString());
Log.d("TAG", "package name : " + list.get(a).packageName);
if(list.get(a).loadLabel(packageManager).toString().equalsIgnoreCase("Camera")) {
intentpackage = list.get(a).packageName;
break;
}
}
}
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(defaultCameraPackage!=null){
cameraIntent.setPackage(intentpackage);
}
startActivityForResult(cameraIntent, 1);