强制使用棉花糖设备代号

时间:2017-02-19 04:52:34

标签: codenameone

我创建了一个NativeTest.java

1.code:

import com.codename1.system.NativeInterface;

public interface NativeTest extends NativeInterface{
    public void dispatchTakePictureIntent();    
}
  1. 生成了原生接口

  2. 在native \ android \ pathToNativeiImpl

  3. NativeTestImpl.java代码:

    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;
        }
    }
    

    天然\ JavaSE的\ COM \联想\ capitaleyenepal \ NativeTestImpl.java

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

    仍然没有强制许可,我如何强制使用相机的权限?

    添加本机代码后构建错误:

        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.
    

0 个答案:

没有答案