Commit 2bb34864 authored by linfeng's avatar linfeng

推送

parent 4f93c399
...@@ -13,7 +13,7 @@ android { ...@@ -13,7 +13,7 @@ android {
multiDexEnabled true multiDexEnabled true
ndk { ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips" abiFilters "armeabi", "armeabi-v7a", "x86", "mips", 'arm64-v8a'
} }
//新版Gradle 是 implementation 为了兼容compile,写上这句话 //新版Gradle 是 implementation 为了兼容compile,写上这句话
javaCompileOptions { javaCompileOptions {
...@@ -22,6 +22,13 @@ android { ...@@ -22,6 +22,13 @@ android {
} }
} }
manifestPlaceholders = [
JPUSH_PKGNAME : appId,
JPUSH_APPKEY : "530b223034b92715e0295047", //JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
// javaCompileOptions { // javaCompileOptions {
// //
// annotationProcessorOptions { // annotationProcessorOptions {
...@@ -111,6 +118,8 @@ dependencies { ...@@ -111,6 +118,8 @@ dependencies {
debugApi 'com.squareup.leakcanary:leakcanary-android:1.6.1' debugApi 'com.squareup.leakcanary:leakcanary-android:1.6.1'
releaseApi 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1' releaseApi 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
api 'cn.jiguang.sdk:jpush:3.3.4' // 此处以JPush 3.3.4 版本为例。
api 'cn.jiguang.sdk:jcore:2.1.2' // 此处以JCore 2.1.2 版本为例。
// api project(path: ':RvTravel') // api project(path: ':RvTravel')
api project(':component_resource') api project(':component_resource')
......
...@@ -129,7 +129,8 @@ ...@@ -129,7 +129,8 @@
android:enabled="true" android:enabled="true"
android:process=":remote" /> android:process=":remote" />
<service android:name="com.tencent.smtt.export.external.DexClassLoaderProviderService" <service
android:name="com.tencent.smtt.export.external.DexClassLoaderProviderService"
android:label="dexopt" android:label="dexopt"
android:process=":dexopt" /> android:process=":dexopt" />
...@@ -188,8 +189,8 @@ ...@@ -188,8 +189,8 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:screenOrientation="portrait" android:launchMode="singleTask"
android:launchMode="singleTask" /> android:screenOrientation="portrait" />
<activity <activity
android:name="com.rv.home.rv.module.ui.login.LoginRvActivity" android:name="com.rv.home.rv.module.ui.login.LoginRvActivity"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
...@@ -387,6 +388,43 @@ ...@@ -387,6 +388,43 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".GuideActivity"></activity> <activity android:name=".GuideActivity"></activity>
<!--======================================== 极光 ==============================================================-->
<!-- Since JCore2.0.0 Required SDK核心功能-->
<!-- 这个Service要继承JCommonService -->
<service
android:name=".other.PushService"
android:process=":pushcore">
<intent-filter>
<action android:name="cn.jiguang.user.service.action" />
</intent-filter>
</service>
<!-- User defined. For test only 用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调-->
<receiver android:name=".other.MyJPushMessageReceiver">
<intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
<category android:name="com.xxfc.rv"></category>
</intent-filter>
</receiver>
<!-- User defined. For test only 用户自定义的广播接收器-->
<receiver
android:name=".other.MyReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTRATION" /> <!--Required 用户注册SDK的intent-->
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!--Required 用户接收SDK消息的intent-->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!--Required 用户接收SDK通知栏信息的intent-->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!--Required 用户打开自定义通知栏的intent-->
<action android:name="cn.jpush.android.intent.CONNECTION" /><!-- 接收网络变化 连接/断开 since 1.6.3 -->
<category android:name="com.xxfc.rv" />
</intent-filter>
</receiver>
<!--===========================================================================================================-->
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -34,6 +34,7 @@ import com.yuyife.okgo.OkGoUtil; ...@@ -34,6 +34,7 @@ import com.yuyife.okgo.OkGoUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import cn.jpush.android.api.JPushInterface;
import cn.pedant.SweetAlert.SweetAlertDialog; import cn.pedant.SweetAlert.SweetAlertDialog;
import me.jessyan.autosize.AutoSize; import me.jessyan.autosize.AutoSize;
import me.jessyan.autosize.AutoSizeConfig; import me.jessyan.autosize.AutoSizeConfig;
...@@ -107,6 +108,10 @@ public class RvClientApplication extends FrameApp { ...@@ -107,6 +108,10 @@ public class RvClientApplication extends FrameApp {
} }
ARouter.init(RvClientApplication.this); ARouter.init(RvClientApplication.this);
JPushInterface.setDebugMode(true);
JPushInterface.init(this);
/**********************内存检测****************************/ /**********************内存检测****************************/
/* if (LeakCanary.isInAnalyzerProcess(this)) { /* if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis. // This process is dedicated to LeakCanary for heap analysis.
......
package com.xxfc.rv.other;
import android.content.Context;
import android.util.Log;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver;
/**
* 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)
* */
public class MyJPushMessageReceiver extends JPushMessageReceiver {
private static final String TAG = "JIGUANG";
/**
* TODO 连接极光服务器
*/
@Override
public void onConnected(Context context, boolean b) {
super.onConnected(context, b);
Log.e(TAG, "onConnected");
}
/**
* TODO 注册极光时的回调
*/
@Override
public void onRegister(Context context, String s) {
super.onRegister(context, s);
Log.e(TAG, "onRegister" + s);
}
/**
* TODO 注册以及解除注册别名时回调
*/
@Override
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
super.onAliasOperatorResult(context, jPushMessage);
Log.e(TAG, jPushMessage.toString());
}
/**
* TODO 接收到推送下来的通知
* 可以利用附加字段(notificationMessage.notificationExtras)来区别Notication,指定不同的动作,附加字段是个json字符串
* 通知(Notification),指在手机的通知栏(状态栏)上会显示的一条通知信息
*/
@Override
public void onNotifyMessageArrived(Context context, NotificationMessage notificationMessage) {
super.onNotifyMessageArrived(context, notificationMessage);
Log.e(TAG, notificationMessage.toString());
}
/**
* TODO 打开了通知
* notificationMessage.notificationExtras(附加字段)的内容处理代码
* 比如打开新的Activity, 打开一个网页等..
*/
@Override
public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
super.onNotifyMessageOpened(context, notificationMessage);
Log.e(TAG, notificationMessage.notificationExtras);
}
/**
* TODO 接收到推送下来的自定义消息
* 自定义消息不是通知,默认不会被SDK展示到通知栏上,极光推送仅负责透传给SDK。其内容和展示形式完全由开发者自己定义。
* 自定义消息主要用于应用的内部业务逻辑和特殊展示需求
*/
@Override
public void onMessage(Context context, CustomMessage customMessage) {
super.onMessage(context, customMessage);
Log.e(TAG, "onMessage");
}
}
package com.xxfc.rv.other;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import com.xxfc.rv.MainActivity;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Iterator;
import cn.jpush.android.api.JPushInterface;
/**
* 自定义接收器
*
* 如果不定义这个 Receiver,则:
* 1) 默认用户会打开主界面
* 2) 接收不到自定义消息
*/
public class MyReceiver extends BroadcastReceiver {
private static final String TAG = "JIGUANG-Example";
@Override
public void onReceive(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));
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Log.d(TAG, "[MyReceiver] 接收到推送下来的通知");
int notifactionId = 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] 用户点击打开了通知");
// //打开自定义的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));
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等..
} else if(JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
boolean connected = 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 数据
private static String printBundle(Bundle bundle) {
StringBuilder sb = new StringBuilder();
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));
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.get(key));
}
}
return sb.toString();
}
}
package com.xxfc.rv.other;
import cn.jpush.android.service.JCommonService;
public class PushService extends JCommonService {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment