移動推送 騰訊信鴿集成
阿新 • • 發佈:2018-04-09
fish intent ndk oid his ken 3.2 mes ror
背景
現在移動推送很多大廠都在做,騰訊信鴿跟個推、極光、友盟比算是比較晚的一個了。
但這並不妨礙我用它。
服務端
這邊服務端用的C#,有兩種方式集成騰訊信鴿:
1.引用官方編譯好的XingeApp.dll
推薦,相當簡單方便,基本的Api都有。
ps:老版本的NewtonsoftJson(低於10.0.0)可能會報錯。
2.調用Restful Api
不談,稍微麻煩了些。
Android端
推薦使用Android Studio一鍵引用。就很方便了。(基於AS 3.0.1)
build.gradle
apply plugin: ‘com.android.application‘ android { compileSdkVersion 26 defaultConfig { ... ndk { abiFilters ‘armeabi‘, ‘armeabi-v7a‘, ‘arm64-v8a‘ } manifestPlaceholders = [ XG_ACCESS_ID:"your id", XG_ACCESS_KEY : "your key", ] } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘ } } } dependencies { ... implementation ‘com.tencent.xinge:xinge:3.2.2-release‘ implementation ‘com.tencent.wup:wup:1.0.0.E-release‘ implementation ‘com.tencent.mid:mid:4.0.6-release‘ }
註冊清單Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kuaijiajin.julynovel">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".application.MyApplication"
android:theme="@style/AppTheme">
<receiver android:name=".receiver.XGReceiver"
android:enabled="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>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
在業務界面或者Application處註冊
public class MyApplication extends Application {
@Override
public void onCreate(){
super.onCreate();
XGPushManager.enableService(this, true);
XGPushManager.registerPush(this, new XGIOperateCallback() {
@Override
public void onSuccess(Object o, int i) {
LogUtils.dTag("註冊成功,設備token為:", o);
}
@Override
public void onFail(Object o, int errCode, String s) {
ToastUtils.showLong("註冊失敗,錯誤碼:" + errCode + ",錯誤信息:" + s);
}
});
}
}
繼承receiver實現點擊跳轉
public class XGReceiver extends XGPushBaseReceiver {
@Override
public void onTextMessage(Context context,XGPushTextMessage message){
}
@Override
public void onRegisterResult(Context context,int errorCode,XGPushRegisterResult registerMessage){
}
@Override
public void onUnregisterResult(Context context, int errorCode){
}
@Override
public void onSetTagResult(Context context,int errorCode,String tagName){
}
@Override
public void onDeleteTagResult(Context context, int errorCode,String tagName){
}
@Override
public void onNotifactionShowedResult(Context context, XGPushShowedResult notifiShowedRlt){
}
@Override
public void onNotifactionClickedResult(Context context, XGPushClickedResult message){
if(ActivityUtils.isActivityExists("com.kuaijiajin.julynovel", MainActivity.class.getName())){
ActivityUtils.finishToActivity(MainActivity.class, false);
MainActivity activity = (MainActivity) ActivityUtils.getActivityList().get(0);
if(activity.mHandler != null){
Message msg = new Message();
Bundle bundle = new Bundle();
bundle.putString("content", message.getContent());
bundle.putString("title", message.getTitle());
msg.what = 1;
msg.setData(bundle);
activity.mHandler.sendMessage(msg);
}
}else{
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
}
}
}
移動推送 騰訊信鴿集成