How to set text on status bar notification in Android

后端 未结 1 1238
长发绾君心
长发绾君心 2021-01-15 18:33

i dont know how to set status bar notifaction in android please give some idea

相关标签:
1条回答
  • 2021-01-15 19:18

    @spectrum you will refer:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

    Notification

    Notification notification = new Notification(
        android.R.drawable.stat_sys_warning,  //Icon to use
        "Hello World!", //Text
        System.currentTimeMillis() //When to display - i.e. now
    );
    

    Create a PendingIntent to do something when the user clicks on the Notification

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://www.stackoverflow.com"));
    PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
    
    //Add to the Notification
    notification.setLatestEventInfo(
        getApplicationContext(),
        "Stack Overflow", //Title of detail view
        "This will launch Stack Overflow",  //Text on detail view
        pi
    );
    //Display the Notification
    NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(ID_HELLO_WORLD, notification);  //ID_HELLO_WORLD is a int ID
    
    0 讨论(0)
提交回复
热议问题