通知栏 - 如何在那里写文字

Bak*_*kih 2 android

我想知道如何只在通知栏上写通知文本和通知布局上的不同文本?

S.T*_*ane 11

接受的答案包含deprecated类和方法.看看这里.

这是一个NotificationCompat.Builder用于构建Notifications 的示例:

        Intent notificationIntent = new Intent(this, MyClass.class);  
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.my_drawable_resource)
            .setContentTitle("my title")
            .setContentText("my content")
            .setContentIntent(pendingIntent);
        Notification notification = mBuilder.build();
            // default phone settings for notifications
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_SOUND;

            // cancel notification after click
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
            // show scrolling text on status bar when notification arrives
        notification.tickerText = title + "\n" + content;

            // notifiy the notification using NotificationManager
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)

可以帮助新人!


Pom*_*air 9

NotificationCompat.Builder类有方法setTicker(),可以让你做到这一点.