- public class MainActivity extends Activity{
- private Button show;
- private PendingIntent contentIntent;
- private Intent intent;
- private NotificationManager manager;
- private Notification notification;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- intent = new Intent(Intent.ACTION_VIEW);
- intent.setType("vnd.android-dir/mms-sms");
- contentIntent =PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
- //1.notification进行提示(一闪而过的)时候的图片,提示,以及时间(一般设为当前时间)
- notification =new Notification(R.drawable.ic_launcher, "有新消息", System.currentTimeMillis());
- //2. 设置下拉status bar出现的 notification标题和具体内容,以及点击notification进行跳转的pendingIntent
- notification.setLatestEventInfo(getApplicationContext(), "10086", "尊敬的用户您好,最近....", contentIntent);
- //3. 实例化NotificationManager
- manager =(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- show = (Button) findViewById(R.id.button);
- show.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //4. 设置要唤醒的notification的id
- manager.notify(0, notification);
- }
- });
- }
- }
转载于:https://blog.51cto.com/vincenttung/1141087