具有产品口味的Android GCM - java

我有GCM示例android gradle项目。它运行良好,当我添加2种口味时,推送通知停止工作。我的编译清单(取自app\build\intermediates\manifests\ex\debug)文件如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.flavor.app"
    <uses-permission android:name="com.flavor.app.permission.C2D_MESSAGE" />

    <permission
        android:name="com.flavor.app.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="com.flavor.app" />
            </intent-filter>
        </receiver>

        <service android:name="com.ex.app.GCMIntentService" />
        <service
            android:name="com.ex.app.AppLocationService"
            class=".AppLocationService" >
            <intent-filter>
                <action
                    android:name=".AppLocationService"
                    android:value=".AppLocationService" />
            </intent-filter>
        </service>

我应该怎么做才能解决这个问题?请帮忙。

UPD1。 我正在使用gradle v.0.12 +。我认为我的最终清单文件看起来不错,GCMRegistrar.checkManifest(this); -没有错误,但GCMRegistrar.isRegistered(this)始终为false。 =(

UPD2。 我的第一个带有原始包名称的flavor项目(与主分支中的项目一样)运行良好,但是第二个带有更改包的flavor无法正常工作(push的registrationId仍然为空),但是清单文件中的所有许可都是正确的。

参考方案

Simpy像这样使用${applicationId}别名

<permission android:name=            "${applicationId}.permission.C2D_MESSAGE"
            android:protectionLevel= "signature" />
<uses-permission android:name=       "${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name=       "com.google.android.c2dm.permission.RECEIVE" />

并为相应的接收者使用

    <receiver
        android:name = "com.mixpanel.android.mpmetrics.GCMReceiver"
        android:permission = "com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name = "com.google.android.c2dm.intent.RECEIVE"/>
            <action android:name = "com.google.android.c2dm.intent.REGISTRATION"/>

            <category android:name = "${applicationId}"/>
        </intent-filter>
    </receiver>

在Android Studio中设计可滚动内容时应遵循的方法是什么? - java

我正在约束布局中设计我的应用程序,并将其放置在“滚动视图”下。我想放置更多的Card Views,但是在xml文件的预览中没有放置空间。当布局已满时,我应该在哪里拖放Buttons,TextViews等?我已经处理了文本的滚动视图,但这是另外一回事。我知道我只能输入代码,但是当内容超出定义的屏幕尺寸时,我将无法看到我正在设计的内容时,我将很难这样做。(如果您…

android studio的设计预览中的布局为空 - java

我一直在从事一个项目,有一天我的布局在android studio设计中显得空白。我已经尝试过放置“ Base”。在文件style.xml中的“ Theme.AppCompat.Light.DarkActionBar”之前,我还尝试清理项目并使缓存/重新启动无效,但没有任何效果。我在manifest.xml中有此代码<?xml version=…

Android:如何为wrap_content设置高度动画? - java

我需要使用ValueAnimator来使用户拖动特定视图时出现自定义“放置字段”。 (我想将字段从gone, height = 0更改为visible, height = wrap_content)。我已经尝试过以下问题的解决方案:How to animate to wrap_content?当我在单个TextView上使用它时,答案就起作用了,但是当我尝试…

为什么我的应用在启动时总是崩溃-Android - java

刚刚遵循了有关如何制作按钮和活动的youtube指南。我按照他的代码减小字体大小,并且在启动时一直崩溃。有人知道为什么吗?public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { su…

AppCompat不支持当前主题 - java

我的应用在Android N上运行正常,但在Android M上的setContentView(R.layout.activity_main)崩溃: Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features: { w…