开发者

android trying to figure out how to create a notification

I'm trying to create a notification in andro开发者_高级运维id. The icon gets displyed, and the text vaneshed. Also when you click it the Intent does not get called. (I have a test intent that should bring up the web browser). I cannot figure out why the text goes away and when I click the sttus bar, the browser does not come up. code

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);
    }
}

Ted


You could try initializing your notifyIntent with the

new Intent(packageContext:Context, cls:Class<?>)

constructor.

To see how the new Intent(action:String, uri:Uri) works, please see the overview of the Intent class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