从字符串文件 android 中定义清单中的权限?
Defining permission in manifest from string file, android?
在我的应用程序中,我使用 GCM 进行推送通知,我们必须在我从字符串 xml
中获取其值的清单中设置 2 个权限标签
<uses-permission android:name="@string/app_gcm_permission" />
<permission
android:name="@string/app_gcm_permission"
android:protectionLevel="signature" />
在字符串文件中
<string name="app_gcm_permission">com.lift.chi.permission.C2D_MESSAGE</string>
gradle 构建成功,当我尝试 运行 应用时出现以下错误
error: invalid Java identifier '@string/app_gcm_permission'.
Message{kind=ERROR, text=error: invalid Java identifier '@string/app_gcm_permission'
发生这种情况是因为 android studio 在内部将点转换为下划线,从而抛出无效的 java 标识符错误。
请不要给我直接在清单中添加权限而不是从字符串文件中选择的解决方案。
我该如何解决这个问题?
您不能在 <uses-permission>
的 android:name
字段中使用字符串资源。您将不得不使用预定义的字符串。有关详细信息,请访问此 link :-
试试这个快速修复
<permission
android:name="com.lift.chi.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
而不是
<uses-permission android:name="@string/app_gcm_permission" />
<permission
android:name="@string/app_gcm_permission"
android:protectionLevel="signature" />
去做
<uses-permission android:name="com.lift.chi.permission.C2D_MESSAGE" />
<permission
android:name="com.lift.chi.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
我是根据这个问题的回答解决的
解决代码,在build gradle, ->android->defaultConfig
manifestPlaceholders = [ gcmPermission:"com.lift.chi.permission.C2D_MESSAGE"]
并且在清单文件中
<uses-permission android:name="${gcmPermission}" />
<permission
android:name="${gcmPermission}"
android:protectionLevel="signature" />
在我的应用程序中,我使用 GCM 进行推送通知,我们必须在我从字符串 xml
中获取其值的清单中设置 2 个权限标签 <uses-permission android:name="@string/app_gcm_permission" />
<permission
android:name="@string/app_gcm_permission"
android:protectionLevel="signature" />
在字符串文件中
<string name="app_gcm_permission">com.lift.chi.permission.C2D_MESSAGE</string>
gradle 构建成功,当我尝试 运行 应用时出现以下错误
error: invalid Java identifier '@string/app_gcm_permission'.
Message{kind=ERROR, text=error: invalid Java identifier '@string/app_gcm_permission'
发生这种情况是因为 android studio 在内部将点转换为下划线,从而抛出无效的 java 标识符错误。 请不要给我直接在清单中添加权限而不是从字符串文件中选择的解决方案。
我该如何解决这个问题?
您不能在 <uses-permission>
的 android:name
字段中使用字符串资源。您将不得不使用预定义的字符串。有关详细信息,请访问此 link :-
试试这个快速修复
<permission
android:name="com.lift.chi.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
而不是
<uses-permission android:name="@string/app_gcm_permission" />
<permission
android:name="@string/app_gcm_permission"
android:protectionLevel="signature" />
去做
<uses-permission android:name="com.lift.chi.permission.C2D_MESSAGE" />
<permission
android:name="com.lift.chi.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
我是根据这个问题的回答解决的
解决代码,在build gradle, ->android->defaultConfig
manifestPlaceholders = [ gcmPermission:"com.lift.chi.permission.C2D_MESSAGE"]
并且在清单文件中
<uses-permission android:name="${gcmPermission}" />
<permission
android:name="${gcmPermission}"
android:protectionLevel="signature" />