使用場景
1.項目中耗時操作,比如上傳多張說說照片,上傳文件等;
2.發佈長篇說說等。
點擊發布說說或上傳照片時,設置發佈中…
Bitmap btm = BitmapFactory.decodeResource(getResources(),
R.drawable.logo);//設置logo
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext())
.setSmallIcon(R.drawable.logo)
.setContentTitle("發佈中...");
mBuilder.setTicker("發佈中...");//第一次提示消息的時候顯示在通知欄上
mBuilder.setLargeIcon(btm);
mBuilder.setAutoCancel(true);//自己維護通知的消失
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
2.通過調接口,返回成功後設置,發佈成功
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// mNotificationManager.cancel(0);
Bitmap btm = BitmapFactory.decodeResource(getResources(),
R.drawable.logo);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext())
.setSmallIcon(R.drawable.logo)
.setContentTitle("發佈成功");
mBuilder.setTicker("發佈成功");//第一次提示消息的時候顯示在通知欄上
mBuilder.setLargeIcon(btm);
mBuilder.setAutoCancel(true);//自己維護通知的消失
mNotificationManager.notify(0, mBuilder.build());
mNotificationManager.cancel(0);
3.如果返回失敗,或者網絡無連接,提示發佈失敗
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Bitmap btm = BitmapFactory.decodeResource(getResources(),
R.drawable.logo);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext())
.setSmallIcon(R.drawable.logo)
.setContentTitle("發佈失敗");
mBuilder.setTicker("發佈失敗");//第一次提示消息的時候顯示在通知欄上
mBuilder.setLargeIcon(btm);
mBuilder.setAutoCancel(true);//自己維護通知的消失
mNotificationManager.notify(0, mBuilder.build());
4.項目中直接複製粘貼,換下logo即可使用,項目親測實用。