日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

极光推送 android 最新,Android——快速集成极光推送-Go语言中文社区

發(fā)布時(shí)間:2024/9/27 Android 195 豆豆
生活随笔 收集整理的這篇文章主要介紹了 极光推送 android 最新,Android——快速集成极光推送-Go语言中文社区 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

集成極光推送

1,首先肯定是注冊(cè),添加應(yīng)用

2,開始自動(dòng)集成比手動(dòng)集成簡(jiǎn)單第一步 在 build.gradle

defaultConfig {

multiDexEnabledtrue

applicationId rootProject.ext.cfg.applicationId

minSdkVersionrootProject.ext.cfg.minSdkVersion

targetSdkVersionrootProject.ext.cfg.targetSdkVersion

versionCode rootProject.ext.pkg.versionCode

versionName rootProject.ext.pkg.versionName

testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"

vectorDrawables.useSupportLibrarytrue

jackOptions {

enabledtrue

}

// dex突破65535的限制

multiDexEnabledtrue

//默認(rèn)是umeng的渠道

manifestPlaceholders = [UMENG_CHANNEL_VALUE:"umeng"]

ndk {

//選擇要添加的對(duì)應(yīng)cpu類型的.so庫(kù)(不需要的刪除即可)。

abiFilters'armeabi','armeabi-v7a','armeabi-v8a','x86','x86_64','mips','mips64'

}

manifestPlaceholders= [

JPUSH_PKGNAME:applicationId,

JPUSH_APPKEY:"your appkey",//JPush上注冊(cè)的包名對(duì)應(yīng)的appkey(*換成你的*)

JPUSH_CHANNEL:"developer-default",//暫時(shí)填寫默認(rèn)值即可.

]

}

第二步

還是Module的build.gradle文件中哦

compile'cn.jiguang:jpush:2.1.8'// 此處以SDK 2.1.8版本為例

編譯一下

如果報(bào)錯(cuò)的話,需要在Project的gradle.properties文件中添加下面的代碼:

android.useDeprecatedNdk=true第三步 ? ?在MyApplication繼承 Application中onCreat()方法中

初始化sdk

JPushInterface.setDebugMode(true);//正式版的時(shí)候設(shè)置false,關(guān)閉調(diào)試

JPushInterface.init(this);

//建議添加tag標(biāo)簽,發(fā)送消息的之后就可以指定tag標(biāo)簽來發(fā)送了

Set set =newHashSet<>();

set.add("xunChang");//名字任意,可多添加幾個(gè)

set.add("Home");

set.add("Expand");

set.add("Mine");

JPushInterface.setTags(this,set, null);//設(shè)置標(biāo)簽第四步 ? 自定義廣播

packagecom.etcxc.android.base;

importandroid.content.BroadcastReceiver;

importandroid.content.Context;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.text.TextUtils;

importandroid.util.Log;

importorg.json.JSONException;

importorg.json.JSONObject;

importjava.util.Iterator;

importcn.jpush.android.api.JPushInterface;

/**

*自定義接收器

*

*如果不定義這個(gè)Receiver,則:

* 1)默認(rèn)用戶會(huì)打開主界面

* 2)接收不到自定義消息

*/

public classMyReceiverextendsBroadcastReceiver{

private static finalStringTAG="JIGUANG-Example";

@Override

public voidonReceive(Context context,Intent intent) {

try{

Bundle bundle = intent.getExtras();

Log.d(TAG,"[MyReceiver] onReceive - "+ intent.getAction() +", extras: "+printBundle(bundle));

if(JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {

String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);

Log.d(TAG,"[MyReceiver]接收Registration Id : "+ regId);

//send the Registration Id to your server...

}else if(JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {

Log.d(TAG,"[MyReceiver]接收到推送下來的自定義消息: "+ bundle.getString(JPushInterface.EXTRA_MESSAGE));

processCustomMessage(context,bundle);

}else if(JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {

Log.d(TAG,"[MyReceiver]接收到推送下來的通知");

intnotifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);

Log.d(TAG,"[MyReceiver]接收到推送下來的通知的ID: "+ notifactionId);

}else if(JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {

Log.d(TAG,"[MyReceiver]用戶點(diǎn)擊打開了通知");

//? ? ? ? ? //打開自定義的Activity

//? ? ? ? ? Intent i = new Intent(context, TestActivity.class);

//? ? ? ? ? i.putExtras(bundle);

//? ? ? ? ? //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

//? ? ? ? ? i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );

//? ? ? ? ? context.startActivity(i);

}else if(JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {

Log.d(TAG,"[MyReceiver]用戶收到到RICH PUSH CALLBACK: "+ bundle.getString(JPushInterface.EXTRA_EXTRA));

//在這里根據(jù)JPushInterface.EXTRA_EXTRA的內(nèi)容處理代碼,比如打開新的Activity, 打開一個(gè)網(wǎng)頁等..

}else if(JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {

booleanconnected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);

Log.w(TAG,"[MyReceiver]"+ intent.getAction() +" connected state change to "+connected);

}else{

Log.d(TAG,"[MyReceiver] Unhandled intent - "+ intent.getAction());

}

}catch(Exception e){

}

}

//打印所有的intent extra數(shù)據(jù)

private staticStringprintBundle(Bundle bundle) {

StringBuilder sb =newStringBuilder();

for(String key : bundle.keySet()) {

if(key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {

sb.append("nkey:"+ key +", value:"+ bundle.getInt(key));

}else if(key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)){

sb.append("nkey:"+ key +", value:"+ bundle.getBoolean(key));

}else if(key.equals(JPushInterface.EXTRA_EXTRA)) {

if(TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {

Log.i(TAG,"This message has no Extra data");

continue;

}

try{

JSONObject json =newJSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));

Iterator it =? json.keys();

while(it.hasNext()) {

String myKey = it.next().toString();

sb.append("nkey:"+ key +", value: ["+

myKey +" - "+json.optString(myKey) +"]");

}

}catch(JSONException e) {

Log.e(TAG,"Get message extra JSON error!");

}

}else{

sb.append("nkey:"+ key +", value:"+ bundle.getString(key));

}

}

returnsb.toString();

}

//send msg to MainActivity

private voidprocessCustomMessage(Context context,Bundle bundle) {

//? ? if (MainActivity.isForeground) {

//? ? ? String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);

//? ? ? String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);

//? ? ? Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);

//? ? ? msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);

//? ? ? if (!ExampleUtil.isEmpty(extras)) {

//? ? ? ? ? try {

//? ? ? ? ? ? JSONObject extraJson = new JSONObject(extras);

//? ? ? ? ? ? if (extraJson.length() > 0) {

//? ? ? ? ? ? ? ? msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);

//? ? ? ? ? ? }

//? ? ? ? ? } catch (JSONException e) {

//

//? ? ? ? ? }

//

//? ? ? }

//? ? ? LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);

//? ? }

}

}第五步 注冊(cè)廣播? AndroidManifest.xml 并添加相應(yīng)權(quán)限 ,看官網(wǎng)demo添加

AndroidManifest.xml

第六步、混淆

在ProGuard文件(即proguard-rules.pro)中加入混淆代碼:

-dontoptimize

-dontpreverify

-dontwarn cn.jpush.**

-keepclasscn.jpush.** { *;}最后 ?去測(cè)試吧~~~~~~

總結(jié)

以上是生活随笔為你收集整理的极光推送 android 最新,Android——快速集成极光推送-Go语言中文社区的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。