Search code examples
javacordovacordova-plugins

How to add permission based on API level inside class to a static string


I have a Cordova plugin that needs to add a permission depending on the API level

public class someClass{

public static String[] PERMISSIONS = {
    Manifest.permission.ACCESS_COARSE_LOCATION,
    Manifest.permission.ACCESS_FINE_LOCATION
};

public someClass(Context context, PluginDelegate delegate){
     if(Build.VERSION.SDK_INT >= 29){
          someClass.PERMISSIONS.add(Manifest.permission.ACTIVITY_RECOGNITION);
     }
};

....

 

But then the build fails

error: cannot find symbol
        someClass.PERMISSIONS.add(Manifest.permission.ACTIVITY_RECOGNITION); 
                             ^
symbol:   method add(String)
location: variable PERMISSIONS of type String[]

How can I modify the static array of string?


Solution

  • Found my answer.

     if (Build.VERSION.SDK_INT >= 29){
            BackgroundGeolocationFacade.PERMISSIONS[2] = Manifest.permission.ACTIVITY_RECOGNITION;
     }
    

    did the trick