public void showUpdateNotification ( String content ,String url){
Intent updateIntent = new Intent();
updateIntent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse(url);
updateIntent.setData(content_url);
PendingIntent pt =PendingIntent.getActivity (this , 0,updateIntent , 0);//点击通知要跳到的activity
NotificationManager notificationManager = (NotificationManager )getSystemService (Context .NOTIFICATION_SERVICE );
Resources res = getResources();
String title = "有更新版本啦";
Notification notification = null;
int NOTIF_ID = R.string.app_name;
Builder builder = new Notification.Builder(this);
builder.setContentIntent(pt)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.ic_launcher))
.setWhen(System.currentTimeMillis()).setAutoCancel(false)
.setTicker(title)
.setAutoCancel(false)
.setContentTitle(title)
.setContentText(content);
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN){
notification = builder.build();
}else {
notification = builder.getNotification();;
}
notificationManager.notify (NOTIF_ID , notification );
}
转载于:https://my.oschina.net/kevinvane/blog/190205