问题
I have created a NativeTest.java
1.code:
import com.codename1.system.NativeInterface;
public interface NativeTest extends NativeInterface{
public void dispatchTakePictureIntent();
}
generated the native interfaces
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