Notification

1.android3.0版本以上的用法:

NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
       Notification.Builder nb=new Builder(DownLoadService.this);                
       Intent intent=new Intent();
       intent.setAction(Intent.ACTION_CALL);
       intent.setData(Uri.parse("tel:110"));
       PendingIntent pendingIntent=PendingIntent.getActivity(DownLoadService.this, 0, intent, 0);
       nb.setContentTitle("标题");
       nb.setContentText("内容");
       nb.setSmallIcon(R.drawable.alert_dark_frame);
       nb.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.alert_dark_frame));
       nb.setContentIntent(pendingIntent);
       Notification notification=nb.build();
       notification.flags= Notification.FLAG_AUTO_CANCEL;
       nm.notify(0, notification);



2.android任何版本通用用法:

NotificationManager nm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
       Notification notification=new Notification(R.drawable.alert_dark_frame,"",System.currentTimeMillis());
       notification.flags= Notification.FLAG_AUTO_CANCEL;
       Intent intent=new Intent();
       intent.setAction(Intent.ACTION_CALL);
       intent.setData(Uri.parse("tel:110"));
       PendingIntent pendingIntent=PendingIntent.getActivity(this, 0, intent, 0);
       notification.setLatestEventInfo(this, "标题", "内容", pendingIntent);
       nm.notify(0, notification);


你可能感兴趣的:(移动开发,notification)