diff --git a/app/src/main/java/com/shayu/phonelive/utils/CustomMessageReceiver.java b/app/src/main/java/com/shayu/phonelive/utils/CustomMessageReceiver.java index 21dd5926c..48fc30fd8 100644 --- a/app/src/main/java/com/shayu/phonelive/utils/CustomMessageReceiver.java +++ b/app/src/main/java/com/shayu/phonelive/utils/CustomMessageReceiver.java @@ -2,7 +2,9 @@ package com.shayu.phonelive.utils; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; +import android.Manifest; import android.annotation.SuppressLint; +import android.app.Dialog; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -17,6 +19,7 @@ import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.net.Uri; +import android.os.Build; import android.util.Log; import android.view.ViewGroup; import android.widget.ImageView; @@ -34,6 +37,8 @@ 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.common.utils.DialogUitl; +import com.yunbao.common.utils.SpUtil; import com.yunbao.main.activity.MainActivity; import org.json.JSONException; @@ -81,6 +86,20 @@ public class CustomMessageReceiver extends PushMessageReceiver { @Override public boolean onNotificationMessageArrived(Context context, PushType pushType, PushNotificationMessage notificationMessage) { Log.i("gmc", notificationMessage.getPushContent() + "VVV" + notificationMessage.getPushTitle() + "gmc11112222" + notificationMessage.getExtra()); + if(!SpUtil.getInstance().getBooleanValue("NOTIFICATION")){ + DialogUitl.showSimpleDialog(context, "应用需要通知权限", new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + Intent intent = new Intent(); + intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); + intent.putExtra("app_package", context.getPackageName()); + intent.putExtra("app_uid", context.getApplicationInfo().uid); + // for Android 8 and above + intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName()); + context.startActivity(intent); + } + }); + } if (notificationMessage.getExtra() == null) { msg.setImg("" + notificationMessage.getSenderPortrait()); msg.setTitle(notificationMessage.getPushTitle()); diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index d79039bf8..26f152090 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -483,23 +483,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene //获取指导员账号 ConversationIMListManager.get(this).getUserInstructor(this); checkVersion(); - if(!SpUtil.getInstance().getBooleanValue("NOTIFICATION")){ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - this.requestPermissions(new String[]{Manifest.permission.ACCESS_NOTIFICATION_POLICY,Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE}, 233); - } - DialogUitl.showSimpleDialog(this, "应用需要通知权限", new DialogUitl.SimpleCallback() { - @Override - public void onConfirmClick(Dialog dialog, String content) { - Intent intent = new Intent(); - intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); - intent.putExtra("app_package", getPackageName()); - intent.putExtra("app_uid", getApplicationInfo().uid); - // for Android 8 and above - intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName()); - startActivity(intent); - } - }); - } } @Override