一切正常,但是按照Play商店的要求,我将我的应用升级到api level 27
,所有Play商店库都升级到了15.0.0
版,收到推送通知后,应用开始崩溃。
现在,当我发送推送通知应用程序时,崩溃并显示以下错误消息。
java.lang.AbstractMethodError: abstract method "void com.google.firebase.iid.zzb.zzd(android.content.Intent)"
at com.google.firebase.iid.zzg.run(Unknown Source:29)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:7)
at java.lang.Thread.run(Thread.java:764)
这是我的代码,我只在这里集成了channels
,并且当play-services
设置为版本9.0.0
时,它运行良好
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String from = remoteMessage.getFrom();
Map data = remoteMessage.getData();
Log.d("MSG", "onMessageReceived: "+data);
JSONObject jsonObject = new JSONObject();
Set<String> keys = remoteMessage.getData().keySet();
for (String key : keys) {
try {
jsonObject.put(key, remoteMessage.getData().get(key));
} catch (JSONException e) {
e.printStackTrace();
}
}
try {
SharedPreferences appPrefs = mContext.getSharedPreferences(SHARD_PREF, Context.MODE_PRIVATE);
String notifcation_settings = appPrefs.getString(NOTIFICATION_ENABLED, "");
message= jsonObject.getString("message");
if(!jsonObject.isNull("urlToOpen")){
urlToOpen= jsonObject.getString("urlToOpen");
}
sendNotification(message, urlToOpen);
} catch (JSONException e) {
e.printStackTrace();
}
}
private void sendNotification(final String msg, final String urlToOpen) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
NotificationManager notificationManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent = PendingIntent.getActivity(getApplicationContext(), 0,
notificationIntent, 0);
}
Long getCurrentTime= System.currentTimeMillis();
int id= Math.abs(getCurrentTime.intValue());
mBuilder = new Notification.Builder(mContext);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel();
mBuilder.setChannelId(getResources().getString(R.string.notification_channel_general));
}
mBuilder
.setSmallIcon(R.mipmap.ic_launcher)
.setAutoCancel(true)
.setContentIntent(intent)
.setContentTitle(getResources().getString(R.string.notification_title)).setContentText(msg)
.setStyle(new Notification.BigTextStyle().bigText(msg))
.setSound(soundUri)
.build();
notificationManager.notify("packageIid , mBuilder.build());
}
});
}
private void createNotificationChannel() {
String CHANNEL_ID= getResources().getString(R.string.notification_channel_general);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getString(R.string.channel_name);
String description = getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.enableVibration(true);
channel.setDescription(description);
channel.enableLights(true);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
这些是我的gradle设置。
Build.gradle(Project)
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.2.0'
build.gradle(app)
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
applicationId ''
minSdkVersion 21
targetSdkVersion 27
versionCode 285
multiDexEnabled true
resConfigs "en"
}
resolutionStrategy {
force 'com.squareup.okhttp:okhttp:2.4.0'
force 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
force 'com.android.support:support-v4:24.1.1'
force 'com.android.support:cardview-v7:24.1.1'
force 'com.android.support:appcompat-v7:24.1.1'
force 'com.android.support:design:24.1.1'
force 'com.google.android.gms:play-services-ads:15.0.0'
force 'com.google.android.gms:play-services-location:15.0.0'
force 'com.google.android.gms:play-services-auth-base:15.0.1'
force 'com.google.android.gms:play-services-base:15.0.0'
force 'com.google.android.gms:play-services-maps:15.0.0'
force 'com.google.android.gms:play-services-identity:15.0.0'
force 'com.google.android.gms:play-services-wallet:15.0.0'
force 'com.google.android.gms:play-services-tasks:15.0.0'
force 'com.google.android.gms:play-services-basement:15.0.0'
force 'com.google.firebase:firebase-common:15.0.0'
force 'com.google.android.gms:play-services-base:15.0.0'
}
dependencies {
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.google.android.gms:play-services-maps:15.0.0'
implementation 'com.google.android.gms:play-services-analytics:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'com.google.firebase:firebase-appindexing:15.0.0'
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.google.android.gms:play-services-auth-base:15.0.0'
implementation 'com.google.android.gms:play-services-panorama:15.0.0'
implementation 'com.google.android.gms:play-services-ads:15.0.0'
implementation('com.google.firebase:firebase-messaging:15.0.0') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
}
implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'org.jsoup:jsoup:1.8.3'
}
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip