代码之家  ›  专栏  ›  技术社区  ›  WISHY

从字符串文件定义清单中的权限,android?

  •  0
  • WISHY  · 技术社区  · 6 年前

    在我的应用程序中,我使用gcm进行推送通知,我们必须在清单中设置2个权限标记,我从字符串xml中获取其值。

     <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工作室内部将DOT转换为下划线,因为它会导致无效的Java标识符错误。 请不要给我直接在清单中添加权限的解决方案,而不要从字符串文件中选择权限。

    我如何解决这个问题??

    4 回复  |  直到 6 年前
        1
  •  1
  •   Ganesh K    6 年前

    android:name <uses-permission>

    Manifest Permission

        2
  •  0
  •   Bmbariah    6 年前

     <permission
        android:name="com.lift.chi.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    
        3
  •  0
  •   Gourango Sutradhar    6 年前

    <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" />
    
        4
  •  0
  •   WISHY    6 年前

    Set string from gradle in manefesst

    manifestPlaceholders = [ gcmPermission:"com.lift.chi.permission.C2D_MESSAGE"]
    

    <uses-permission android:name="${gcmPermission}" />
    
    <permission
        android:name="${gcmPermission}"
        android:protectionLevel="signature" />