【问题标题】:How to set text on status bar notification in Android如何在 Android 中的状态栏通知上设置文本
【发布时间】:2011-04-30 15:38:40
【问题描述】:

我不知道如何在android中设置状态栏通知,请给出一些想法

【问题讨论】:

    标签: android


    【解决方案1】:

    @spectrum 你会参考:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

    通知

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

    创建一个 PendingIntent 以在用户点击通知时执行某些操作

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多