我是一名图书馆开发人员(SDK),我的SDK正在使用'com.google.android.gms:play-services-gcm:9.0.2'
,它可以正常使用GCM的应用程序,但每次应用程序从FCM / GCM接收推送时都会崩溃,
对于使用FCM的应用程序使用GCM librery是一个好主意吗?是否有任何解决方案来阻止崩溃?我无法收到GCM / FCM的通知
库build.gradle:
android {
enforceUniquePackageName = false
compileSdkVersion 22
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 18
resConfig "en"
}
repositories {
mavenCentral()
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.github.nkzawa:socket.io-client:0.5.2'
}
清单:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19"></uses-sdk>
<!-- GCM requires a Google account. -->
<!--<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />-->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Required if we need to invalidate access tokens -->
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--other permissions-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:label="@string/app_name">
<!--GCM services starts here-->
<!--
WakefulBroadcastReceiver that will receive intents from GCM
services and hand them to the custom IntentService.
The com.google.android.c2dm.permission.SEND permission is necessary
so only GCM services can send data messages for the app.
-->
<receiver
android:name="com.xyz.gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
<service android:name=".NgageGcmIntentService" />
<!--GCM services ends here-->
<!--<activity-->
<!--android:name="com.xyz.messaging.ChatActivity"-->
<!--android:label="@string/app_name"-->
<!--android:screenOrientation="sensorPortrait"-->
<!--android:theme="@style/AppTheme"-->
<!--android:windowSoftInputMode="adjustResize" />-->
<activity
android:name="com.xyz.ui.ImageViewer"
android:label="@string/app_name"
android:screenOrientation="sensorPortrait">
</activity>
<activity
android:name="com.xyz.messaging.LoginActivity"
android:label="@string/title_activity_login"
android:screenOrientation="sensorPortrait"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize" />
<service
android:name="com.xyz.gcm.PNListenerService"
android:label="@string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
<service
android:name="com.xyz.gcm.GCMInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
</application>
</manifest>
示例App build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.xyz.sample"
minSdkVersion 14
targetSdkVersion 18
versionCode 3
versionName "0.3"
}
repositories {
mavenCentral()
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.2'
compile project(':gcm')
}
apply plugin: 'com.google.gms.google-services'
示例App Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz.sample">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.xyz.messaging.ChatActivity"
android:label="@string/app_name"
android:screenOrientation="sensorPortrait"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name="com.xyz.sample.DeepLinkedActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="com.ndtv"
android:pathPrefix="/pushnotification"
android:scheme="ndtv" />
</intent-filter>
</activity>
<meta-data
android:name="gcm_launching_activity"
android:value="com.xyz.sample.MainActivity" />
<service
android:name=".FCMMessageRecieverService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<!-- <meta-data
android:name="gcm_enable_notification_access"
android:value="disable" />-->
</application>
</manifest>