Przeglądaj źródła

添加极光推送支持

zengjiebin 8 lat temu
rodzic
commit
b609c52a93

+ 3 - 0
app/build.gradle

@@ -266,6 +266,9 @@ dependencies {
     annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.16'
     compile 'com.sunfusheng:marqueeview:1.3.3'
     compile 'com.github.nanchen2251:CompressHelper:1.0.5'
+    //极光
+    compile files('libs/jcore-android-1.2.0.jar')
+    compile files('libs/jpush-android-3.1.2.jar')
 
 }
 def releaseTime() {

BIN
app/libs/jcore-android-1.2.0.jar


BIN
app/libs/jpush-android-3.1.2.jar


+ 17 - 1
app/proguard-rules.pro

@@ -386,4 +386,20 @@
 -dontwarn android.support.design.**
 -keep class android.support.design.** { *; }
 -keep interface android.support.design.** { *; }
--keep public class android.support.design.R$* { *; }
+-keep public class android.support.design.R$* { *; }
+
+##极光推送
+-dontoptimize
+-dontpreverify
+
+-dontwarn cn.jpush.**
+-keep class cn.jpush.** { *; }
+-keep class * extends cn.jpush.android.helpers.JPushMessageReceiver { *; }
+
+-dontwarn cn.jiguang.**
+-keep class cn.jiguang.** { *; }
+#2.0.5 ~ 2.1.7 版本有引入 gson 和 protobuf ,增加排除混淆的配置。(2.1.8版本不需配置)
+#==================gson && protobuf==========================
+-dontwarn com.google.**
+-keep class com.google.gson.** {*;}
+-keep class com.google.protobuf.** {*;}

+ 144 - 1
app/src/main/AndroidManifest.xml

@@ -2,6 +2,36 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     package="com.sheep.jiuyan.samllsheep">
+    <!--极光推送-->
+    <!-- Required -->
+    <permission
+        android:name="${applicationId}.permission.JPUSH_MESSAGE"
+        android:protectionLevel="signature" />
+
+    <!-- Required  一些系统要求的权限,如访问网络等-->
+    <uses-permission android:name="${applicationId}.permission.JPUSH_MESSAGE" />
+    <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
+    <uses-permission android:name="android.permission.VIBRATE" />
+    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+
+    <!-- Optional for location -->
+    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- 用于开启 debug 版本的应用在6.0 系统上 层叠窗口权限 -->
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.GET_TASKS" />
+    <!--极光推送end-->
+
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.CAMERA" />
     <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
@@ -74,7 +104,7 @@
         <!-- 必须配置 fileProvider, 注意: android:authorities="${applicationId}.fileProvider" 不要直接copy,设置为你的包名.fileProvider-->
         <provider
             android:name="android.support.v4.content.FileProvider"
-            android:authorities="com.sheep.jiuyan.samllsheep.fileProvider"
+            android:authorities="${applicationId}.fileProvider"
             android:exported="false"
             android:grantUriPermissions="true">
             <meta-data
@@ -273,6 +303,119 @@
             android:value="5ab0a1da8f4a9d742900035f"/>
         <meta-data android:value="xxx" android:name="UMENG_CHANNEL"/>
 
+
+        <!--极光推送-->
+
+        <!-- Rich push 核心功能 since 2.0.6-->
+        <activity
+            android:name="cn.jpush.android.ui.PopWinActivity"
+            android:theme="@style/MyDialogStyle"
+            android:exported="false">
+        </activity>
+        <!-- Required SDK核心功能-->
+        <activity
+            android:name="cn.jpush.android.ui.PushActivity"
+            android:configChanges="orientation|keyboardHidden"
+            android:theme="@android:style/Theme.NoTitleBar"
+            android:exported="false">
+            <intent-filter>
+                <action android:name="cn.jpush.android.ui.PushActivity" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="${applicationId}" />
+            </intent-filter>
+        </activity>
+
+        <!-- Required SDK 核心功能-->
+        <!-- 可配置android:process参数将PushService放在其他进程中 -->
+        <service
+            android:name="cn.jpush.android.service.PushService"
+            android:process=":mult"
+            android:exported="false">
+            <intent-filter>
+                <action android:name="cn.jpush.android.intent.REGISTER" />
+                <action android:name="cn.jpush.android.intent.REPORT" />
+                <action android:name="cn.jpush.android.intent.PushService" />
+                <action android:name="cn.jpush.android.intent.PUSH_TIME" />
+            </intent-filter>
+        </service>
+        <!-- since 3.0.9 Required SDK 核心功能-->
+        <provider
+            android:authorities="${applicationId}.DataProvider"
+            android:name="cn.jpush.android.service.DataProvider"
+            android:exported="false"
+            />
+
+
+        <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
+        <!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
+        <service
+            android:name="cn.jpush.android.service.DaemonService"
+            android:enabled="true"
+            android:exported="true">
+            <intent-filter>
+                <action android:name="cn.jpush.android.intent.DaemonService" />
+                <category android:name="${applicationId}" />
+            </intent-filter>
+
+        </service>
+        <!-- since 3.1.0 Required SDK 核心功能-->
+        <provider
+            android:authorities="${applicationId}.DownloadProvider"
+            android:name="cn.jpush.android.service.DownloadProvider"
+            android:exported="true"
+            />
+        <!-- Required SDK核心功能-->
+        <receiver
+            android:name="cn.jpush.android.service.PushReceiver"
+            android:enabled="true"
+            android:exported="false">
+            <intent-filter android:priority="1000">
+                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />   <!--Required  显示通知栏 -->
+                <category android:name="${applicationId}" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.USER_PRESENT" />
+                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
+            </intent-filter>
+            <!-- Optional -->
+            <intent-filter>
+                <action android:name="android.intent.action.PACKAGE_ADDED" />
+                <action android:name="android.intent.action.PACKAGE_REMOVED" />
+
+                <data android:scheme="package" />
+            </intent-filter>
+        </receiver>
+
+        <!-- Required SDK核心功能-->
+        <receiver android:name="cn.jpush.android.service.AlarmReceiver" android:exported="false"/>
+
+        <!-- User defined.  For test only  用户自定义的广播接收器-->
+        <receiver
+            android:name="com.sheep.gamegroup.receiver.SheepJpushReceiver"
+            android:exported="false"
+            android:enabled="true">
+            <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="${applicationId}" />
+            </intent-filter>
+        </receiver>
+
+        <!-- User defined.  For test only  用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调-->
+        <receiver android:name="com.sheep.gamegroup.receiver.SheepJpushMessageReceiver">
+            <intent-filter>
+                <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
+                <category android:name="${applicationId}"/>
+            </intent-filter>
+        </receiver>
+
+        <!-- Required  . Enable it you can get statistics data with channel -->
+        <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
+        <meta-data android:name="JPUSH_APPKEY" android:value="28b74d520261c6f78e3e0921" /> <!--  </>值来自开发者平台取得的AppKey-->
+        <!--极光推送end-->
     </application>
 
 

+ 135 - 0
app/src/main/java/com/sheep/gamegroup/receiver/ExampleUtil.java

@@ -0,0 +1,135 @@
+package com.sheep.gamegroup.receiver;
+
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.os.Bundle;
+import android.os.Looper;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+import android.widget.Toast;
+
+import com.orhanobut.logger.Logger;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import cn.jpush.android.api.JPushInterface;
+
+public class ExampleUtil {
+    public static final String PREFS_NAME = "JPUSH_EXAMPLE";
+    public static final String PREFS_DAYS = "JPUSH_EXAMPLE_DAYS";
+    public static final String PREFS_START_TIME = "PREFS_START_TIME";
+    public static final String PREFS_END_TIME = "PREFS_END_TIME";
+    public static final String KEY_APP_KEY = "JPUSH_APPKEY";
+
+    public static boolean isEmpty(String s) {
+        if (null == s)
+            return true;
+        if (s.length() == 0)
+            return true;
+        if (s.trim().length() == 0)
+            return true;
+        return false;
+    }
+    /**
+     * 只能以 “+” 或者 数字开头;后面的内容只能包含 “-” 和 数字。
+     * */
+    private final static String MOBILE_NUMBER_CHARS = "^[+0-9][-0-9]{1,}$";
+    public static boolean isValidMobileNumber(String s) {
+        if(TextUtils.isEmpty(s)) return true;
+        Pattern p = Pattern.compile(MOBILE_NUMBER_CHARS);
+        Matcher m = p.matcher(s);
+        return m.matches();
+    }
+    // 校验Tag Alias 只能是数字,英文字母和中文
+    public static boolean isValidTagAndAlias(String s) {
+        Pattern p = Pattern.compile("^[\u4E00-\u9FA50-9a-zA-Z_!@#$&*+=.|]+$");
+        Matcher m = p.matcher(s);
+        return m.matches();
+    }
+
+    // 取得AppKey
+    public static String getAppKey(Context context) {
+        Bundle metaData = null;
+        String appKey = null;
+        try {
+            ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
+                    context.getPackageName(), PackageManager.GET_META_DATA);
+            if (null != ai)
+                metaData = ai.metaData;
+            if (null != metaData) {
+                appKey = metaData.getString(KEY_APP_KEY);
+                if ((null == appKey) || appKey.length() != 24) {
+                    appKey = null;
+                }
+            }
+        } catch (NameNotFoundException e) {
+
+        }
+        return appKey;
+    }
+    
+    // 取得版本号
+    public static String GetVersion(Context context) {
+		try {
+			PackageInfo manager = context.getPackageManager().getPackageInfo(
+					context.getPackageName(), 0);
+			return manager.versionName;
+		} catch (NameNotFoundException e) {
+			return "Unknown";
+		}
+	}
+
+    public static void showToast(final String toast, final Context context)
+    {
+    	new Thread(new Runnable() {
+			
+			@Override
+			public void run() {
+				Looper.prepare();
+				Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
+				Looper.loop();
+			}
+		}).start();
+    }
+    
+    public static boolean isConnected(Context context) {
+        ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+        NetworkInfo info = conn.getActiveNetworkInfo();
+        return (info != null && info.isConnected());
+    }
+    
+	public static String getImei(Context context, String imei) {
+        String ret = null;
+		try {
+			TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+            ret = telephonyManager.getDeviceId();
+		} catch (Exception e) {
+			Logger.e(ExampleUtil.class.getSimpleName(), e.getMessage());
+		}
+		if (isReadableASCII(ret)){
+            return ret;
+        } else {
+            return imei;
+        }
+	}
+
+    private static boolean isReadableASCII(CharSequence string){
+        if (TextUtils.isEmpty(string)) return false;
+        try {
+            Pattern p = Pattern.compile("[\\x20-\\x7E]+");
+            return p.matcher(string).matches();
+        } catch (Throwable e){
+            return true;
+        }
+    }
+
+    public static String getDeviceId(Context context) {
+        return JPushInterface.getUdid(context);
+    }
+}

