This commit is contained in:
18142669586
2022-08-26 13:00:45 +08:00
parent b3500b94c0
commit 036f27a415
29 changed files with 1262 additions and 80 deletions

View File

@@ -0,0 +1,92 @@
{
"agcgw":{
"backurl":"connect-drcn.hispace.hicloud.com",
"url":"connect-drcn.dbankcloud.cn",
"websocketbackurl":"connect-ws-drcn.hispace.dbankcloud.com",
"websocketurl":"connect-ws-drcn.hispace.dbankcloud.cn"
},
"agcgw_all":{
"CN":"connect-drcn.dbankcloud.cn",
"CN_back":"connect-drcn.hispace.hicloud.com",
"DE":"connect-dre.dbankcloud.cn",
"DE_back":"connect-dre.hispace.hicloud.com",
"RU":"connect-drru.hispace.dbankcloud.ru",
"RU_back":"connect-drru.hispace.dbankcloud.cn",
"SG":"connect-dra.dbankcloud.cn",
"SG_back":"connect-dra.hispace.hicloud.com"
},
"websocketgw_all":{
"CN":"connect-ws-drcn.hispace.dbankcloud.cn",
"CN_back":"connect-ws-drcn.hispace.dbankcloud.com",
"DE":"connect-ws-dre.hispace.dbankcloud.cn",
"DE_back":"connect-ws-dre.hispace.dbankcloud.com",
"RU":"connect-ws-drru.hispace.dbankcloud.ru",
"RU_back":"connect-ws-drru.hispace.dbankcloud.cn",
"SG":"connect-ws-dra.hispace.dbankcloud.cn",
"SG_back":"connect-ws-dra.hispace.dbankcloud.com"
},
"client":{
"cp_id":"30086000612391734",
"product_id":"99536292102564216",
"client_id":"964994320723627840",
"client_secret":"6D5FE29D85B967D3A66BDCD473641E4C7B5524F7F4935CA0EF4A842730C3402D",
"project_id":"99536292102564216",
"app_id":"106936673",
"api_key":"DAEDADYGta/0O4ZSdrnug52NgC67/w/RIyTq9A8LyAY0+mp6g6XeJDbxugpluFPLAhaqjaMs5c0PLnRx14UzWbPPADgi1EqihbWLoA==",
"package_name":"com.pdlive.shayu"
},
"oauth_client":{
"client_id":"106936673",
"client_type":1
},
"app_info":{
"app_id":"106936673",
"package_name":"com.pdlive.shayu"
},
"service":{
"analytics":{
"collector_url":"datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn",
"collector_url_ru":"datacollector-drru.dt.dbankcloud.ru,datacollector-drru.dt.hicloud.com",
"collector_url_sg":"datacollector-dra.dt.hicloud.com,datacollector-dra.dt.dbankcloud.cn",
"collector_url_de":"datacollector-dre.dt.hicloud.com,datacollector-dre.dt.dbankcloud.cn",
"collector_url_cn":"datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn",
"resource_id":"p1",
"channel_id":""
},
"search":{
"url":"https://search-drcn.cloud.huawei.com"
},
"cloudstorage":{
"storage_url_sg_back":"https://agc-storage-dra.cloud.huawei.asia",
"storage_url_ru_back":"https://agc-storage-drru.cloud.huawei.ru",
"storage_url_ru":"https://agc-storage-drru.cloud.huawei.ru",
"storage_url_de_back":"https://agc-storage-dre.cloud.huawei.eu",
"storage_url_de":"https://ops-dre.agcstorage.link",
"storage_url":"https://agc-storage-drcn.platform.dbankcloud.cn",
"storage_url_sg":"https://ops-dra.agcstorage.link",
"storage_url_cn_back":"https://agc-storage-drcn.cloud.huawei.com.cn",
"storage_url_cn":"https://agc-storage-drcn.platform.dbankcloud.cn"
},
"ml":{
"mlservice_url":"ml-api-drcn.ai.dbankcloud.com,ml-api-drcn.ai.dbankcloud.cn"
}
},
"region":"CN",
"configuration_version":"3.0",
"appInfos":[
{
"package_name":"com.pdlive.shayu",
"client":{
"app_id":"106936673"
},
"app_info":{
"package_name":"com.pdlive.shayu",
"app_id":"106936673"
},
"oauth_client":{
"client_type":1,
"client_id":"106936673"
}
}
]
}

View File

