Push-уведомление не работает в lollipop после изменения моего целевого SDK на 26, мой текущий минимальный SDK - 19. Он работал нормально раньше.Но после изменения на 26 он теперь работает только в O, N и M. Пожалуйста, предложите мне решение.Заранее спасибо.
Ниже приведен мой класс, который расширяет службу FirebaseMessaging
FireMsgService.java
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// super.onMessageReceived(remoteMessage);
Log.e("Msg", "Message received [" + remoteMessage + "]");
Intent intent = new Intent(this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410,
intent, PendingIntent.FLAG_ONE_SHOT);
context = getApplicationContext();
String message = "";
String type = "";
try {
JSONObject jsonObject = new JSONObject(remoteMessage.getData());
if (jsonObject.has("id"))
message = (String) jsonObject.get("id");
if (jsonObject.has("type"))
type = (String) jsonObject.get("type");
if (jsonObject.has("room_id"))
message = (String) jsonObject.get("room_id");
if (jsonObject.has("type"))
type = (String) jsonObject.get("type");
saveTypeId(type,message);
if (jsonObject.has("badge")) {
badge = (int) jsonObject.get("badge");
Log.d("BadgeCount",badge+"");
}
Log.e("","------> "+message);
} catch (JSONException e) {
e.printStackTrace();
}
NotificationCompat.Builder notificationBuilder = new
NotificationCompat.Builder(this)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setNumber(badge);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder.setSmallIcon(R.drawable.ic_new_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher))
.setColor(ContextCompat.getColor(context,R.color.blue));
} else {
notificationBuilder.setSmallIcon(R.drawable.ic_launcher);
}
notificationBuilder.setAutoCancel(true)
.setVibrate(new long[0])
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1410, notificationBuilder.build());
}
Вот мой файл build.gradle
build.gradle
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
applicationId "com.abc.xyz"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.1.3'
compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.android.gms:play-services-auth:11.0.4'
compile 'com.google.android.gms:play-services-places:11.0.4'
compile 'com.google.firebase:firebase-messaging:11.0.4'
compile 'com.google.firebase:firebase-messaging:11.0.4'
}
apply plugin: 'com.google.gms.google-services'