android - Why didn't the notification show? -
The app will post a notification but when you click it, nothing will happen.
/ / This imports a notification app android.os.Bundle; Import android App Import android.app.Notification; Import android.app.NotificationManager; Import android.app.PendingIntent; Import android.content.Intent; Import android.view.Menu; Import android.view.View; Import android.widget.Button; Public class extends the main activity (static final difference NOTIFICATION_ID = 0x1123; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); setContentView (R.layout.other); buttons BN 1 = (button) this.findViewById (R.id.button1); bn1.setOnClickListener (new View.OnClickListener () {@SuppressWarnings ( "resistance") @Override public void onClick (View v) {// TODO auto-generated method stub Intent = new intent (MainActivity.this, OtherActivity.class); PendingIntent Pending = PendingIntent.getActivity (MainActivity.this, 0, Intentions, 0); Notification notif = new Notification (); notif.icon = R.drawable.notify; notif.tickerText = "启动 其他 activity 的 通知"; notif When SystemkcurrentTimeMillis = (); Notifkdefaults = Notification .DEFAULT_SOUND; notif.defaults = Notification.DEFAULT_ALL; notif.setLatestEventInfo (MainActivity.this, "普通 通知", "点击 查看", pending); NotificationManager NFM = (notification Manager) system (NOTIFICATION_SERVICE); nfm.notify (NOTIFICATION_ID , Notif); }}); Button bn2 = (button) this.findViewById (R.id.button2); bn2.setOnClickListener (New View.OnClickListener () {@Override public void onClick (View v) {// TODO Auto-generated method stub NotificationManager NFM = (NotificationManager) MainActivity.this.getSystemService (NOTIFICATION_SERVICE); nfm.cancel (NOTIFICATION_ID) ;}}); }} // other activity Java package com.myapp.notification; Importroid.os.Bundle; Import android App Public class enhances other activity activity {@ Override Crate at Public Zero (Bundled Saved Instantstate) {super.onCreate (savedInstanceState); SetContentView (R.layout.other)}} // Make sure! XML layout file is no problem * /
step button for BN1 = (button ) This.findViewById (R.id.button1); bn1.setOnClickListener (New View.OnClickListener () {
And so on, onCreateView Method
Comments
Post a Comment