cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Filip Maj (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-13026) java.lang.NoSuchMethodError: No virtual method requestPermissions([Ljava/lang/String;I)V in class Landroid/app/Activity
Date Thu, 27 Jul 2017 22:03:00 GMT

    [ https://issues.apache.org/jira/browse/CB-13026?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16103988#comment-16103988
] 

Filip Maj commented on CB-13026:
--------------------------------

Linking this up to CB-12730, as we are looking at integrating cordova-plugin-compat into cordova-android
anyways. It looks like there may be some additional work to consolidate the way plugins request
permissions in cordova-android.

> java.lang.NoSuchMethodError: No virtual method requestPermissions([Ljava/lang/String;I)V
in class Landroid/app/Activity
> -----------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-13026
>                 URL: https://issues.apache.org/jira/browse/CB-13026
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-android
>    Affects Versions: cordova@7.0.0
>            Reporter: Alex B.
>            Assignee: Joe Bowser
>              Labels: bug
>             Fix For: 7.0.0
>
>
> h3. The problem
> Problem reproduced on Android 5.1.1 (API level 22), on all my devices which below API
level 23 
> Problematic part of code
> {code:java}
> public class HelloWorldBridge extends CordovaPlugin {
>     String [] permissions = {
>             Manifest.permission.CALL_PHONE,
>             Manifest.permission.INSTALL_SHORTCUT };
>     private static int REQUEST_CODE_PERMISSION = 0;
>     @Override protected void pluginInitialize() {
>         onStart();
>     }
>     @Override public void onStart() {
>         cordova.requestPermissions(this, REQUEST_CODE_PERMISSION, permissions);
>     }
>     @Override public void onNewIntent(Intent intent) {
>         cordova.getActivity().setIntent(intent);
>     }
>     @Override
>     public void onRequestPermissionResult(int requestCode, String[] permissions, int[]
grantResults) throws JSONException {
>         super.onRequestPermissionResult(requestCode, permissions, grantResults);
>         if (requestCode == REQUEST_CODE_PERMISSION) {
>             for (int r : grantResults) {
>                 if (r == PackageManager.PERMISSION_DENIED) {
>                     return;
>                 }
>             }
>             cordova.getActivity().runOnUiThread(new Runnable() {
>                 @Override
>                 public void run() {
>                    Log.d(TAG, "Granted!");
>                 }
>             });
>         }
>     }
> }
> {code}
> Stack trace:
> {code:java}
> java.lang.NoSuchMethodError: No virtual method requestPermissions([Ljava/lang/String;I)V
in class Landroid/app/Activity; or its super classes (declaration of 'android.app.Activity'
appears in /system/framework/framework.jar)
>       at org.apache.cordova.CordovaInterfaceImpl.requestPermissions(CordovaInterfaceImpl.java:226)
>       at org.mysample.HelloWorldBridge.initDialOnce(DialOnceBridge.java:40)
>       at org.mysample.HelloWorldBridge.pluginInitialize(DialOnceBridge.java:27)
>       at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:58)
>       at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171)
>       at org.apache.cordova.PluginManager.startupPlugins(PluginManager.java:97)
>       at org.apache.cordova.PluginManager.init(PluginManager.java:86)
>       at org.apache.cordova.CordovaWebViewImpl.init(CordovaWebViewImpl.java:115)
>       at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:149)
>       at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:224)
>       at com.dialonce.cordova.sample.MainActivity.onCreate(MainActivity.java:39)
>       at android.app.Activity.performCreate(Activity.java:6092)
>       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
>       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
>       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
>       at android.app.ActivityThread.access$800(ActivityThread.java:178)
>       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
>       at android.os.Handler.dispatchMessage(Handler.java:111)
>       at android.os.Looper.loop(Looper.java:194)
>       at android.app.ActivityThread.main(ActivityThread.java:5631)
>       at java.lang.reflect.Method.invoke(Native Method)
>       at java.lang.reflect.Method.invoke(Method.java:372)
>       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:963)
>       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)
> {code}
> h3. Investigation
> According docs [Activity.requestPermissions | https://developer.android.com/reference/android/app/Activity.html#requestPermissions(java.lang.String[],
int)] this method require Android API 23
> h3. Workaround
> Wrap `requestPermissions` code with `if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{ ... }`



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message