+ 36 - 0
app/src/main/java/com/sheep/gamegroup/receiver/SheepJpushMessageReceiver.java

@@ -0,0 +1,36 @@
+package com.sheep.gamegroup.receiver;
+
+import android.content.Context;
+
+import cn.jpush.android.api.JPushMessage;
+import cn.jpush.android.service.JPushMessageReceiver;
+
+/**
+ * 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)
+ * Created by realicing on 2018/5/9.
+ * realicing@sina.com
+ */
+public class SheepJpushMessageReceiver extends JPushMessageReceiver {
+
+    @Override
+    public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
+        TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage);
+        super.onTagOperatorResult(context, jPushMessage);
+    }
+    @Override
+    public void onCheckTagOperatorResult(Context context,JPushMessage jPushMessage){
+        TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context,jPushMessage);
+        super.onCheckTagOperatorResult(context, jPushMessage);
+    }
+    @Override
+    public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
+        TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context,jPushMessage);
+        super.onAliasOperatorResult(context, jPushMessage);
+    }
+
+    @Override
+    public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
+        TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context,jPushMessage);
+        super.onMobileNumberOperatorResult(context, jPushMessage);
+    }
+}

+ 131 - 0
app/src/main/java/com/sheep/gamegroup/receiver/SheepJpushReceiver.java

