修复推送通知权限提示框非activity导致的闪图问题

This commit is contained in:
zlzw 2022-11-28 15:27:28 +08:00
parent ecbfa57276
commit 6fb29bbf60

View File

@ -4,6 +4,7 @@ import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
@ -34,6 +35,7 @@ import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
import com.makeramen.roundedimageview.RoundedImageView; import com.makeramen.roundedimageview.RoundedImageView;
import com.shayu.phonelive.AppContext;
import com.shayu.phonelive.activity.LauncherActivity; import com.shayu.phonelive.activity.LauncherActivity;
import com.yunbao.common.bean.NotificationMsgBean; import com.yunbao.common.bean.NotificationMsgBean;
import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.glide.ImgLoader;
@ -87,7 +89,9 @@ public class CustomMessageReceiver extends PushMessageReceiver {
public boolean onNotificationMessageArrived(Context context, PushType pushType, PushNotificationMessage notificationMessage) { public boolean onNotificationMessageArrived(Context context, PushType pushType, PushNotificationMessage notificationMessage) {
Log.i("gmc", notificationMessage.getPushContent() + "VVV" + notificationMessage.getPushTitle() + "gmc11112222" + notificationMessage.getExtra()); Log.i("gmc", notificationMessage.getPushContent() + "VVV" + notificationMessage.getPushTitle() + "gmc11112222" + notificationMessage.getExtra());
if (!SpUtil.getInstance().getBooleanValue("NOTIFICATION")) { if (!SpUtil.getInstance().getBooleanValue("NOTIFICATION")) {
DialogUitl.showSimpleDialog(context, "应用需要通知权限", new DialogUitl.SimpleCallback() { Activity activity = AppContext.activityWeakReference.get();
if (activity != null) {
DialogUitl.showSimpleDialog(activity, "应用需要通知权限", new DialogUitl.SimpleCallback() {
@Override @Override
public void onConfirmClick(Dialog dialog, String content) { public void onConfirmClick(Dialog dialog, String content) {
Intent intent = new Intent(); Intent intent = new Intent();
@ -96,10 +100,11 @@ public class CustomMessageReceiver extends PushMessageReceiver {
intent.putExtra("app_uid", context.getApplicationInfo().uid); intent.putExtra("app_uid", context.getApplicationInfo().uid);
// for Android 8 and above // for Android 8 and above
intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName()); intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName());
context.startActivity(intent); activity.startActivity(intent);
} }
}); });
} }
}
if (notificationMessage.getExtra() == null) { if (notificationMessage.getExtra() == null) {
msg.setImg("" + notificationMessage.getSenderPortrait()); msg.setImg("" + notificationMessage.getSenderPortrait());
msg.setTitle(notificationMessage.getPushTitle()); msg.setTitle(notificationMessage.getPushTitle());