111
This commit is contained in:
@@ -92,13 +92,19 @@
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:replace="theme,label,icon,allowBackup">
|
||||
<service
|
||||
android:name="io.rong.push.platform.google.RongFirebaseMessagingService"
|
||||
android:stopWithTask="false"
|
||||
android:exported="false">
|
||||
android:name="com.shayu.phonelive.utils.MyNotificationService">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<!-- <service-->
|
||||
<!-- android:name="io.rong.push.platform.google.RongFirebaseMessagingService"-->
|
||||
<!-- android:stopWithTask="false"-->
|
||||
<!-- android:exported="false">-->
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="com.google.firebase.MESSAGING_EVENT"/>-->
|
||||
<!-- </intent-filter>-->
|
||||
<!-- </service>-->
|
||||
<activity
|
||||
android:name="com.shayu.phonelive.activity.LauncherActivity"
|
||||
android:screenOrientation="portrait"
|
||||
@@ -158,6 +164,7 @@
|
||||
<meta-data
|
||||
android:name="firebase_analytics_collection_enabled"
|
||||
android:value="false" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.shayu.phonelive.utils;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import com.google.android.gms.common.internal.zzm;
|
||||
import com.google.firebase.messaging.FirebaseMessagingService;
|
||||
import com.google.firebase.messaging.RemoteMessage;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.main.activity.MainActivity;
|
||||
|
||||
import myname.pdlive.shayu.R;
|
||||
|
||||
public class MyNotificationService extends FirebaseMessagingService {
|
||||
private String createNotificationChannel(String channelID, String channelNAME, int level) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = new NotificationChannel(channelID, channelNAME, level);
|
||||
manager.createNotificationChannel(channel);
|
||||
return channelID;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public void onMessageReceived(RemoteMessage remoteMessage) {
|
||||
Log.e("gmc","remoteMessage");
|
||||
// do nothing
|
||||
sendNotification("remoteMessage");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void sendNotification(String messageBody) {
|
||||
|
||||
// 设置通知的点击行为:这里启动一个 Activity
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
|
||||
String channelId = createNotificationChannel("my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
|
||||
// 构建 remoteView
|
||||
RemoteViews remoteView = new RemoteViews(getPackageName(), R.layout.notification_message);
|
||||
// remoteView.setTextViewText(R.id.tvMsg, "RemoteViews");
|
||||
// remoteView.setImageViewResource(R.id.ivIcon, R.mipmap.ic_launcher_round);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,channelId);
|
||||
// 设置自定义 RemoteViews
|
||||
builder.setContent(remoteView).setSmallIcon(R.mipmap.ic_launcher);
|
||||
// 设置通知的优先级(悬浮通知)
|
||||
builder.setPriority(NotificationCompat.PRIORITY_MAX);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
builder.setAutoCancel(true);
|
||||
Notification notification = builder.build();
|
||||
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
manager.notify(0, notification);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user