【问题标题】:Codename one marshmallow authorization代号一棉花糖授权
【发布时间】:2017-08-08 21:09:42
【问题描述】:

我正在尝试在 Android 上获取相机和微权限。我在 codenameone_library_required.properties 文件中添加了:

android.xpermissions=<uses-permission android:name="android.permission.CAMERA" android:required="true"/> <uses-permission android:name="android.permission.RECORD_AUDIO" android:required="true"/> <uses-permission android:name="android.permission.INTERNET" android:required="true"/>

这适用于旧版本的 Android,但不适用于 Marshmallow。因此,我阅读了代号一个开发人员指南,在以后的 android 版本中请求权限,我必须以 sdk 23 为目标。事实上,我在构建提示中添加了:

android.targetSDKVersion=23

但不幸的是,这还不够,当我启动应用程序时,它不会请求权限。

我应该添加一些东西来请求权限吗?也许是“Display.getInstance().setProperty(...)”?

提前感谢您!

【问题讨论】:

    标签: android codenameone opentok


    【解决方案1】:

    如果我真的理解你的问题,你应该像这样在运行时(android Marshmallow 及更高版本)请求相机权限:

    //to check if the user grant the permission before
    if(ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
    
        //if it is not the case, request new permission
        ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CAMERA},requestCode);
        return;
    }
    
    //your camera code is here 
    

    在 Codename One 的情况下,正如 @mina 所说,你找不到 ActivityCompat 类,所以试试这段代码:

    if(!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.READ_PHONE_STATE, "This should be the description shown to the user...")){
    
    // you didn't get the permission, you might want to return here
    }
    // you have the permission, do what you need
    

    【讨论】:

    • 我认为我无法从代号 1 访问 ActivityCompat,但我可能错了。
    • 试试这个link
    • 是的,它也包含在开发者指南中
    猜你喜欢
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多