@@ -0,0 +1,131 @@
+package com.sheep.gamegroup.receiver;
+
+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 org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.Iterator;
+
+import cn.jpush.android.api.JPushInterface;
+
+/**
+ * Created by realicing on 2018/5/9.
+ * realicing@sina.com
+ * 自定义接收器
+ *
+ * 如果不定义这个 Receiver,则:
+ * 1) 默认用户会打开主界面
+ * 2) 接收不到自定义消息
+ */
+public class SheepJpushReceiver extends BroadcastReceiver {
+    private static final String TAG = "JIGUANG-SmallSheep";
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        try {
+            Bundle bundle = intent.getExtras();
+            Log.d(TAG, "[SheepJpushReceiver] 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, "[SheepJpushReceiver] 接收Registration Id : " + regId);
+                //send the Registration Id to your server...
+
+            } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {//自定义消息中有自定义字段时才会接收到,且不会有通知
+                Log.d(TAG, "[SheepJpushReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
+                processCustomMessage(context, bundle);
+
+            } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {//除了自定义消息中有自定义字段的消息,都会接收到通知
+                Log.d(TAG, "[SheepJpushReceiver] 接收到推送下来的通知");
+                int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
+                Log.d(TAG, "[SheepJpushReceiver] 接收到推送下来的通知的ID: " + notifactionId);
+
+            } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
+                Log.d(TAG, "[SheepJpushReceiver] 用户点击打开了通知");
+
+//                //打开自定义的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, "[SheepJpushReceiver] 用户收到到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, "[SheepJpushReceiver]" + intent.getAction() +" connected state change to "+connected);
+            } else {
+                Log.d(TAG, "[SheepJpushReceiver] 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.getString(key));
+            }
+        }
+        return sb.toString();
+    }
+
+    //send msg to MainActivity
+    private void processCustomMessage(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);
+//        }
+    }
+}

