android试图弄清楚如何创建通知

时间:2011-04-28 19:42:48

标签: android notifications

我正在尝试在android中创建通知。图标变得显而易见,文本变得清晰。此外,当您单击它时,不会调用Intent。 (我有一个应该启动Web浏览器的测试意图)。 我无法弄清楚为什么文本会消失,当我点击sttus栏时,浏览器不会出现。 代码

public class Welcome extends Activity
{
    private NotificationManager mNotificationManager;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mNotificationManager = (NotificationManager) 
            getSystemService(NOTIFICATION_SERVICE);
        Notification notifyDetails = new Notification(
                R.drawable.icon, "Click Me!", System.currentTimeMillis());

        Context context = getApplicationContext();
        CharSequence contentTitle = "Notification Details...";
        CharSequence contentText = "Ted";
        Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW, 
                Uri.parse("http://www.android.com"));

        PendingIntent intent = PendingIntent.getActivity(this, 0, notifyIntent, 
                android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
        notifyDetails.setLatestEventInfo(context, contentTitle, 
                contentText, intent);
        mNotificationManager.notify(1, notifyDetails);
    }
}

泰德

1 个答案:

答案 0 :(得分:0)

您可以尝试使用

初始化notifyIntent
new Intent(packageContext:Context, cls:Class<?>)

构造。

要查看new Intent(action:String, uri:Uri)的工作原理,请参阅overview of the Intent class