Android没有推送通知,android – 一些Oreo设备没有获得推送通知

三星S8 / S5 / J2 / Note3成功获得Firebase推送通知应用程序被杀死,在后台或前台,

但如果应用程序被杀,Infinix Note 5(Android One-Oreo)和Oppo F9(Oreo)没有得到推送通知,如果应用程序处于后台或前台,它们可以正常工作.

我经历了很多文章,this和this,提到中国手机存在这个问题,并且用户方面有一些工作要让这些通知在他们的手机上工作.

但我想知道从开发方面是否有可能在每个Android设备上进行通知工作.

我的目标是API 27,这是我的代码

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {

@Override

public void onMessageReceived(RemoteMessage remoteMessage) {

super.onMessageReceived(remoteMessage);

String from = remoteMessage.getFrom();

Map data = remoteMessage.getData();

JSONObject jsonObject = new JSONObject();

Set keys = remoteMessage.getData().keySet();

for (String key : keys) {

try {

jsonObject.put(key, remoteMessage.getData().get(key));

} catch (JSONException e) {

e.printStackTrace();

}

}

message= jsonObject.getString("message");

sendNotification(message, urlToOpen);

private void sendNotification(final String msg, final String urlToOpen) {

Intent intent = new Intent(this, MainActivity.class);

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,

PendingIntent.FLAG_ONE_SHOT);

String channelId = getString(R.string.notification_channel_general);

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

NotificationCompat.Builder notificationBuilder =

new NotificationCompat.Builder(this, channelId)

.setSmallIcon(R.drawable.notification_icon)

.setContentTitle("App Name")

.setContentText(msg)

.setAutoCancel(true)

.setSound(defaultSoundUri)

.setPriority(Notification.PRIORITY_MAX)

.setContentIntent(pendingIntent);

NotificationManager notificationManager =

(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

NotificationChannel channel = new NotificationChannel(channelId,

"App Channel",

NotificationManager.IMPORTANCE_HIGH);

notificationManager.createNotificationChannel(channel);

}

notificationManager.notify(0, notificationBuilder.build());

摇篮

compileSdkVersion 27

defaultConfig {

applicationId "com.myapp.app"

minSdkVersion 19

targetSdkVersion 27

versionCode 2

versionName "1"

multiDexEnabled true

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

vectorDrawables.useSupportLibrary = true

}

buildTypes {

release {

minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}

debug {

// Disable fabric build ID generation for debug builds

ext.enableCrashlytics = false

}

}

implementation 'com.google.firebase:firebase-messaging:15.0.0'

implementation 'com.google.android.gms:play-services-location:15.0.0'

implementation 'com.google.android.gms:play-services-auth:15.0.0'

implementation 'com.google.android.gms:play-services-basement:16.0.1'

implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'

implementation 'com.google.android.gms:play-services-stats:16.0.1'

implementation 'com.google.android.gms:play-services-tasks:16.0.1'

implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'

implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'

implementation 'com.google.android.gms:play-services-maps:16.0.0'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值