+ 340 - 0
app/src/main/java/com/sheep/gamegroup/receiver/TagAliasOperatorHelper.java

@@ -0,0 +1,340 @@
+package com.sheep.gamegroup.receiver;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Message;
+import android.util.SparseArray;
+
+import com.orhanobut.logger.Logger;
+
+import java.util.Locale;
+import java.util.Set;
+
+import cn.jpush.android.api.JPushInterface;
+import cn.jpush.android.api.JPushMessage;
+
+/**
+ * 处理tagalias相关的逻辑
+ * */
+public class TagAliasOperatorHelper {
+    private static final String TAG = "JIGUANG-TagAliasHelper";
+    public static int sequence = 1;
+    /**增加*/
+    public static final int ACTION_ADD = 1;
+    /**覆盖*/
+    public static final int ACTION_SET = 2;
+    /**删除部分*/
+    public static final int ACTION_DELETE = 3;
+    /**删除所有*/
+    public static final int ACTION_CLEAN = 4;
+    /**查询*/
+    public static final int ACTION_GET = 5;
+
+    public static final int ACTION_CHECK = 6;
+
+    public static final int DELAY_SEND_ACTION = 1;
+
+    public static final int DELAY_SET_MOBILE_NUMBER_ACTION = 2;
+
+    private Context context;
+
+    private static TagAliasOperatorHelper mInstance;
+    private TagAliasOperatorHelper(){
+    }
+    public static TagAliasOperatorHelper getInstance(){
+        if(mInstance == null){
+            synchronized (TagAliasOperatorHelper.class){
+                if(mInstance == null){
+                    mInstance = new TagAliasOperatorHelper();
+                }
+            }
+        }
+        return mInstance;
+    }
+    public void init(Context context){
+        if(context != null) {
+            this.context = context.getApplicationContext();
+        }
+    }
+    private SparseArray<Object> setActionCache = new SparseArray<Object>();
+
+    public Object get(int sequence){
+        return setActionCache.get(sequence);
+    }
+    public Object remove(int sequence){
+        return setActionCache.get(sequence);
+    }
+    public void put(int sequence,Object tagAliasBean){
+        setActionCache.put(sequence,tagAliasBean);
+    }
+    private Handler delaySendHandler = new Handler(){
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what){
+                case DELAY_SEND_ACTION:
+                    if(msg.obj !=null && msg.obj instanceof  TagAliasBean){
+                        Logger.i(TAG,"on delay time");
+                        sequence++;
+                        TagAliasBean tagAliasBean = (TagAliasBean) msg.obj;
+                        setActionCache.put(sequence, tagAliasBean);
+                        if(context!=null) {
+                            handleAction(context, sequence, tagAliasBean);
+                        }else{
+                            Logger.e(TAG,"#unexcepted - context was null");
+                        }
+                    }else{
+                        Logger.w(TAG,"#unexcepted - msg obj was incorrect");
+                    }
+                    break;
+                case DELAY_SET_MOBILE_NUMBER_ACTION:
+                    if(msg.obj !=null && msg.obj instanceof  String) {
+                        Logger.i(TAG, "retry set mobile number");
+                        sequence++;
+                        String mobileNumber = (String) msg.obj;
+                        setActionCache.put(sequence, mobileNumber);
+                        if(context !=null) {
+                            handleAction(context, sequence, mobileNumber);
+                        }else {
+                            Logger.e(TAG, "#unexcepted - context was null");
+                        }
+                    }else{
+                        Logger.w(TAG,"#unexcepted - msg obj was incorrect");
+                    }
+                    break;
+            }
+        }
+    };
+    public void handleAction(Context context,int sequence,String mobileNumber){
+        put(sequence,mobileNumber);
+        Logger.d(TAG,"sequence:"+sequence+",mobileNumber:"+mobileNumber);
+        JPushInterface.setMobileNumber(context,sequence,mobileNumber);
+    }
+    /**
+     * 处理设置tag
+     * */
+    public void handleAction(Context context,int sequence, TagAliasBean tagAliasBean){
+        init(context);
+        if(tagAliasBean == null){
+            Logger.w(TAG,"tagAliasBean was null");
+            return;
+        }
+        put(sequence,tagAliasBean);
+        if(tagAliasBean.isAliasAction){
+            switch (tagAliasBean.action){
+                case ACTION_GET:
+                    JPushInterface.getAlias(context,sequence);
+                    break;
+                case ACTION_DELETE:
+                    JPushInterface.deleteAlias(context,sequence);
+                    break;
+                case ACTION_SET:
+                    JPushInterface.setAlias(context,sequence,tagAliasBean.alias);
+                    break;
+                default:
+                    Logger.w(TAG,"unsupport alias action type");
+                    return;
+            }
+        }else {
+            switch (tagAliasBean.action) {
+                case ACTION_ADD:
+                    JPushInterface.addTags(context, sequence, tagAliasBean.tags);
+                    break;
+                case ACTION_SET:
+                    JPushInterface.setTags(context, sequence, tagAliasBean.tags);
+                    break;
+                case ACTION_DELETE:
+                    JPushInterface.deleteTags(context, sequence, tagAliasBean.tags);
+                    break;
+                case ACTION_CHECK:
+                    //一次只能check一个tag
+                    String tag = (String)tagAliasBean.tags.toArray()[0];
+                    JPushInterface.checkTagBindState(context,sequence,tag);
+                    break;
+                case ACTION_GET:
+                    JPushInterface.getAllTags(context, sequence);
+                    break;
+                case ACTION_CLEAN:
+                    JPushInterface.cleanTags(context, sequence);
+                    break;
+                default:
+                    Logger.w(TAG,"unsupport tag action type");
+                    return;
+            }
+        }
+    }
+    private boolean RetryActionIfNeeded(int errorCode,TagAliasBean tagAliasBean){
+        if(!ExampleUtil.isConnected(context)){
+            Logger.w(TAG,"no network");
+            return false;
+        }
+        //返回的错误码为6002 超时,6014 服务器繁忙,都建议延迟重试
+        if(errorCode == 6002 || errorCode == 6014){
+            Logger.d(TAG,"need retry");
+            if(tagAliasBean!=null){
+                Message message = new Message();
+                message.what = DELAY_SEND_ACTION;
+                message.obj = tagAliasBean;
+                delaySendHandler.sendMessageDelayed(message,1000*60);
+                String logs =getRetryStr(tagAliasBean.isAliasAction, tagAliasBean.action,errorCode);
+                ExampleUtil.showToast(logs, context);
+                return true;
+            }
+        }
+        return false;
+    }
+    private boolean RetrySetMObileNumberActionIfNeeded(int errorCode,String mobileNumber){
+        if(!ExampleUtil.isConnected(context)){
+            Logger.w(TAG,"no network");
+            return false;
+        }
+        //返回的错误码为6002 超时,6024 服务器内部错误,建议稍后重试
+        if(errorCode == 6002 || errorCode == 6024){
+            Logger.d(TAG,"need retry");
+            Message message = new Message();
+            message.what = DELAY_SET_MOBILE_NUMBER_ACTION;
+            message.obj = mobileNumber;
+            delaySendHandler.sendMessageDelayed(message,1000*60);
+            String str = "Failed to set mobile number due to %s. Try again after 60s.";
+            str = String.format(Locale.ENGLISH,str,(errorCode == 6002 ? "timeout" : "server internal error”"));
+            ExampleUtil.showToast(str, context);
+            return true;
+        }
+        return false;
+
+    }
+    private String getRetryStr(boolean isAliasAction,int actionType,int errorCode){
+        String str = "Failed to %s %s due to %s. Try again after 60s.";
+        str = String.format(Locale.ENGLISH,str,getActionStr(actionType),(isAliasAction? "alias" : " tags") ,(errorCode == 6002 ? "timeout" : "server too busy"));
+        return str;
+    }
+
+    private String getActionStr(int actionType){
+        switch (actionType){
+            case ACTION_ADD:
+                return "add";
+            case ACTION_SET:
+                return "set";
+            case ACTION_DELETE:
+                return "delete";
+            case ACTION_GET:
+                return "get";
+            case ACTION_CLEAN:
+                return "clean";
+            case ACTION_CHECK:
+                return "check";
+        }
+        return "unkonw operation";
+    }
+    public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
+        int sequence = jPushMessage.getSequence();
+        Logger.i(TAG,"action - onTagOperatorResult, sequence:"+sequence+",tags:"+jPushMessage.getTags());
+        Logger.i(TAG,"tags size:"+jPushMessage.getTags().size());
+        init(context);
+        //根据sequence从之前操作缓存中获取缓存记录
+        TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
+        if(tagAliasBean == null){
+            ExampleUtil.showToast("获取缓存记录失败", context);
+            return;
+        }
+        if(jPushMessage.getErrorCode() == 0){
+            Logger.i(TAG,"action - modify tag Success,sequence:"+sequence);
+            setActionCache.remove(sequence);
+            String logs = getActionStr(tagAliasBean.action)+" tags success";
+            Logger.i(TAG,logs);
+            ExampleUtil.showToast(logs, context);
+        }else{
+            String logs = "Failed to " + getActionStr(tagAliasBean.action)+" tags";
+            if(jPushMessage.getErrorCode() == 6018){
+                //tag数量超过限制,需要先清除一部分再add
+                logs += ", tags is exceed limit need to clean";
+            }
+            logs += ", errorCode:" + jPushMessage.getErrorCode();
+            Logger.e(TAG, logs);
+            if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
+                ExampleUtil.showToast(logs, context);
+            }
+        }
+    }
+    public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage){
+        int sequence = jPushMessage.getSequence();
+        Logger.i(TAG,"action - onCheckTagOperatorResult, sequence:"+sequence+",checktag:"+jPushMessage.getCheckTag());
+        init(context);
+        //根据sequence从之前操作缓存中获取缓存记录
+        TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
+        if(tagAliasBean == null){
+            ExampleUtil.showToast("获取缓存记录失败", context);
+            return;
+        }
+        if(jPushMessage.getErrorCode() == 0){
+            Logger.i(TAG,"tagBean:"+tagAliasBean);
+            setActionCache.remove(sequence);
+            String logs = getActionStr(tagAliasBean.action)+" tag "+jPushMessage.getCheckTag() + " bind state success,state:"+jPushMessage.getTagCheckStateResult();
+            Logger.i(TAG,logs);
+            ExampleUtil.showToast(logs, context);
+        }else{
+            String logs = "Failed to " + getActionStr(tagAliasBean.action)+" tags, errorCode:" + jPushMessage.getErrorCode();
+            Logger.e(TAG, logs);
+            if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
+                ExampleUtil.showToast(logs, context);
+            }
+        }
+    }
+    public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
+        int sequence = jPushMessage.getSequence();
+        Logger.i(TAG,"action - onAliasOperatorResult, sequence:"+sequence+",alias:"+jPushMessage.getAlias());
+        init(context);
+        //根据sequence从之前操作缓存中获取缓存记录
+        TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
+        if(tagAliasBean == null){
+            ExampleUtil.showToast("获取缓存记录失败", context);
+            return;
+        }
+        if(jPushMessage.getErrorCode() == 0){
+            Logger.i(TAG,"action - modify alias Success,sequence:"+sequence);
+            setActionCache.remove(sequence);
+            String logs = getActionStr(tagAliasBean.action)+" alias success";
+            Logger.i(TAG,logs);
+            ExampleUtil.showToast(logs, context);
+        }else{
+            String logs = "Failed to " + getActionStr(tagAliasBean.action)+" alias, errorCode:" + jPushMessage.getErrorCode();
+            Logger.e(TAG, logs);
+            if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
+                ExampleUtil.showToast(logs, context);
+            }
+        }
+    }
+    //设置手机号码回调
+    public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
+        int sequence = jPushMessage.getSequence();
+        Logger.i(TAG,"action - onMobileNumberOperatorResult, sequence:"+sequence+",mobileNumber:"+jPushMessage.getMobileNumber());
+        init(context);
+        if(jPushMessage.getErrorCode() == 0){
+            Logger.i(TAG,"action - set mobile number Success,sequence:"+sequence);
+            setActionCache.remove(sequence);
+        }else{
+            String logs = "Failed to set mobile number, errorCode:" + jPushMessage.getErrorCode();
+            Logger.e(TAG, logs);
+            if(!RetrySetMObileNumberActionIfNeeded(jPushMessage.getErrorCode(),jPushMessage.getMobileNumber())){
+                ExampleUtil.showToast(logs, context);
+            }
+        }
+    }
+    public static class TagAliasBean{
+        int action;
+        Set<String> tags;
+        String alias;
+        boolean isAliasAction;
+
+        @Override
+        public String toString() {
+            return "TagAliasBean{" +
+                    "action=" + action +
+                    ", tags=" + tags +
+                    ", alias='" + alias + '\'' +
+                    ", isAliasAction=" + isAliasAction +
+                    '}';
+        }
+    }
+
+
+}

