android notification 的例子
16lz
2021-01-23
public class SimpleNotification extends Activity { private NotificationManager mNotificationManager; private int SIMPLE_NOTFICATION_ID; /** 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); final Notification notifyDetails = new Notification(R.drawable.android,"New Alert, Click Me!",System.currentTimeMillis()); Button start = (Button)findViewById(R.id.notifyButton); Button cancel = (Button)findViewById(R.id.cancelButton); start.setOnClickListener(new OnClickListener() { public void onClick(View v) { Context context = getApplicationContext(); CharSequence contentTitle = "Notification Details..."; CharSequence contentText = "Browse Android Official Site by clicking me"; Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com")); PendingIntent intent = PendingIntent.getActivity(SimpleNotification.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent); mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); } }); cancel.setOnClickListener(new OnClickListener() { public void onClick(View v) { mNotificationManager.cancel(SIMPLE_NOTFICATION_ID); } }); } } //hello word级别的例子。
更多相关文章
- android aidl使用小例子
- Android学习札记36:一个关于onSaveInstanceState ()方法的例子
- android binder c++层-客户端(c++) 调用 服务端(c++) 例子
- android上实现语音识别,基于google的语音识的简单例子.
- 如何导入android 自带的例子
- Android Toast 例子
- Android 实现旋转键盘的例子