Android Studio 3.2.1
在我的Manifest.xml中
<service
android:name="com.myproject.app.gcm.GcmIntentService_"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
<receiver
android:name="com.myproject.app.gcm.GcmWakefulBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.myproject.app" />
</intent-filter>
</receiver>
我的自定义接收者:
public class GcmWakefulBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
GcmIntentService_.startService(context, intent);
setResultCode(Activity.RESULT_OK);
}
}
我的自定义JobIntentService:
public class GcmIntentService extends JobIntentService {
private static final int JOB_ID = 1001;
private static String TAG = GcmIntentService_.class.getName();
public static void startService(Context context, Intent intent) {
Class dispatchClass = GcmIntentService_.class;
enqueueWork(context, dispatchClass, JOB_ID, intent);
}
@Override
protected void onHandleWork(@NonNull Intent intent) {
}
}
在我的 app / build.gradle 中:
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myproject.app"
minSdkVersion 18
targetSdkVersion 28
versionCode 425
versionName "2.1.425"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
configBuildType(delegate, "RELEASE_INSTANCE_NAME", "RELEASE_APP_NAME", "beta")
signingConfig signingConfigs.release
}
debug {
configBuildType(delegate, "DEBUG_INSTANCE_NAME", "DEBUG_APP_NAME", null)
}
}
def configBuildType(buildType, instanceName, appName, appIdSuffix) {
buildType.resValue("string", "app_name", appName)
buildType.applicationIdSuffix(appIdSuffix)
buildType.buildConfigField("String", "INSTANCE_NAME", instanceName)
}
结果是,我可以使用diff成功安装两个应用程序。 applicationId
在一台设备上:
com.myproject.app
com.myproject.app.beta
很好。
但是问题是当接收推送通知时(在通知抽屉中)。 重复。 我收到两个应用程序的两个推送通知。 但是,只有一个应用程序收到了推送通知。