+ 6 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/BaseApplication.java

@@ -9,6 +9,8 @@ import com.umeng.socialize.UMShareAPI;
 import org.xutils.BuildConfig;
 import org.xutils.x;
 
+import cn.jpush.android.api.JPushInterface;
+
 /**
  * Created by Administrator on 2018/1/19.
  */
@@ -26,5 +28,9 @@ public abstract class BaseApplication extends KFZSApp {
         UMShareAPI.get(this);
         PlatformConfig.setWeixin("wx2be7f59bb7bb963f", "6cf7ca0f6c6ac97c6961d901fee8adb9");
         PlatformConfig.setQQZone("101461115", "b874bc950bcf066f17fd52cf2bb959e9");
+
+        //极光推送
+        JPushInterface.setDebugMode(BuildConfig.DEBUG);
+        JPushInterface.init(this);
     }
 }

BIN
app/src/main/jniLibs/arm64-v8a/libjcore120.so


BIN
app/src/main/jniLibs/armeabi-v7a/libjcore120.so


BIN
app/src/main/jniLibs/armeabi/libjcore120.so


BIN
app/src/main/jniLibs/mips/libjcore120.so


BIN
app/src/main/jniLibs/mips64/libjcore120.so


BIN
app/src/main/jniLibs/x86/libjcore120.so