@@ -110,4 +110,6 @@ dependencies {
//短视频
api project(':video')
annotationProcessor rootProject.ext.dependencies["arouter-compiler"]
}

View File

@@ -91,20 +91,20 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="theme,label,icon,allowBackup">
<service
android:name="com.shayu.phonelive.utils.MyNotificationService">
<intent-filter>
<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">-->
<!-- 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"
@@ -164,7 +164,29 @@
<meta-data
android:name="firebase_analytics_collection_enabled"
android:value="false" />
<receiver
android:name="com.shayu.phonelive.utils.CustomMessageReceiver"
android:exported="true">
<intent-filter>
<action android:name="io.rong.push.intent.MESSAGE_ARRIVED" />
<action android:name="io.rong.push.intent.MESSAGE_CLICKED" />
<action android:name="io.rong.push.intent.THIRD_PARTY_PUSH_STATE" />
</intent-filter>
</receiver>
<service
android:name="io.rong.push.platform.hms.HMSPushService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="106936673"/>
<meta-data
android:name="com.huawei.hms.client.cpid"
android:value="30086000612391734"/>
</application>
</manifest>

View File

@@ -120,11 +120,6 @@ public class AppContext extends CommonAppContext {
}
ARouter.init(this);
//谷歌推送
PushConfig gconfig = new PushConfig.Builder()
.enableFCM(true)
.build();
RongPushClient.setPushConfig(gconfig);
//初始化 邀请码库
if (isMainProcess()) {
@@ -194,6 +189,7 @@ public class AppContext extends CommonAppContext {
}
});
//监听im消息
V2TIMManager.getInstance().addSimpleMsgListener(new V2TIMSimpleMsgListener() {
@Override

View File

@@ -31,6 +31,8 @@ import com.tencent.rtmp.TXLivePlayer;
import com.tencent.rtmp.ui.TXCloudVideoView;
import com.tencent.ugc.TXUGCBase;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants;
import com.yunbao.common.activity.WebViewActivity;
import com.yunbao.common.bean.AdBean;
import com.yunbao.common.bean.ConfigBean;
import com.yunbao.common.bean.IMLoginModel;
@@ -40,6 +42,7 @@ import com.yunbao.common.event.DataUserInfoEvent;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.http.CommonHttpConsts;
import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.interfaces.CommonCallback;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
@@ -50,11 +53,17 @@ import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.SpUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.bean.LiveBean;
import com.yunbao.live.http.LiveHttpUtil;
import com.yunbao.live.presenter.LiveRoomCheckLivePresenter;
import com.yunbao.live.views.LauncherAdViewHolder;
import com.yunbao.main.activity.EntryActivity;
import com.yunbao.main.activity.MainActivity;
import com.yunbao.main.activity.PDLiveConversationListActivity;
import com.yunbao.main.http.MainHttpConsts;
import com.yunbao.main.http.MainHttpUtil;
import com.yunbao.main.manager.imrongcloud.ConversationIMListManager;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -78,8 +87,8 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
private static final String TAG = "LauncherActivity";
private static final int WHAT_GET_CONFIG = 0;
private static final int WHAT_COUNT_DOWN = 1;
private Handler mHandler;
protected Context mContext;
private Handler mHandler;
private ViewGroup mRoot;
private ImageView mCover;
private ViewGroup mContainer;
@@ -261,11 +270,25 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
*/
private void forwardMainActivity() {
releaseVideo();
MainActivity.forward(mContext);
Intent intent = new Intent(
LauncherActivity.this, MainActivity.class);
intent.putExtra(Constants.SHOW_INVITE, false);
if (getIntent().getStringExtra("liveid") != null) {
intent.putExtra("liveid", getIntent().getStringExtra("liveid"));
}
if (getIntent().getStringExtra("type") != null) {
intent.putExtra("type", getIntent().getStringExtra("type"));
}
if (getIntent().getStringExtra("activityUrl") != null) {
intent.putExtra("activityUrl", getIntent().getStringExtra("activityUrl"));
}
LauncherActivity.this.startActivity(intent);
finish();
}
@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);

View File

@@ -0,0 +1,282 @@
package com.shayu.phonelive.utils;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import android.annotation.SuppressLint;
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.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.net.Uri;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RemoteViews;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.makeramen.roundedimageview.RoundedImageView;
import com.shayu.phonelive.activity.LauncherActivity;
import com.yunbao.common.bean.NotificationMsgBean;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.main.activity.MainActivity;
import org.json.JSONException;
import org.json.JSONObject;
import io.rong.imlib.ConnectChangeReceiver;
import io.rong.push.PushType;
import io.rong.push.notification.PushMessageReceiver;
import io.rong.push.notification.PushNotificationMessage;
import myname.pdlive.shayu.R;
public class CustomMessageReceiver extends PushMessageReceiver {
private String createNotificationChannel(Context context, String channelID, String channelNAME, int level) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel(channelID, channelNAME, level);
channel.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/raw/pdlive_sound"),null);
manager.createNotificationChannel(channel);
return channelID;
} else {
return null;
}
}
@Override
public boolean onNotificationMessageClicked(
Context context, PushType pushType, PushNotificationMessage message) {
if (pushType.equals(PushType.GOOGLE_FCM)) {
Log.i("gmc", "gmc");
// TODO
} else {
Log.i("gmc", "gmc1111");
}
// 返回 true 表示拦截false 为不拦截
return true;
}
NotificationMsgBean msg = new NotificationMsgBean();
@Override
public boolean onNotificationMessageArrived(Context context, PushType pushType, PushNotificationMessage notificationMessage) {
Log.i("gmc", notificationMessage.getPushContent() + "VVV" + notificationMessage.getPushTitle() + "gmc11112222" + notificationMessage.getExtra());
if (notificationMessage.getExtra() == null) {
msg.setImg("" + notificationMessage.getSenderPortrait());
msg.setTitle(notificationMessage.getPushTitle());
msg.setContent(notificationMessage.getPushContent());
msg.setType("-1");
sendNotification(context, msg);
} else {
try {
JSONObject obj = new JSONObject(notificationMessage.getExtra());
Log.i("gmc", "1111222");
//开播
if (obj.getString("type").equals("1") || obj.getString("type").equals("9")) {
Log.i("gmc", "1111");
msg.setImg("" + obj.getString("avatar"));
msg.setTitle(notificationMessage.getPushTitle());
msg.setContent(notificationMessage.getPushContent());
msg.setLiveuid(obj.getString("liveuid"));
msg.setType("1");
liveNotification(context, msg);
//发布动态 2
//点赞 3
//评论 4
//鼓励 5
} else if (obj.getString("type").equals("2") || obj.getString("type").equals("3") || obj.getString("type").equals("4") || obj.getString("type").equals("5")) {
msg.setImg("" + obj.getString("avatar"));
msg.setTitle(notificationMessage.getPushTitle());
msg.setContent(notificationMessage.getPushContent());
msg.setType("2");
dynamicNotification(context, msg);
} else if (obj.getString("type").equals("8") || obj.getString("type").equals("7")) {
msg.setImg("" + obj.getString("avatar"));
msg.setTitle(notificationMessage.getPushTitle());
msg.setContent(notificationMessage.getPushContent());
msg.setType(obj.getString("type"));
msg.setActivityurl(obj.getString("activityUrl"));
serviceNotification(context, msg);
}
} catch (JSONException e) {
Log.i("gmc", "1111" + e.getMessage());
e.printStackTrace();
}
}
return true;
}
public static Bitmap makeRoundCorner(Bitmap bitmap, float roundPx) {
try {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;// 颜色值0xff---alpha
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);// Rect是使用int类型作为数值RectF是使用float类型作为数值
// --------抗锯齿-------//
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
final Rect src = new Rect(0, 0, bitmap.getWidth(),
bitmap.getHeight());
canvas.drawBitmap(bitmap, null, rect, paint);
return output;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
//私聊
private void sendNotification(Context context, NotificationMsgBean message) {
// 设置通知的点击行为:这里启动一个 Activity
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
// 构建 remoteView
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message);
remoteView.setTextViewText(R.id.title, message.getTitle());
remoteView.setTextViewText(R.id.content, message.getContent());
Glide.with(context).asBitmap().load(message.getImg()).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
remoteView.setImageViewBitmap(R.id.img, makeRoundCorner(resource, 50));
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
// 设置自定义 RemoteViews
builder.setContent(remoteView).setSmallIcon(R.drawable.small_icons);
// 设置通知的优先级(悬浮通知)
builder.setPriority(NotificationCompat.PRIORITY_MAX);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, notification);
}
});
}
int id = 1;
//动态
private void dynamicNotification(Context context, NotificationMsgBean message) {
// 设置通知的点击行为:这里启动一个 Activity
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra("type", "2");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
// 构建 remoteView
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message);
remoteView.setTextViewText(R.id.title, message.getTitle());
remoteView.setTextViewText(R.id.content, message.getContent());
remoteView.setImageViewResource(R.id.img, R.mipmap.ic_launcher);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
// 设置自定义 RemoteViews
builder.setContent(remoteView).setSmallIcon(R.drawable.small_icons);
// 设置通知的优先级(悬浮通知)
builder.setPriority(NotificationCompat.PRIORITY_MAX);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
id = (int) (id + System.currentTimeMillis());
manager.notify(id, notification);
}
//开播
private void liveNotification(Context context, NotificationMsgBean message) {
// 设置通知的点击行为:这里启动一个 Activity
Intent intent = new Intent(context, LauncherActivity.class);
intent.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("liveid", message.getLiveuid());
Log.e("gmc", message.getLiveuid() + "21121");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
// 构建 remoteView
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message);
remoteView.setTextViewText(R.id.title, message.getTitle());
remoteView.setTextViewText(R.id.content, message.getContent());
Glide.with(context).asBitmap().load(message.getImg()).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
remoteView.setImageViewBitmap(R.id.img, makeRoundCorner(resource, 50));
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
// 设置自定义 RemoteViews
builder.setContent(remoteView).setSmallIcon(R.drawable.small_icons);
// 设置通知的优先级(悬浮通知)
builder.setPriority(NotificationCompat.PRIORITY_MAX);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
id = (int) (id + System.currentTimeMillis());
manager.notify(id, notification);
}
});
Log.i("gmc", "11123231");
}
//后台
private void serviceNotification(Context context, NotificationMsgBean message) {
// 设置通知的点击行为:这里启动一个 Activity
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra("type", message.getType());
if (message.getType().equals("8")) {
intent.putExtra("activityUrl", message.getActivityurl());
}
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
String channelId = createNotificationChannel(context, "my_channel_ID", "my_channel_NAME", NotificationManager.IMPORTANCE_HIGH);
// 构建 remoteView
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_message);
remoteView.setTextViewText(R.id.title, message.getTitle());
remoteView.setTextViewText(R.id.content, message.getContent());
remoteView.setImageViewResource(R.id.img, R.mipmap.ic_launcher);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
// 设置自定义 RemoteViews
builder.setContent(remoteView).setSmallIcon(R.drawable.small_icons);
// 设置通知的优先级(悬浮通知)
builder.setPriority(NotificationCompat.PRIORITY_MAX);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
id = (int) (id + System.currentTimeMillis());
manager.notify(id, notification);
}
}

