【问题标题】:Android small and big notificationsAndroid 大小通知
【发布时间】:2017-05-26 06:19:06
【问题描述】:

有些手机不支持大通知。那么我怎么知道在运行时让我的通知变大或通常大小?我也需要它支持控制按钮。 这是我的大通知代码:

RemoteViews remoteViews = new RemoteViews(getPackageName(),
            settings.getAttributeId(settings.getThemeByString(), R.attr.theme_dependent_notification));

    remoteViews.setOnClickPendingIntent(R.id.prev, ppreviousIntent);
    remoteViews.setOnClickPendingIntent(R.id.play, pplayIntent);
    remoteViews.setOnClickPendingIntent(R.id.next, pnextIntent);
    remoteViews.setOnClickPendingIntent(R.id.close, pcloseIntent);

    remoteViews.setImageViewBitmap(R.id.cover, icon);
    remoteViews.setTextViewText(R.id.name, title);
    remoteViews.setTextViewText(R.id.artist, text);
    remoteViews.setTextViewText(R.id.count, count);

    if (isPlayerActive) remoteViews.setImageViewResource(R.id.play, R.drawable.pause);
    else remoteViews.setImageViewResource(R.id.play, R.drawable.play);

    notification = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.equalizer_icon)
            .setContentTitle(title)
            .setContentText(text)
            .setTicker(getString(R.string.app_name))
            .setContentIntent(pendingIntent)
            .setPriority(Notification.PRIORITY_MAX)
            .build();

    notification.bigContentView = remoteViews;

【问题讨论】:

    标签: android android-notifications android-remoteview


    【解决方案1】:

    试试这个代码:

    public static void showNotification(Context context) {
        int notificationId = 99;
        Intent cancelIntent = new Intent(YOUR_ACTION).putExtra(YOUR_EXTRA_NOTIFICATION_ID, notificationId);
        PendingIntent buttonPendingIntent = PendingIntent.getBroadcast(context, 123, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    
        NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(context)
                .setAutoCancel(false)
                .setOngoing(true)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setSmallIcon(android.R.drawable.stat_notify_sync)
                .setTicker("Ticker title")
                .setOnlyAlertOnce(true)
                .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, YourActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
    
        Notification not = notBuilder
                .setContentTitle("Title")
                .setContentText("Message")
                .setProgress(100, 33, false)
                .addAction(android.R.drawable.ic_menu_close_clear_cancel, "Cancel", buttonPendingIntent)
                .setStyle(new NotificationCompat.BigTextStyle().bigText("Message"))
                .build();
    
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationId, not);
    }
    

    它通过一个按钮显示一个大通知 - 您可以通过向下拉底部边缘来放大它。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    相关资源
    最近更新 更多