如何将 class 内基于 API 级别的权限添加到静态字符串
How to add permission based on API level inside class to a static string
我有一个 Cordova 插件需要根据 API 级别添加权限
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);
}
};
....
但随后构建失败
error: cannot find symbol
someClass.PERMISSIONS.add(Manifest.permission.ACTIVITY_RECOGNITION);
^
symbol: method add(String)
location: variable PERMISSIONS of type String[]
如何修改字符串的静态数组?
找到我的答案。
if (Build.VERSION.SDK_INT >= 29){
BackgroundGeolocationFacade.PERMISSIONS[2] = Manifest.permission.ACTIVITY_RECOGNITION;
}
成功了
我有一个 Cordova 插件需要根据 API 级别添加权限
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);
}
};
....
但随后构建失败
error: cannot find symbol
someClass.PERMISSIONS.add(Manifest.permission.ACTIVITY_RECOGNITION);
^
symbol: method add(String)
location: variable PERMISSIONS of type String[]
如何修改字符串的静态数组?
找到我的答案。
if (Build.VERSION.SDK_INT >= 29){
BackgroundGeolocationFacade.PERMISSIONS[2] = Manifest.permission.ACTIVITY_RECOGNITION;
}
成功了