View File

@@ -22,9 +22,15 @@ import com.google.firebase.messaging.RemoteMessage;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.main.activity.MainActivity;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Map;
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);
@@ -35,36 +41,70 @@ public class MyNotificationService extends FirebaseMessagingService {
return null;
}
}
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e("gmc","remoteMessage");
public void onMessageReceived(RemoteMessage message) {
// do nothing
sendNotification("remoteMessage");
Map<String, String> params = message.getData();
JSONObject object = new JSONObject(params);
Log.e("JSON_OBJECT", object.toString());
JSONObject remoteMessage = null;
try {
remoteMessage = new JSONObject(object.getString("message"));
Log.e("gmc","remoteMessage1"+remoteMessage.toString());
Log.e("gmc","remoteMessage"+remoteMessage.getString("fromUserName"));
} catch (JSONException e) {
e.printStackTrace();
}
// if(remoteMessage!=null && remoteMessage.isNull("fcm_token")) {
// String title = remoteMessage.getData().get("title");
// String message = remoteMessage.getData().get("text");
// String username = remoteMessage.getData().get("username");
// String uid = remoteMessage.getData().get("uid");
// String fcmToken = remoteMessage.getData().get("fcm_token");
// Log.e("gmc","remoteMessage"+remoteMessage.getData().get("username"));
//
// //Muestro la notifiación
//// sendNotification(title, message, username, uid, fcmToken);
// }else {
// /// Si es de tipo inserción la muestro sino no.
// //Es una nueva notificación de que alguien ha creado algo
// if(remoteMessage.getData().get("accion")!=null &&
// remoteMessage.getData().get("accion").compareTo("insert")==0)
//// displayNotification(remoteMessage.getNotification(), remoteMessage.getData());
//// //Envío los datos al RecyclerView correspondiente para que se actualice
//// addNotificacion(remoteMessage);
// Log.e("gmc","remoteMessage"+remoteMessage.getData().get("username"));
//
// }
// 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);
}
// 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);
//
// }
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.