BIN
app/src/main/jniLibs/x86_64/libjcore120.so


BIN
app/src/main/res/drawable-hdpi/jpush_ic_richpush_actionbar_back.png


BIN
app/src/main/res/drawable-hdpi/jpush_ic_richpush_actionbar_divider.png


+ 21 - 0
app/src/main/res/drawable-hdpi/jpush_richpush_btn_selector.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?> 
+<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
+    <!-- 获得焦点但未按下时的背景图片 --> 
+    <item 
+        android:state_focused="true" 
+        android:state_enabled="true" 
+        android:state_pressed="false" 
+        android:drawable="@drawable/jpush_ic_richpush_actionbar_back" />
+     <!-- 按下时的背景图片 --> 
+    <item 
+        android:state_enabled="true" 
+        android:state_pressed="true" 
+        android:drawable="@android:color/darker_gray" /> 
+    <!-- 按下时的背景图片 --> 
+    <item 
+        android:state_enabled="true" 
+        android:state_checked="true" 
+        android:drawable="@android:color/darker_gray" /> 
+    <!-- 默认时的背景图片 --> 
+    <item android:drawable="@drawable/jpush_ic_richpush_actionbar_back" />
+</selector> 

+ 20 - 0
app/src/main/res/drawable-hdpi/jpush_richpush_progressbar.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
+
+    <!-- 背景  gradient是渐变,corners定义的是圆角 -->
+    <item android:id="@android:id/background">
+        <shape>
+            <solid android:color="#ffffff" />
+        </shape>
+    </item>
+    
+    <!-- 进度条 -->
+    <item android:id="@android:id/progress">
+        <clip>
+            <shape>
+                <solid android:color="#4393ea" />
+            </shape>
+        </clip>
+    </item>
+
+</layer-list>

