How to show the message on the top bar in Android

I want to show this message at the top of Android after completing some background work. How can I show this notification? Thank..

enter image description here

+4
source share
4 answers

It looks like a ticker text Notification, suggesting that this screenshot is at the top of the screen. You can add this to Notificationvia setTicker()onNotificationCompat.Builder . However, note that the text of the ticker is no longer displayed from API level 21 (Android 5.0). Also note that the ticker text automatically disappears after a couple of seconds.

+4
source

, , , , ..... : http://developer.android.com/guide/topics/ui/notifiers/notifications.html

google dev:

NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle("My notification")
    .setContentText("Hello World!");
Intent resultIntent = new Intent(this, ResultActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ResultActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
    stackBuilder.getPendingIntent(
        0,
        PendingIntent.FLAG_UPDATE_CURRENT
    );
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mBuilder.build());

!

+2

setTicker ( doc ):

NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_event)
        .setContentTitle(eventTitle)
        .setContentText(eventLocation)
        .setContentIntent(viewPendingIntent)
        .setTicker("Your message");
+1

SYSTEM_ALERT_WINDOW, , .

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT);

params.gravity = Gravity.CENTER|Gravity.TOP;

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
wm.addView(view, params);





<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
0

All Articles