這裏是我的代碼:手電筒應用程序無法連接到相機服務
我添加了一個github上許可的代碼,但它仍然崩潰
我所做的每一件事,但它崩潰每一次
我也有我的清單
parameter = camera.getParameters();
}
@Override public void onPermissionDenied(PermissionDeniedResponse response) {
Toast.makeText(getApplicationContext(), "Permission Denied", Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("App needs permission to access camera")
.setPositiveButton("Granted", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent myAppSettings = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + getPackageName()));
myAppSettings.addCategory(Intent.CATEGORY_DEFAULT);
myAppSettings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myAppSettings);
}
}).setNegativeButton("Denied", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
}).create().show();
}
@Override public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token)
{[enter image description here][1]
token.continuePermissionRequest();
}
}).check();
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
textview = (TextView) findViewById(R.id.textView);
flashLight = (ImageButton) findViewById(R.id.flash_light);
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)添加權限相機;
//askPermission(CAMERA,camera1);
flashLight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!isFlashLightOn) {
turnOnTheFlash();
} else {
turnOffTheFlash();
}
}
});
logcat的:
09-30 18:59:31.698 11339-11339/inducesmile.com.androidflashlightapp E/AndroidRuntime:致命異常:主 工藝:inducesmile.com.androidflashlightapp,PID:11339 java.lang.RuntimeException:無法恢復活動{inducesmile.com.androidflashlightapp/inducesmile.com.androidflashlightapp.MainActivity}:java.lang.RuntimeException:無法連接到攝像頭服務 at android.app.ActivityThread.performResumeActivity(ActivityThread .java:3506) android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3546) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2795) app.ActivityThread $ H.handleMessage(ActivityThread.java:1527) 在android.os.Handler.dispatchMessage(Handler.java:110) 在android.os.Looper.loop(Looper.java:203) 的機器人。 app.ActivityThread.main(ActivityThread.java:6251) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit .java:1073) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934) 引起:java.lang.RuntimeException:無法連接到相機服務 at android.hardware.Camera。( Camera.java:647) 在android.hardware.Camera.open(Camera.java:510) 在inducesmile.com.androidflashlightapp.MainActivity.turnOffTheFlash(MainActivity.java:105) 在inducesmile.com.androidflashlightapp.MainActivity。 onResume(MainActivity.java:165) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1269) at android.app.Activity.performResume(Activity.java:6791) 在android.app.ActivityThread.performResumeActivity(ActivityThread.java:3477) 在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3546) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2795) 在android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1527) at android.os.Handler.dispatchMessage(Handler.java:110) at android .os.Looper.loop(Looper.java:203) at android.app.ActivityThread.main(ActivityThread.java:6251) 在java.lang.reflect。Method.invoke(Native Method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1073) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934) 09-30 18:59:31.804 11339-11347/inducesmile.com.androidflashlightapp I/art:輸入while循環。
請應用程式end Logcat –
編輯問題時有格式化工具可用。沒有正確的格式化,很難閱讀logcat。 – jdv
其中有許多潛在的重複:https://stackoverflow.com/q/26305107/1531971這些類似的問題對你來說有何不同? – jdv