+ 15 - 0
app/src/main/res/layout/jpush_popwin_layout.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/popLayoutId"
+    style="@style/MyDialogStyle"
+    android:orientation="vertical"
+    android:layout_width="280dp"
+    android:layout_height="250dp" >
+
+        <WebView
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:id="@+id/wvPopwin"/>
+
+</LinearLayout>

+ 59 - 0
app/src/main/res/layout/jpush_webview_layout.xml

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<cn.jpush.android.ui.FullScreenView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/actionbarLayoutId"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical" >
+
+    <RelativeLayout
+        android:id="@+id/rlRichpushTitleBar"
+        android:layout_width="match_parent"
+        android:layout_height="40.0dp"
+        android:background="#29313a">
+
+        <ImageButton
+            android:id="@+id/imgRichpushBtnBack"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_marginLeft="9dp"
+            android:layout_marginRight="10dp"
+            android:background="@drawable/jpush_richpush_btn_selector" />
+
+        <ImageView
+            android:id="@+id/imgView"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_toRightOf="@id/imgRichpushBtnBack"
+            android:clickable="false"
+            android:src="@drawable/jpush_ic_richpush_actionbar_divider" />
+
+        <TextView
+            android:id="@+id/tvRichpushTitle"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_marginLeft="7dp"
+            android:layout_marginRight="5dp"
+            android:layout_toRightOf="@id/imgView"
+            android:clickable="false"
+            android:text=" "
+            android:textSize="20sp"
+            android:textColor="#ffffff" />
+    </RelativeLayout>
+
+    <ProgressBar
+        android:id="@+id/pushPrograssBar"
+        android:layout_width="match_parent"
+        android:layout_height="1dp"
+        android:progress="0"
+        android:progressDrawable="@drawable/jpush_richpush_progressbar"
+        style="?android:attr/progressBarStyleHorizontal" />
+    <WebView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:id="@+id/fullWebView"
+        android:background="#000000" />
+
+</cn.jpush.android.ui.FullScreenView>

+ 13 - 0
app/src/main/res/values/jpush_style.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+    <style name="MyDialogStyle">
+        <item name="android:windowBackground">@android:color/transparent</item>
+        <item name="android:windowFrame">@null</item>
+        <item name="android:windowNoTitle">true</item>
+        <item name="android:windowIsFloating">true</item>
+        <item name="android:windowIsTranslucent">true</item>
+        <item name="android:windowContentOverlay">@null</item>
+        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
+        <item name="android:backgroundDimEnabled">true</item>
+    </style>
+</resources>