Launch default camera app (no return)

拈花ヽ惹草 提交于 2019-12-28 04:08:16

问题


I'd like to launch the default camera, but want it to act like it was started from the launcher (i.e. the resulting picture should be stored by the camera app to the user's gallery, rather than being returned to my app). If I use Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);, the camera app uses the "OK? Retry?"-UI and doesn't save the picture. I'd rather not use a "direct" com.android.camera intent, because a lot of devices use custom camera apps. I've seen that the stock gallery3d-app uses an alias implementing com.android.camera/.Camera, but I'm not sure that every pre-loaded manufacturer camera app does this.


回答1:


I've now implemented it like this:

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); 
}



回答2:


This code will do the trick:

Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
context.startActivity(intent);


来源:https://stackoverflow.com/questions/18599421/launch-default-camera-app-no-return

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!