Aurora Push Fast Integration

Read-through: Quick integration takes only 5 steps to complete. jcenter in official documents automatically integrates steps, but it takes time to look at the documents, and then look here between encounters in the future to improve efficiency.

Step 1 Configuration
In module Buile.Gradle defaultconfig configuration for

ndk {


//Select the.so library that corresponds to the type of cpu you want to add.
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
// You can also add 'x86', 'x86_64', 'mips', 'mips64'
}

manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "Your appkey", //appkey for package name registered on JPush.
JPUSH_CHANNEL : "developer-default", //Just fill in the default values temporarily.
]

Step 2 Adding Dependencies
Build.gradle Dependencies of add dependencies

dependencies {
compile 'cn.jiguang.sdk:jpush:3.0.9' // Here's an example of JPush version 3.0.9.
compile 'cn.jiguang.sdk:jcore:1.1.7' // Here is an example of JCore version 1.1.7.
}

Step 3 Initializing SDK
Initialize the SDK in the application, remember that it must be in the AndroidMainfest.xml Configure the name property of the application

public class ExampleApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
JPushInterface.setDebugMode(true);
JPushInterface.init(this);
}
}

Step 4 Create a broadcast receive message
Create Receiver Broadcast Receive Message (copy MyReceiver from Aurora Push demo)
Create some code in Receiver to change

else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Log.d(TAG, "[MyReceiver] User clicks to open notification");

String data = printBundle(bundle);
Intent i = new Intent();
if(data != null){
if(data.contains("adddepedency")){
i.setClass(context, ApplyMessageActivity.class);
}else if(data.contains("message")){
i.setClass(context, YYMMessageAtivity.class);
}
}else{
i.setClass(context, YYMMessageAtivity.class);
}
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
context.startActivity(i);

}
// Print all intent extra data
private static String printBundle(Bundle bundle) {
StringBuilder sb = new StringBuilder();
String yymType = "";
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 = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
yymType = json.toString();
Iterator<String> it = json.keys();

while (it.hasNext()) {
String myKey = it.next();
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));
}
}
Log.e("===sll=Jpush",sb.toString()) ;
return yymType;
}

Step 5 Configure Broadcasting
AndroidManifest.xml Configure custom broadcasts

<receiver
android:name=".receiver.MyReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTRATION" /> <!-- Required User registration SDK Of intent -->
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!-- Required User Receive SDK Message intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!-- Required User Receive SDK Notification bar information intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!-- Required User opens a custom notification bar intent -->
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" /> <!-- Optional User Acceptance Rich Push Javascript Callback function intent -->
<action android:name="cn.jpush.android.intent.CONNECTION" /> <!-- Receive Network Change Connections/To break off since 1.6.3 -->
<category android:name="com.telehot.yym" />
</intent-filter>
</receiver>

summary
1. Complete the above five steps to test, with special emphasis on the right to turn on mobile app notifications.
2. Backend needs to be aliased

//add alias
String code = aCache.getAsString("userCode");
JPushInterface.setAlias(this, 0, code);
//Exit Logon Delete Alias
JPushInterface.deleteAlias(this, 0);

Tags: Android SDK JSON Gradle

Posted on Thu, 28 May 2020 09:49:43 -0700 by zyrolasting