Android的摇篮产品口味与解析推送通知 [英] Android Gradle product Flavors with Parse Push Notifications

查看:130
本文介绍了Android的摇篮产品口味与解析推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过解析发送推送通知和集成的产品口味。当我实现了产品的味道,我不能够接受解析推送通知。有没有人有任何意见纠正这个问题。

I am trying to send Push notifications via Parse and integrating product flavors. When I implement product flavors, i am not able to receive Parse Push Notifications. Does anyone have any advise on correcting this issue

摇篮的应用程序文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.project"
        minSdkVersion 16
        targetSdkVersion 21

}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
productFlavors{
    freeApp{
        applicationId "com.example.project.free"

    }
    premiumApp{
        applicationId "com.example.project.paid"
    }
}
}

dependencies {
compile files('libs/android-async-http-1.4.2-66-g4b6eb97.jar')
compile files('libs/android-support-v13.jar')
compile files('libs/bolts-android-1.2.0.jar')
compile files('libs/Parse-1.9.2.jar')
compile files('libs/ParseCrashReporting-1.9.2.jar')
}

Android清单

Android Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project"
android:versionCode="1"
android:versionName="1.1" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission android:name="com.example.project.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.project.permission.C2D_MESSAGE" />

<application
    android:name="com.example.project.Application"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">



    <activity
        android:name="com.example.project.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>



    <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/ic_launcher"/>

    <service android:name="com.parse.PushService" />
    <receiver android:name="com.parse.ParseBroadcastReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
    <receiver android:name="com.parse.ParsePushBroadcastReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="com.parse.push.intent.RECEIVE" />
            <action android:name="com.parse.push.intent.DELETE" />
            <action android:name="com.parse.push.intent.OPEN" />
        </intent-filter>
    </receiver>
    <receiver android:name="com.parse.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" />

            <!--
              IMPORTANT: Change "com.parse.starter" to match your app's package name.
            -->
            <category android:name="com.example.project" />
        </intent-filter>
    </receiver>
</application>

推荐答案

这是什么问题?

我觉得你没有收到任何推的原因是,在你的Andr​​oidManifest.xml中声明如下的解析:

I think the reason you are not receiving any pushes is that in your AndroidManifest.xml you declare the following for Parse:

<permission android:name="com.example.project.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.project.permission.C2D_MESSAGE" />

<receiver android:name="com.parse.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" />

        <!--
          IMPORTANT: Change "com.parse.starter" to match your app's package name.
        -->
        <category android:name="com.example.project" />
    </intent-filter>
</receiver>

包名,不过,被定义为

The package names, however, are defined as

applicationId "com.example.project.free"

applicationId "com.example.project.paid"

因此​​,包名不匹配您的Andr​​oidManifest.xml中声明,因此解析无法接收推。其实,如果你看看你的logcat输出,你应该看到从解析消息,告诉你究竟是什么在你的Andr​​oidManifest.xml中丢失了。

So the package names don't match the declarations in your AndroidManifest.xml and therefore Parse is unable to receive pushes. Actually, if you look at your logcat output, you should be seeing a message from Parse that tells you exactly what is missing in your AndroidManifest.xml.

那么,如何解决此问题?

这是一个有点棘手的情况,但它可以做到的:

This is a bit of a tricky situation but it can be done:

1)删除在两部分我引用上面的Andr​​oidManifest.xml中主源组(的src /主/ AndroidManifest.xml中)。

1.) Remove the two parts I quoted above from the AndroidManifest.xml in your main source set (src/main/AndroidManifest.xml).

2A)中创建一个AndroidManifest.xml中的免费源组(的src /免费/ AndroidManifest.xml中 ),并输入以下内容:

2a.) Create an AndroidManifest.xml in your free source set (src/free/AndroidManifest.xml) and enter the following:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <permission
        android:name="com.example.project.free.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.project.free.permission.C2D_MESSAGE" />

    <application>
        <receiver
            android:name="com.parse.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.example.project.free" />
            </intent-filter>
        </receiver>

    </application>

</manifest>

图2b)执行相同的支付源集。一定要正确替换在AndroidManifest.xml包名。

2b.) Do the same for the paid source set. Be sure to replace the package name correctly in the AndroidManifest.xml.

为什么这项工作?

由于摇篮不会替换的src /主/ AndroidManifest.xml中的src /免费/ AndroidManifest.xml中而是合并的成一个。所以,如果你只是离开了声明了来源组,并把它们到免费支付,你会得到一个正确合并的Andr​​oidManifest.xml每个味道。

Because gradle does not replace the src/main/AndroidManifest.xml with the src/free/AndroidManifest.xml but instead merges them into one. So if you just leave the declarations out of the main source set and put them in to free and paid you will get a correctly merged AndroidManifest.xml for each flavor.

这篇关于Android的摇篮产品口味与解析推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