通知无法在MI redmi 4中扩展

时间:2017-09-19 05:04:14

标签: android push-notification

我正在制作一个项目,我需要在其中显示带图像的自定义notifications,它在所有手机中都运行良好,但在“MI redmi note 4” 它不能扩展。我已经尝试了下面的代码,除了MI redmi note 4之外,所有其他设备都能正常工作。有没有解决方法呢?请帮帮我。

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        notification();
    }

    private void notification() {

        NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.customnoti);
        contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher);
        contentView.setImageViewResource(R.id.dec_img, R.mipmap.ic_launcher);
        contentView.setTextViewText(R.id.title, "Custom notification");
        contentView.setTextViewText(R.id.text, "This is a custom layout");

        NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setPriority(Notification.PRIORITY_MAX)
                .setContent(contentView)
                ;

        Notification notification = mBuilder.build();


        if (Build.VERSION.SDK_INT >= 16) {
            // Inflate and set the layout for the expanded notification view
            RemoteViews expandedView =
                    new RemoteViews(getPackageName(), R.layout.customnoti);
            notification.bigContentView = expandedView;
        }

        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationmanager.notify(1, notification);

    }
}

customnoti.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:orientation="vertical">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp" >
        <ImageView
            android:src="@mipmap/ic_launcher"
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginRight="10dp" />
        <TextView
            android:textSize="13dp"
            android:textColor="#000"
            android:text="Testing"
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/image"
            />
        <TextView
            android:textSize="13dp"
            android:textColor="#000"
            android:text="Testing is awecome"
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/image"
            android:layout_below="@id/title"
            />
    </RelativeLayout>

    <ImageView
        android:id="@+id/dec_img"
        android:src="@mipmap/ic_launcher"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="10dp" />


</LinearLayout>

enter image description here

0 个答案:

没有答案