启动默认相机应用程序(不返回)

问题描述 投票:11回答:2

我想启动默认摄像头,但希望它像从启动器启动一样(即结果图片应该由相机应用程序存储到用户的图库,而不是返回到我的应用程序)。如果我使用Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);,相机应用程序使用“OK?Retry?” - UI并且不保存图片。我宁愿不使用“直接”com.android.camera意图,因为很多设备使用自定义相机应用程序。我已经看到库存gallery3d-app使用实现com.android.camera/.Camera的别名,但我不确定每个预装的制造商相机应用程序都这样做。

android android-camera android-camera-intent
2个回答
13
投票

我现在已经实现了这样:

Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
    PackageManager pm = mContext.getPackageManager();

    final ResolveInfo mInfo = pm.resolveActivity(i, 0);

    Intent intent = new Intent();
    intent.setComponent(new ComponentName(mInfo.activityInfo.packageName, mInfo.activityInfo.name));
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(intent); 
} catch (Exception e){ 
    Log.i(TAG, "Unable to launch camera: " + e); 
}

10
投票

这段代码可以解决问题:

Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
context.startActivity(intent);
© www.soinside.com 2019 - 2024. All rights reserved.