简体   繁体   English

Android - 单击时菜单项崩溃(相机意图)

[英]Android - Menu Item Crashing on Click (Camera Intent)

I have a menu item that uses a camera intent.我有一个使用相机意图的菜单项。 But whenever it is clicked, it crashes.但是每当它被点击时,它就会崩溃。 I tested it with several different methods of camera intents, and they all caused crashes.我用几种不同的相机意图方法对其进行了测试,它们都导致了崩溃。 The code is in the link below (as StackOverflow was acting strange when I try to directly insert Java code)代码在下面的链接中(因为 StackOverflow 在我尝试直接插入 Java 代码时表现得很奇怪)

MainActivity/CameraIntent: https://gist.github.com/VirusThePanda/2c99048977c16f7e1ffa MainActivity/CameraIntent: https ://gist.github.com/VirusThePanda/2c99048977c16f7e1ffa

LogCat: https://gist.github.com/VirusThePanda/66a13a58674fdacea224 LogCat: https : //gist.github.com/VirusThePanda/66a13a58674fdacea224

Menu:菜单:

 <item
        android:id="@+id/photo"
        android:icon="@drawable/ic_photo"
        android:title="Take Photo"
        android:onClick="phototake"
        app:showAsAction="ifRoom" />

Please note that the MainActivity and Menu is not the full file.请注意 MainActivity 和 Menu 不是完整文件。 Just the important parts for this question.只是这个问题的重要部分。

Your error log shows you have SecurityException: Permission Denial...with revoked permission android.permission.CAMERA.您的错误日志显示您有 SecurityException: Permission Denial...with revoked permission android.permission.CAMERA。 This means you are targetting API level 23 and the user has revoked the CAMERA permission.这意味着您的目标是 API 级别 23,并且用户已撤销 CAMERA 权限。 You should add code to check and request permission and handle permission acceptance/denial.您应该添加代码来检查和请求权限并处理权限接受/拒绝。 Read more about it here . 在此处阅读更多相关信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM