国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

信鴿推送用法

2019-11-09 14:28:10
字體:
來源:轉載
供稿:網友
step1.注冊并下載SDK 地址http://xg.QQ.com/apps/ctr_app應用創建成功后,點擊“應用配置”即可看到APP專屬的accessId和AccessKey等信息。step2.導入jar包setp3.配置Androidmanifest.xml<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.dc.xgdemo"><!-- 【必須】 信鴿SDK所需權限 --><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.READ_PHONE_STATE" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.WRITE_SETTINGS" /><uses-permission android:name="android.permission.WAKE_LOCK" /><uses-permission android:name="android.permission.VIBRATE" /><!-- 【常用】 信鴿SDK所需權限 --><uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" /><uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><!-- 【可選】 信鴿SDK所需權限 --><uses-permission android:name="android.permission.RESTART_PACKAGES" /><uses-permission android:name="android.permission.BROADCAST_STICKY" /><uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /><uses-permission android:name="android.permission.GET_TASKS" /><uses-permission android:name="android.permission.READ_LOGS" /><uses-permission android:name="android.permission.BLUETOOTH" /><uses-permission android:name="android.permission.BATTERY_STATS" /><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:supportsRtl="true"android:theme="@style/APPTheme"><activity android:name=".MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><!-- 【必須】 (2.30及以上版新增)展示通知的activity --><activityandroid:name="com.tencent.android.tpush.XGPushActivity"android:exported="false"android:theme="@android:style/Theme.Translucent"><intent-filter><!-- 若使用AndroidStudio,請設置android:name="android.intent.action" --><action android:name="android.intent.action" /></intent-filter></activity><!-- 【必須】 信鴿receiver廣播接收 --><receiverandroid:name="com.tencent.android.tpush.XGPushReceiver"android:process=":xg_service_v2"><intent-filter android:priority="0x7fffffff"><!-- 【必須】 信鴿SDK的內部廣播 --><action android:name="com.tencent.android.tpush.action.SDK" /><action android:name="com.tencent.android.tpush.action.INTERNAL_PUSH_MESSAGE" /><!-- 【必須】 系統廣播:網絡切換 --><action android:name="android.net.conn.CONNECTIVITY_CHANGE" /><!-- 【可選】 系統廣播:開屏 --><action android:name="android.intent.action.USER_PRESENT" /><!-- 【可選】 一些常用的系統廣播,增強信鴿service的復活機會,請根據需要選擇。當然,你也可以添加APP自定義的一些廣播讓啟動service --><action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /><action android:name="android.intent.action.ACTION_POWER_CONNECTED" /><action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" /></intent-filter><!-- 【可選】 usb相關的系統廣播,增強信鴿service的復活機會,請根據需要添加 --><intent-filter android:priority="0x7fffffff"><action android:name="android.intent.action.MEDIA_UNMOUNTED" /><action android:name="android.intent.action.MEDIA_REMOVED" /><action android:name="android.intent.action.MEDIA_CHECKING" /><action android:name="android.intent.action.MEDIA_EJECT" /><data android:scheme="file" /></intent-filter></receiver><!-- 【必須】 信鴿service --><serviceandroid:name="com.tencent.android.tpush.service.XGPushService"android:exported="true"android:persistent="true"android:process=":xg_service_v2" /><!-- 【必須】 --><serviceandroid:name="com.tencent.android.tpush.rpc.XGRemoteService"android:exported="true"><intent-filter><!-- 【必須】 請修改為當前APP名包.PUSH_ACTION,如demo的包名為:com.example.dc.xgdemo --><action android:name="com.example.dc.xgdemo.PUSH_ACTION" /></intent-filter></service><!-- 【必須】 請修改為APP的AccessId,“21”開頭的10位數字,中間沒空格 --><meta-dataandroid:name="XG_V2_ACCESS_ID"android:value="2100250500" /><!-- 【必須】 請修改為APP的AccessKey,“A”開頭的12位字符串,中間沒空格 --><meta-dataandroid:name="XG_V2_ACCESS_KEY"android:value="A95A2HLQ4K1K" /></application></manifest>step4.在activity中注冊信鴿public class MainActivity extends AppCompatActivity {Message m = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);XGPushConfig.enableDebug(this, true);setContentView(R.layout.activity_main);getToken();}/*** 獲取設備Token*/private void getToken() {Handler handler = new HandlerExtension(MainActivity.this);m = handler.obtainMessage();// 注冊接口XGPushManager.registerPush(getApplicationContext(), "單個賬號",new XGIOperateCallback() {@Overridepublic void onSuccess(Object data, int flag) {Log.i("info", "+++ register push sucess. token:" + data);m.obj = "+++ register push sucess. token:" + data;m.sendToTarget();}@Overridepublic void onFail(Object data, int errCode, String msg) {Log.i("info", "+++ register push fail. token:" + data+ ", errCode:" + errCode + ",msg:" + msg);m.obj = "+++ register push fail. token:" + data+ ", errCode:" + errCode + ",msg:" + msg;m.sendToTarget();}});}@Overrideprotected void onNewIntent(Intent intent) {super.onNewIntent(intent);setIntent(intent);}@Overrideprotected void onPause() {super.onPause();XGPushManager.onActivityStoped(this);}private static class HandlerExtension extends Handler {WeakReference<MainActivity> mActivity;HandlerExtension(MainActivity activity) {mActivity = new WeakReference<>(activity);}@Overridepublic void handleMessage(Message msg) {super.handleMessage(msg);MainActivity theActivity = mActivity.get();if (theActivity == null) {theActivity = new MainActivity();}if (msg != null) {Log.i("info", "msg--->" + msg.obj.toString());}}}}setp5.如果要處理廣播創建一個廣播類XGPushBaseReceiverpublic class MessageReceiver extends XGPushBaseReceiver{@Overridepublic void onRegisterResult(Context context, int i, XGPushRegisterResult xgPushRegisterResult) {}@Overridepublic void onUnregisterResult(Context context, int i) {}@Overridepublic void onSetTagResult(Context context, int i, String s) {}@Overridepublic void onDeleteTagResult(Context context, int i, String s) {}/*** 消息透傳* @param context* @param xgPushTextMessage*/@Overridepublic void onTextMessage(Context context, XGPushTextMessage xgPushTextMessage) {if(xgPushTextMessage!=null){Log.e("info","message:"+xgPushTextMessage.toString());}}/*** 通知點擊回調* @param context* @param xgPushClickedResult*///可以直接在activity中獲取,下面這個方法是寫在activity中的// protected void onResume() {// // TODO Auto-generated method stub// super.onResume();// XGPushClickedResult click = XGPushManager.onActivityStarted(this);// Log.d("TPush", "onResumeXGPushClickedResult:" + click);// if (click != null) { // 判斷是否來自信鴿的打開方式// Toast.makeText(this, "通知被點擊:" + click.toString(),// Toast.LENGTH_SHORT).show();// }// }@Overridepublic void onNotifactionClickedResult(Context context, XGPushClickedResult xgPushClickedResult) {if(xgPushClickedResult!=null){Log.e("info","click:"+xgPushClickedResult.toString());}}/*** 通知的內容* @param context* @param xgPushShowedResult*/@Overridepublic void onNotifactionShowedResult(Context context, XGPushShowedResult xgPushShowedResult) {if(xgPushShowedResult!=null){Log.e("info","notifaction:"+xgPushShowedResult.toString());}}}注冊廣播<!-- YOUR_PACKAGE_PATH.CustomPushReceiver需要改為自己的Receiver: --><receiver android:name=".receiver.MessageReceiver"android:exported="true" ><intent-filter><!-- 接收消息透傳 --><action android:name="com.tencent.android.tpush.action.PUSH_MESSAGE" /><!-- 監聽注冊、反注冊、設置/刪除標簽、通知被點擊等處理結果 --><action android:name="com.tencent.android.tpush.action.FEEDBACK" /></intent-filter></receiver>項目下載地址:http://download.csdn.net/detail/daidaishuiping/9752414
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新巴尔虎左旗| 乌兰浩特市| 丹寨县| 祁阳县| 镇赉县| 扬州市| 鸡泽县| 云浮市| 普洱| 德兴市| 庐江县| 东乌| 涿州市| 锡林浩特市| 凤凰县| 九台市| 朔州市| 新竹县| 陆河县| 象山县| 沙洋县| 吉首市| 科技| 柘城县| 西城区| 上虞市| 桐庐县| 稷山县| 颍上县| 永福县| 苏州市| 长子县| 齐齐哈尔市| 阳山县| 上栗县| 普兰店市| 舟曲县| 清苑县| 长泰县| 从化市| 栾川县|