android 之推送(本地推送遠端推送)

2021-07-11 20:18:53 字數 778 閱讀 8574

推送分為遠端推送和本地推送,都可以通過推送訊息跳轉到一些應用或者活動介面,本地推送幾行**就可以實現,遠端推送就需要借助一些平台的力量

(1)本地推送

notificationmanager nm=(notificationmanager) getsystemservice(context.notification_service);

string title = "通知標題" ;

string content = "通知內容" ;

//1.例項化乙個通知,指定圖示、概要、時間

notification n=new notification(r.drawable.ic_launcher,"這是通知,早上好",1000);

//2.指定通知的標題、內容和intent

intent intent = new intent(this, mainactivity.class);

//設定跳轉到的頁面 ,時間等內容

pendingintent pi= pendingintent.getactivity(this, 0, intent, 1000);

n.setlatesteventinfo(this, title, content, pi);

//3.指定聲音

n.defaults = notification.default_sound;

//4.傳送通知

nm.notify(1, n);

(2)遠端推送

遠端推送方面我用的是極光推送做的調研,參考的  這裡面就寫的很詳細



原 android本地推送

android本地推送的實現原理 開啟乙個broadcastreceiver和乙個alarmmanager,鬧鐘設定推送喚醒時間,broadcastreceiver一直在檢測是否應該推送。目前遺留問題,好多手機 關閉應用 service被殺死,無法接受推送。各種重啟service我也試了 小公尺手機...

iOS推送 實現本地推送

第一步 建立本地推送 建立乙個本地推送 uilocalnotification notification uilocalnotification alloc init autorelease 設定 10秒之後 nsdate pushdate nsdate datewithtimeintervalsi...

iOS推送 實現本地推送

第一步 建立本地推送 建立乙個本地推送 uilocalnotification notification uilocalnotification alloc init autorelease 設定10秒之後 nsdate pushdate nsdate datewithtimeintervalsin...