懸浮通知碎节,例如QQ的懸浮通知捧搞,在你瀏覽網(wǎng)頁的時候,或者瀏覽空間的時候狮荔,QQ會彈出一個懸浮的通知胎撇,這時候只要你點擊了就可以打開QQ消息了。
通知不需要權(quán)限殖氏。但是MIUI系統(tǒng)會有通知的管理晚树。
代碼如下:
final NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
? ? Intent intent = new Intent(Settings.ACTION_SETTINGS);?
? ? NotificationCompat.Builder builder =new NotificationCompat.Builder(this);
? ? builder.setContentTitle("騰訊定位").setSmallIcon(R.drawable.ic_launcher).setContentText("請打開網(wǎng)絡(luò)或者GPS!").setAutoCancel(true);
? ? builder.setDefaults(NotificationCompat.PRIORITY_DEFAULT).setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, intent, 0));
? ? builder.setFullScreenIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT), true);
? ? Notification notification = builder.build();
? ? final int notifyId=0x12345;
? ? notificationManager.notify(notifyId,notification);
? ? //下面一個線程就是為了讓通知再5秒之后自動消失
? ? new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(5000);
notificationManager.cancel(notifyId);//清除通知
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
彈出的通知如下:
下面是小米手機(jī)MIUI的通知管理雅采,如果你禁止了懸浮通知爵憎,軟件會在通知觸發(fā)的時候就會直接打開Intent慨亲。