CAMARA_REQUEST在启动startActivityForResult时导致应用程序崩溃

时间:2016-08-06 00:26:50

标签: android android-intent android-activity

我正在尝试启动相机活动,并通过Uri将结果发送回父活动。当我尝试通过按钮启动活动时,只要按下按钮,程序就会崩溃。

public class First_Page extends AppCompatActivity {

    public static final int CAMERA_REQUEST = 10;
    private Uri imageUri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first__page);
    }

    public void cameraClicked(View view){
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        startActivityForResult(intent, CAMERA_REQUEST);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(resultCode == RESULT_OK && resultCode == CAMERA_REQUEST){
            imageUri = data.getData();
        }
    }
}

这是logcat:

08-05 01:41:51.857 16089-16089/skript.com.tribaltattoo E/AndroidRuntime: FATAL EXCEPTION: main
                                                                     Process: skript.com.tribaltattoo, PID: 16089
                                                                     java.lang.IllegalStateException: Could not execute method for android:onClick
                                                                         at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                                                                         at android.view.View.performClick(View.java:5198)
                                                                         at android.view.View$PerformClick.run(View.java:21147)
                                                                         at android.os.Handler.handleCallback(Handler.java:739)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                      Caused by: java.lang.reflect.InvocationTargetException
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                                                                         at android.view.View.performClick(View.java:5198) 
                                                                         at android.view.View$PerformClick.run(View.java:21147) 
                                                                         at android.os.Handler.handleCallback(Handler.java:739) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                         at android.os.Looper.loop(Looper.java:148) 
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                      Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE cmp=com.android.camera/.Camera (has extras) } from ProcessRecord{16ab3ff 16089:skript.com.tribaltattoo/u0a57} (pid=16089, uid=10057) with revoked permission android.permission.CAMERA
                                                                         at android.os.Parcel.readException(Parcel.java:1599)
                                                                         at android.os.Parcel.readException(Parcel.java:1552)
                                                                         at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2658)
                                                                         at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
                                                                         at android.app.Activity.startActivityForResult(Activity.java:3917)
                                                                         at android.app.Activity.startActivityForResult(Activity.java:3877)
                                                                         at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)
                                                                         at skript.com.tribaltattoo.First_Page.cameraClicked(First_Page.java:39)
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
                                                                         at android.view.View.performClick(View.java:5198) 
                                                                         at android.view.View$PerformClick.run(View.java:21147) 
                                                                         at android.os.Handler.handleCallback(Handler.java:739) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                         at android.os.Looper.loop(Looper.java:148) 
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

其他信息: Android清单包括:

  uses-permission android:name="android.permission.CAMERA"

1 个答案:

答案 0 :(得分:1)

我在桌面上使用Android模拟器来运行该软件。显然这导致了这个问题,因为如果我在我的设备上运行它,它可以很好地工作。显然,模拟器无法处理相机。