android - 应用程序在收到推送通知时崩溃
问题描述
一切正常,但根据 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 设置。
构建.gradle(项目)
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.2.0'
构建.gradle(应用程序)
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
解决方案
推荐阅读
- docker - Docker Build 使用 Buildkit 任何方式来记录哪个文件爆破了缓存?
- java - Spring Boot 无法解析 Eclipse 中的属性占位符
- outlook - 在加载加载项时自动固定 Outlook 中的任务窗格
- angular - 我们可以使用 NGXS 模式像使用 extraProperties Map 一样轻松地扩展模型吗?
- tableau-api - 如何在表格中的特定列中添加值
- javascript - Vue js:数组上的过滤器在我的代码中不起作用
- basic-authentication - IAsyncAuthorizationFilter 在重定向到登录页面后执行
- javascript - 为什么我会收到此错误 - 函数作为 React 子级无效。如果您返回 Component 而不是
从渲染 - css - 无法使用 Live Sass 编译器将 Sass 文件编译为 CSS
- python - pip 在同一网络上的多台计算机上超时