我测试了Android Marshmallow,Lollipop和Kitkat上的应用程序,除了装有Jellybean 4.2.2的设备之外,所有这些应用都正常工作。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.sample">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.test.sample.permission.C2D_MESSAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_TASKS" />
<permission
android:name="com.test.sample.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.test.sample.permission.C2D_MESSAGE"></uses-permission>
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@drawable/sgrficon"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppFullScreenTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/gcmKey" />
<activity
android:name="com.test.sample.SplashActivity"
android:noHistory="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.test.sample.LandingPage"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" />
<activity
android:name="com.test.sample.WebfragmentActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.test.sample.LandingPage" />
</activity>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
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.test.sample" />
</intent-filter>
</receiver>
<service android:name=".GcmPushService">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"></action>
</intent-filter>
</service>
<service
android:name=".GcmIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<activity
android:name=".PdfFragmentActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"></activity>
</application>
</manifest>
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.test.sample"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
configurations {
all*.exclude group: 'com.google.firebase', module: 'firebase-common'
}
configurations.all {
resolutionStrategy {
force 'com.android.support:design:24.1.1'
force 'com.android.support:support-v4:24.1.1'
force 'com.android.support:appcompat-v7:24.1.1'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.google.maps.android:android-maps-utils:0.4+'
compile 'com.android.volley:volley:1.0.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.android.support:design:24.1.1'
compile 'com.afollestad.material-dialogs:core:0.8.6.2'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.google.android.gms:play-services:9.4.0'
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:0)
如果我是你,我会在GCM上尝试Google上的演示并与我的代码进行比较。
https://github.com/google/gcm/tree/master/samples/android/gcm-demo
它支持Android 4.X(API-15)