简体   繁体   English

FCM 通知在前台崩溃 MIUI - Android

[英]FCM Notification Crashes MIUI on Foreground - Android

Im testing the push notification with my app.我用我的应用程序测试推送通知。 while the app is running on foreground, background or killed there is contentIntent to handle the notification to which activity当应用程序在前台、后台运行或被终止时,有 contentIntent 来处理通知哪个活动

on my HTC Desire 816在我的 HTC Desire 816 上

  1. click on notification to launch activity when app is killed ( working fine )单击通知以在应用程序被杀死时启动活动(工作正常)

  2. click on notification to launch activity when app is running on foreground ( working fine )当应用程序在前台运行时单击通知以启动活动(工作正常)

  3. click on notification to launch activity when app is running on background ( working fine )当应用程序在后台运行时单击通知以启动活动(工作正常)

but when i test on Xiaomi Note 4 ( MIUI 10 )但是当我在小米 Note 4(MIUI 10)上测试时

  1. click on notification to launch activity when app is killed ( working fine )单击通知以在应用程序被杀死时启动活动(工作正常)

  2. click on notification to launch activity when app is running on foreground ( crash - App has stopped )当应用程序在前台运行时单击通知以启动活动(崩溃 - 应用程序已停止)

  3. click on notification to launch activity when app is running on background ( crash - App has stopped )当应用程序在后台运行时单击通知以启动活动(崩溃 - 应用程序已停止)

Logcat:日志猫:

java.lang.OutOfMemoryError: Failed to allocate a 100000012 byte allocation with 16777216 free bytes and 82MB until OOM
        at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
        at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:624)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:457)
        at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1152)
        at android.content.res.ResourcesImpl.createFromResourceStream(ResourcesImpl.java:1296)
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:743)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:585)
        at android.content.res.MiuiResourcesImpl.loadDrawable(MiuiResourcesImpl.java:317)
        at android.content.res.Resources.loadDrawable(Resources.java:872)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
        at android.widget.ImageView.<init>(ImageView.java:157)
        at android.widget.ImageView.<init>(ImageView.java:145)
        at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
        at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
        at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:187)
        at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:107)
        at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
        at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1019)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:879)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1019)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:879)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:522)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.app.MainActivity.onCreate(MainActivity.java:62)
which is -> ( setContentView(R.layout.activity_main); )
        at android.app.Activity.performCreate(Activity.java:6845)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2700)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2808)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:165)
        at android.app.ActivityThread.main(ActivityThread.java:6375)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

tried changing flags, adding request id, and my things but no luck尝试更改标志、添加请求 ID 和我的东西,但没有运气

        super.onMessageReceived(remoteMessage);
            showNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
    }

   private void showNotification(String title, String body){
        NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        String NOTIFICATION_CHANNEL_ID = "com.hyatna_eg.hyatna";
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        {
            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Notification", NotificationManager.IMPORTANCE_DEFAULT);
            notificationChannel.setDescription("Hyatna Channel");
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(Color.BLUE);
            notificationChannel.setVibrationPattern(new long[]{0,1000,500,1000});
            notificationManager.createNotificationChannel(notificationChannel);

        }
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID);
        notificationBuilder.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.ic_notification)
                .setContentTitle(title)
                .setContentText(body)
                .setDefaults(Notification.DEFAULT_ALL)
                .setPriority(NotificationManager.IMPORTANCE_HIGH)
                .setPriority(Notification.PRIORITY_MAX)
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setSound(uri)
                .setContentIntent(pendingIntent)
                .setContentInfo("Info");

        notificationManager.notify(new Random().nextInt(),notificationBuilder.build());


    }

It's expected to work normal as HTC but i don't know why giving me crash?预计它可以像 HTC 一样正常工作,但我不知道为什么让我崩溃?

You must be loading very high resolution image which causing OutOfMemoryError exception in MainActivity .您必须加载非常高分辨率的图像,这会导致MainActivity中出现OutOfMemoryError异常。

It's expected to work normal as HTC but i don't know why giving me crash?预计它可以像 HTC 一样正常工作,但我不知道为什么让我崩溃?

It's working on HTC because its PPI density is 267 and Xiaomi's 401.它在 HTC 上工作,因为它的 PPI 密度是 267,而小米是 401。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM