0
以下是我試圖直接打開Android Default Camera的代碼。它適用於大多數設備,如果安裝了其他相機應用程序,則可以在不創建選配器的情況下打開默認相機。Android相機問題(特定於設備)
private void callTheCamera(){
String pkgName = "";
PackageManager pm = getPackageManager();
List<ApplicationInfo> installedApps = pm.getInstalledApplications(0);
for (ApplicationInfo ai: installedApps) {
if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
// System app - do something here
if(ai.toString().toLowerCase().contains("camera")){
pkgName = ai.packageName;
}
} else {
// User installed app?
}
}
if(!pkgName.equals("")){
try {
Intent LaunchIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
LaunchIntent.setPackage(pkgName);
LaunchIntent.putExtra(MediaStore.EXTRA_OUTPUT, setImageUri());
startActivityForResult(LaunchIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
} catch (Exception e) {
e.printStackTrace();
Intent LaunchIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
LaunchIntent.putExtra(MediaStore.EXTRA_OUTPUT, setImageUri());
startActivityForResult(LaunchIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
}
else{
Intent LaunchIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
LaunchIntent.putExtra(MediaStore.EXTRA_OUTPUT, setImageUri());
startActivityForResult(LaunchIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
}
然而,應用程序崩潰的幾臺設備具有以下問題:
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.media.action.IMAGE_CAPTURE pkg=com.sonymobile.android.addoncamera.timeshift (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1638)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1430)
at android.app.Activity.startActivityForResult(Activity.java:3457)
at android.app.Activity.startActivityForResult(Activity.java:3418)
at android.support.v4.app.FragmentActivity.startActivityForResult(SourceFile:784)
at com.goldvip.crownit.BasicCameraActivity.callTheCamera(SourceFile:674)
at com.goldvip.crownit.BasicCameraActivity.access$000(SourceFile:60)
at com.goldvip.crownit.BasicCameraActivity$2.run(SourceFile:136)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5398)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:940)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
at dalvik.system.NativeStart.main(NativeStart.java)
現在,如何有效地解決這個??。
哪個操作系統版本? – Riser
它分散在Android OS 4,5和... – asdec90
什麼是setImageUri()。 ? – Riser