Forcing permission in marshmallow devices codenameone

依然范特西╮ 提交于 2019-12-22 18:12:07

问题


I have created a NativeTest.java

1.code:

import com.codename1.system.NativeInterface;

public interface NativeTest extends NativeInterface{
    public void dispatchTakePictureIntent();    
}
  1. generated the native interfaces

  2. inside native\android\pathToNativeiImpl

NativeTestImpl.java code:

public class NativeTestImpl {
    static final int REQUEST_IMAGE_CAPTURE = 1;


    public void dispatchTakePictureIntent() {
        if(!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.READ_PHONE_STATE, "App requires camera permission for scanner")){
         // you didn't get the permission, you might want to return here

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }
        }
      }


    public boolean isSupported() {
        return true;
    }
}

native\javase\com\lenovo\capitaleyenepal\NativeTestImpl.java

public class NativeTestImpl implements com.lenovo.capitaleyenepal.NativeTest{
    public boolean isSupported() {
        return true;
    }

    @Override
    public void dispatchTakePictureIntent() {
    }


}

Still it is not forcing the permission, how can I force the permission for using camera?

Build error after adding native code:

    Compiling with source level 1.7 and target level 1.7.
:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
file or directory '/tmp/build8873426072869291288xxx/Lenovo/src/debug/java', not found
Compiling with JDK Java compiler API.
/tmp/build8873426072869291288xxx/Lenovo/src/main/java/com/lenovo/capitaleyenepal/NativeTestImpl.java:8: error: package Manifest does not exist
        if(!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.READ_PHONE_STATE, "App requires camera permission for scanner")){
                                                                                    ^
/tmp/build8873426072869291288xxx/Lenovo/src/main/java/com/lenovo/capitaleyenepal/NativeTestImpl.java:11: error: cannot find symbol
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            ^
  symbol:   class Intent
  location: class NativeTestImpl
/tmp/build8873426072869291288xxx/Lenovo/src/main/java/com/lenovo/capitaleyenepal/NativeTestImpl.java:11: error: cannot find symbol
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                           ^
  symbol:   class Intent
  location: class NativeTestImpl
/tmp/build8873426072869291288xxx/Lenovo/src/main/java/com/lenovo/capitaleyenepal/NativeTestImpl.java:11: error: cannot find symbol
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                                  ^
  symbol:   variable MediaStore
  location: class NativeTestImpl
/tmp/build8873426072869291288xxx/Lenovo/src/main/java/com/lenovo/capitaleyenepal/NativeTestImpl.java:12: error: cannot find symbol
            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                                                  ^
  symbol:   method getPackageManager()
  location: class NativeTestImpl
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

来源:https://stackoverflow.com/questions/42323772/forcing-permission-in-marshmallow-devices-codenameone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!