Android 友盟推送开发
生活随笔
收集整理的這篇文章主要介紹了
Android 友盟推送开发
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
推送廠商集成文檔:https://developer.umeng.com/docs/67966/detail/98589?spm=a311a.9588098.0.0#h1-vivo-push-5
?
SDK下載:https://developer.umeng.com/sdk/android?
?
集成步驟
?
1、導(dǎo)入依賴
?
implementation 'com.umeng.sdk:common:1.5.3' implementation 'com.umeng.sdk:push:4.2.0' // 添加友盟分享庫 implementation 'cn.dlc.android:umeng-share:1.0.4'2、在Application初始化?
?
/*** 初始化友盟SDK*/private void initUmengSDK() {/*** 方法2,直接初始化,app key和channel為null的話,等價于方法1* 初始化common庫* 參數(shù)1:上下文,不能為空* 參數(shù)2:友盟 app key* 參數(shù)3:友盟 channel* 參數(shù)4:設(shè)備類型,UMConfigure.DEVICE_TYPE_PHONE為手機、UMConfigure.DEVICE_TYPE_BOX為盒子,默認(rèn)為手機* 參數(shù)5:Push推送業(yè)務(wù)的secret,需要集成Push功能時必須傳入Push的secret,否則傳空*/UMConfigure.init(this, Information.UmengAppkey, Information.UmengChannel,UMConfigure.DEVICE_TYPE_PHONE, Information.UmengPushSecret);PushAgent instance = PushAgent.getInstance(this);instance.register(new IUmengRegisterCallback() {@Overridepublic void onSuccess(String s) {Log.e("xsw", "推送id友盟token: "+s );UserHelper.get().saveUmengToken(s);}@Overridepublic void onFailure(String s, String s1) {Log.e("xsw", s+"---"+s1 );}});UmengNotificationClickHandler umengNotificationClickHandler = new UmengNotificationClickHandler(){@Overridepublic void launchApp(Context context, UMessage uMessage) {Intent mIntent = new Intent(sInstance, WelcomeActivity.class);//自定義通知欄點擊事件mIntent.putExtra("notification",true);mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );startActivity(mIntent);}};instance.setNotificationClickHandler(umengNotificationClickHandler);UmengMessageHandler messageHandler = new UmengMessageHandler() {@Overridepublic Notification getNotification(Context context, UMessage msg) {LgqLog.e(msg.text+"....推送id==== "+msg.builder_id);//推送內(nèi)容和IDMessage msgg = new Message();msgg.what = 1;Bundle bundle = new Bundle();bundle.putString("text1",msg.text); //往Bundle中存放數(shù)據(jù)msgg.setData(bundle);//mes利用Bundle傳遞數(shù)據(jù) // mHandler.sendMessage(msgg);//用activity中的handler發(fā)送消息mHandler.sendMessageAtTime(msgg,2000);switch (msg.builder_id) {case 1://自定義通知欄Notification.Builder builder = new Notification.Builder(context);RemoteViews myNotificationView = new RemoteViews(context.getPackageName(),R.layout.notification_view);SimpleDateFormat df = new SimpleDateFormat("HH:mm");//設(shè)置日期格式"yyyy年-MM月dd日-HH時mm分ss秒"String dfd = df.format(new Date());myNotificationView.setTextViewText(R.id.notification_title, msg.title);myNotificationView.setTextViewText(R.id.notification_text, msg.text);myNotificationView.setTextViewText(R.id.timete, dfd); // myNotificationView.setImageViewBitmap(R.id.notification_large_icon, // getLargeIcon(context, msg)); // myNotificationView.setImageViewResource(R.id.notification_small_icon, // getSmallIconId(context, msg));builder.setContent(myNotificationView).setSmallIcon(getSmallIconId(context, msg)).setTicker(msg.ticker).setAutoCancel(true);return builder.getNotification();default://默認(rèn)為0,若填寫的builder_id并不存在,也使用默認(rèn)。return super.getNotification(context, msg);}}};instance.setMessageHandler(messageHandler);instance.setDisplayNotificationNumber(0);}?
總結(jié)
以上是生活随笔為你收集整理的Android 友盟推送开发的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: myeclipse快捷生成代码块
- 下一篇: 数理统计之卡方检验