commit cdd3d43ae33321528ffb6a88096061f31c50dc7f
Author: Administrator <981964879@qq.com>
Date: Wed Dec 25 11:28:10 2019 +0800
init
diff --git a/app/build.gradle b/app/build.gradle
new file mode 100644
index 0000000..362457a
--- /dev/null
+++ b/app/build.gradle
@@ -0,0 +1,133 @@
+apply plugin: 'com.android.application'
+
+def appName() {
+ return "SnInfo"
+}
+
+def releaseTime() {
+ return new Date().format("yyyyMMddHHmm", TimeZone.getDefault())
+}
+
+android {
+ compileSdkVersion 29
+ buildToolsVersion "29.0.2"
+ defaultConfig {
+ applicationId "com.info.sn"
+ minSdkVersion 23
+ targetSdkVersion 29
+ versionCode 5
+ versionName "1.0.4"
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ ndk {
+ //选择要添加的对应 cpu 类型的 .so 库。
+ abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
+ // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
+ }
+ manifestPlaceholders = [
+ JPUSH_PKGNAME: applicationId,
+ JPUSH_APPKEY : "edf9cec22731b8b2fed56ee6", //JPush 上注册的包名对应的 Appkey.
+ JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
+ ]
+ multiDexEnabled true
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+ lintOptions {
+ checkReleaseBuilds false
+ }
+ //签名
+ signingConfigs {
+ debug {
+ storeFile file("src/keys/xueshibaoos.jks")
+ storePassword "123456"
+ keyAlias "xueshibaoos"
+ keyPassword "123456"
+ v2SigningEnabled false
+ }
+ release {// 签名文件
+ storeFile file("src/keys/xueshibaoos.jks")
+ storePassword "123456"
+ keyAlias "xueshibaoos"
+ keyPassword "123456"
+ v2SigningEnabled false
+ }
+ }
+
+ buildTypes {
+ debug {
+ // 显示Log
+ buildConfigField "boolean", "LOG_DEBUG", "true"
+ versionNameSuffix "-debug"
+ minifyEnabled false
+ //Zipalign优化
+ zipAlignEnabled true
+ signingConfig signingConfigs.debug
+ applicationVariants.all { variant ->
+ variant.outputs.each { output ->
+ if (outputFile != null) {
+ def fileName = "${appName()}-V${defaultConfig.versionName}-${releaseTime()}.apk"
+ output.outputFileName = fileName
+ }
+ }
+ }
+ }
+ release {
+ // 不显示Log
+ buildConfigField "boolean", "LOG_DEBUG", "false"
+ //混淆
+ minifyEnabled false
+ //Zipalign优化
+ zipAlignEnabled true
+ //前一部分代表系统默认的android程序的混淆文件,该文件已经包含了基本的混淆声明,后一个文件是自己的定义混淆文件
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ //签名
+ signingConfig signingConfigs.release
+// 将release版本的包名重命名,加上版本及日期
+ applicationVariants.all { variant ->
+ variant.outputs.each { output ->
+ def outputFile = ""
+ if (outputFile != null) {
+ def fileName = "${appName()}-${defaultConfig.versionCode}-V${defaultConfig.versionName}-${releaseTime()}.apk"
+ output.outputFileName = new File(outputFile, fileName)
+
+ }
+ }
+ }
+ }
+ }
+ lintOptions {
+ checkReleaseBuilds false
+ // Or, if you prefer, you can continue to check for errors in release builds,
+ // but continue the build even when errors are found:
+ abortOnError false
+ }
+
+
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ implementation 'androidx.appcompat:appcompat:1.1.0'
+ implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+
+ implementation 'com.google.zxing:core:3.2.1'
+ implementation 'cn.jiguang.sdk:jpush:3.3.4' // 此处以JPush 3.3.4 版本为例。
+ implementation 'cn.jiguang.sdk:jcore:2.1.2' // 此处以JCore 2.1.2 版本为例。
+ //动态权限框架
+ implementation 'com.hjq:xxpermissions:6.0'
+ //http框架
+ implementation 'com.lzy.net:okgo:3.0.4'
+ implementation 'com.lzy.net:okrx:0.1.2'
+ implementation 'com.lzy.net:okserver:2.0.5'
+ implementation 'com.alibaba:fastjson:1.2.21'
+ implementation 'com.blankj:utilcode:1.26.0'
+ implementation 'com.arialyy.aria:core:3.7.10'
+ annotationProcessor 'com.arialyy.aria:compiler:3.7.10'
+}
diff --git a/app/src/keys/xueshibaoos.jks b/app/src/keys/xueshibaoos.jks
new file mode 100644
index 0000000..b94a626
Binary files /dev/null and b/app/src/keys/xueshibaoos.jks differ
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..6e08ead
--- /dev/null
+++ b/app/src/main/AndroidManifest.xml
@@ -0,0 +1,203 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/aidl/com/info/sn/KeepAliveConnection.aidl b/app/src/main/aidl/com/info/sn/KeepAliveConnection.aidl
new file mode 100644
index 0000000..3cada22
--- /dev/null
+++ b/app/src/main/aidl/com/info/sn/KeepAliveConnection.aidl
@@ -0,0 +1,13 @@
+// KeepAliveConnection.aidl
+package com.info.sn;
+
+// Declare any non-default types here with import statements
+
+interface KeepAliveConnection {
+ /**
+ * Demonstrates some basic types that you can use as parameters
+ * and return values in AIDL.
+ */
+// void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
+// double aDouble, String aString);
+}
diff --git a/app/src/main/java/com/info/sn/MainActivity.java b/app/src/main/java/com/info/sn/MainActivity.java
new file mode 100644
index 0000000..043d0aa
--- /dev/null
+++ b/app/src/main/java/com/info/sn/MainActivity.java
@@ -0,0 +1,379 @@
+package com.info.sn;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.graphics.Bitmap;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.Message;
+import android.text.TextUtils;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.hjq.permissions.OnPermission;
+import com.hjq.permissions.Permission;
+import com.hjq.permissions.XXPermissions;
+import com.info.sn.bean.UserInfo;
+import com.info.sn.jpush.ExampleUtil;
+import com.info.sn.jpush.LocalBroadcastManager;
+import com.info.sn.jpush.TagAliasOperatorHelper;
+import com.info.sn.network.api.HTTPInterface;
+import com.info.sn.service.MyDownloadService;
+import com.info.sn.utils.LogUtils;
+import com.info.sn.utils.SPUtils;
+import com.info.sn.utils.ToastUtil;
+import com.info.sn.utils.Utils;
+
+import java.io.File;
+import java.util.List;
+import java.util.Set;
+
+import cn.jpush.android.api.JPushInterface;
+
+import static com.info.sn.jpush.TagAliasOperatorHelper.ACTION_ADD;
+import static com.info.sn.jpush.TagAliasOperatorHelper.ACTION_CHECK;
+import static com.info.sn.jpush.TagAliasOperatorHelper.ACTION_CLEAN;
+import static com.info.sn.jpush.TagAliasOperatorHelper.ACTION_DELETE;
+import static com.info.sn.jpush.TagAliasOperatorHelper.ACTION_GET;
+import static com.info.sn.jpush.TagAliasOperatorHelper.ACTION_SET;
+import static com.info.sn.jpush.TagAliasOperatorHelper.TagAliasBean;
+import static com.info.sn.jpush.TagAliasOperatorHelper.sequence;
+
+public class MainActivity extends AppCompatActivity {
+ public static boolean isForeground = false;
+ private ImageView imageView;
+ private TextView tv_note, tv_devsn, tv_username, tv_school, tv_grade, tv_version;
+ private int DeviceInfo;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ }
+ PackageManager pm = getPackageManager();
+ //后台为0可能传过来null
+ pm.setApplicationEnabledSetting("com.info.sn", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
+ requestPermission();
+ registerMessageReceiver(); // used for receive msg
+ String rid = JPushInterface.getRegistrationID(getApplicationContext());
+ if (!rid.isEmpty()) {
+ ToastUtil.debugShow("RegId:" + rid);
+ LogUtils.e("RegId", rid);
+ onTagAliasAction(7);
+ } else {
+// ToastUtil.show("Get registration fail, JPush init failed!");
+// Toast.makeText(this, "Get registration fail, JPush init failed!", Toast.LENGTH_SHORT).show();
+ }
+ initView();
+ initData();
+ HTTPInterface.checkDevicesInfo(handler);
+ startService(new Intent(MainActivity.this, MyDownloadService.class));
+
+ }
+
+ private void initView() {
+ tv_note = (TextView) findViewById(R.id.tv_note);
+ imageView = (ImageView) findViewById(R.id.imageView);
+ tv_devsn = (TextView) findViewById(R.id.tv_devsn);
+ tv_devsn.setText("设备SN:" + Utils.getSerial());
+ tv_username = (TextView) findViewById(R.id.tv_username);
+ tv_school = (TextView) findViewById(R.id.tv_school);
+ tv_grade = (TextView) findViewById(R.id.tv_grade);
+ tv_version = findViewById(R.id.version);
+ tv_version.setText("版本:"+ BuildConfig.VERSION_NAME);
+ }
+
+ private void initData() {
+ DeviceInfo = (int) SPUtils.get(this, "isLogined", 2);
+ switch (DeviceInfo) {
+ case 0:
+ setImageAndText(imageView, "设备未绑定");
+ break;
+ case 1:
+ setImageAndText(imageView, "设备已绑定");
+ break;
+ case 2:
+ setImageAndText(imageView, "未经验证的设备,请联系客服");
+
+ break;
+ }
+ }
+
+ private void setImageAndText(ImageView imageView, String text) {
+ Bitmap bitmap = Utils.createQRImage(Utils.getSn(), 250, 250);
+ imageView.setImageBitmap(bitmap);
+ tv_note.setText(text);
+ }
+
+ private void setUserInfo(UserInfo userInfo) {
+ String name = userInfo.getSn_name();
+ String school = userInfo.getSn_school();
+ String grade = userInfo.getSn_grade();
+ if (name == null || name.equals("")) {
+ tv_username.setText("用户姓名:未设置");
+ } else {
+ tv_username.setText("用户姓名:" + name);
+ }
+ if (school == null || school.equals("")) {
+ tv_school.setText("学校:未设置");
+ } else {
+ tv_school.setText("学校:" + school);
+ }
+ if (grade == null || grade.equals("")) {
+ tv_grade.setText("年级:未设置");
+ } else {
+ tv_grade.setText("年级:" + getGrade(grade));
+ }
+
+ }
+
+ private String getGrade(String grade) {
+ String s;
+ switch (grade) {
+ case "1":
+ s = "一年级";
+ break;
+ case "2":
+ s = "二年级";
+ break;
+ case "3":
+ s = "三年级";
+ break;
+ case "4":
+ s = "四年级";
+ break;
+ case "5":
+ s = "五年级";
+ break;
+ case "6":
+ s = "六年级";
+ break;
+ case "7":
+ s = "初一";
+ break;
+ case "8":
+ s = "初二";
+ break;
+ case "9":
+ s = "初三";
+ break;
+ case "10":
+ s = "高一";
+ break;
+ case "11":
+ s = "高二";
+ break;
+ case "12":
+ s = "高三";
+ break;
+ default:
+ s = "一年级";
+ break;
+ }
+ return s;
+ }
+
+ Handler handler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ super.handleMessage(msg);
+ switch (msg.what) {
+ case 0:
+ SPUtils.put(MainActivity.this, "isLogined", 0);
+ setImageAndText(imageView, "设备未绑定");
+ break;
+ case 1:
+ UserInfo userInfo = (UserInfo) msg.obj;
+ SPUtils.put(MainActivity.this, "isLogined", 1);
+ SPUtils.put(MainActivity.this, "member_id", userInfo.getMember_id());
+ SPUtils.put(MainActivity.this, "sn_id", userInfo.getId());
+ setUserInfo((UserInfo) msg.obj);
+ setImageAndText(imageView, "设备已绑定");
+ break;
+ case 2:
+ SPUtils.put(MainActivity.this, "isLogined", 2);
+ setImageAndText(imageView, "未经验证的设备,请联系客服");
+ break;
+ }
+ }
+ };
+
+ private String[] permission = new String[]{
+// Permission.SYSTEM_ALERT_WINDOW,
+// Permission.CAMERA,
+// Permission.READ_SMS,
+// Permission.RECEIVE_SMS,
+// Permission.SEND_SMS,
+ Permission.REQUEST_INSTALL_PACKAGES,
+ Permission.READ_EXTERNAL_STORAGE,
+ Permission.WRITE_EXTERNAL_STORAGE,
+// Permission.READ_PHONE_STATE
+ };
+
+ public void requestPermission() {
+ XXPermissions.with(this)
+ // 可设置被拒绝后继续申请,直到用户授权或者永久拒绝
+ .constantRequest()
+ // 支持请求6.0悬浮窗权限8.0请求安装权限
+ //.permission(Permission.REQUEST_INSTALL_PACKAGES)
+ // 不指定权限则自动获取清单中的危险权限
+ .permission(permission)
+ .request(new OnPermission() {
+
+ @Override
+ public void hasPermission(List granted, boolean isAll) {
+ if (isAll) {
+ String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "POStemp";
+ File file = new File(path);
+ file.mkdirs();
+ } else {
+ ToastUtil.show("需要授予所有权限才能正常使用本程序!");
+ }
+ }
+
+ @Override
+ public void noPermission(List denied, boolean quick) {
+ if (quick) {
+ ToastUtil.show("被永久拒绝授权,请手动授予权限!");
+ //如果是被永久拒绝就跳转到应用权限系统设置页面
+ XXPermissions.gotoPermissionSettings(MainActivity.this);
+ } else {
+ ToastUtil.show("获取权限失败");
+ }
+ }
+ });
+ }
+
+
+ public void onTagAliasAction(int i) {
+ Set tags = null;
+ String alias = null;
+ int action = -1;
+ boolean isAliasAction = false;
+ switch (i) {
+ //设置手机号码:
+ case 0:
+// handleSetMobileNumber();
+ return;
+ //增加tag
+ case 1:
+// tags = getInPutTags();
+ if (tags == null) {
+ return;
+ }
+ action = ACTION_ADD;
+ break;
+ //设置tag
+ case 2:
+// tags = getInPutTags();
+ if (tags == null) {
+ return;
+ }
+ action = ACTION_SET;
+ break;
+ //删除tag
+ case 3:
+// tags = getInPutTags();
+ if (tags == null) {
+ return;
+ }
+ action = ACTION_DELETE;
+ break;
+ //获取所有tag
+ case 4:
+ action = ACTION_GET;
+ break;
+ //清除所有tag
+ case 5:
+ action = ACTION_CLEAN;
+ break;
+ case 6:
+// tags = getInPutTags();
+ if (tags == null) {
+ return;
+ }
+ action = ACTION_CHECK;
+ break;
+ //设置alias
+ case 7:
+// alias = getInPutAlias();
+ alias = Utils.getSerial();
+ if (TextUtils.isEmpty(alias)) {
+ return;
+ }
+ isAliasAction = true;
+ action = ACTION_SET;
+ break;
+ //获取alias
+ case 8:
+ isAliasAction = true;
+ action = ACTION_GET;
+ break;
+ //删除alias
+ case 9:
+ isAliasAction = true;
+ action = ACTION_DELETE;
+ break;
+ default:
+ return;
+ }
+ TagAliasBean tagAliasBean = new TagAliasBean();
+ tagAliasBean.action = action;
+ sequence++;
+ if (isAliasAction) {
+ tagAliasBean.alias = alias;
+ } else {
+ tagAliasBean.tags = tags;
+ }
+ tagAliasBean.isAliasAction = isAliasAction;
+ TagAliasOperatorHelper.getInstance().handleAction(getApplicationContext(), sequence, tagAliasBean);
+
+ }
+
+
+ //for receive customer msg from jpush server
+ private MessageReceiver mMessageReceiver;
+ public static final String MESSAGE_RECEIVED_ACTION = "com.example.jpushdemo.MESSAGE_RECEIVED_ACTION";
+ public static final String KEY_TITLE = "title";
+ public static final String KEY_MESSAGE = "message";
+ public static final String KEY_EXTRAS = "extras";
+
+ public void registerMessageReceiver() {
+ mMessageReceiver = new MessageReceiver();
+ IntentFilter filter = new IntentFilter();
+ filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
+ filter.addAction(MESSAGE_RECEIVED_ACTION);
+ LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter);
+ }
+
+ public class MessageReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ try {
+ if (MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) {
+ String messge = intent.getStringExtra(KEY_MESSAGE);
+ String extras = intent.getStringExtra(KEY_EXTRAS);
+ StringBuilder showMsg = new StringBuilder();
+ showMsg.append(KEY_MESSAGE + " : " + messge + "\n");
+ if (!ExampleUtil.isEmpty(extras)) {
+ showMsg.append(KEY_EXTRAS + " : " + extras + "\n");
+ }
+// setCostomMsg(showMsg.toString());
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
+
+}
diff --git a/app/src/main/java/com/info/sn/MyApplication.java b/app/src/main/java/com/info/sn/MyApplication.java
new file mode 100644
index 0000000..f653ffa
--- /dev/null
+++ b/app/src/main/java/com/info/sn/MyApplication.java
@@ -0,0 +1,447 @@
+package com.info.sn;
+
+import android.app.ActivityManager;
+import android.app.Application;
+import android.app.usage.UsageStats;
+import android.app.usage.UsageStatsManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.os.Environment;
+import android.provider.Settings;
+import android.util.Log;
+
+import com.arialyy.annotations.Download;
+import com.arialyy.aria.core.Aria;
+import com.arialyy.aria.core.task.DownloadTask;
+import com.blankj.utilcode.util.NetworkUtils;
+import com.info.sn.network.api.HTTPInterface;
+import com.info.sn.utils.ApkUtils;
+import com.info.sn.utils.LogUtils;
+import com.info.sn.utils.SPUtils;
+import com.info.sn.utils.ToastUtil;
+import com.lzy.okgo.OkGo;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.File;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import cn.jpush.android.api.CustomMessage;
+
+public class MyApplication extends Application implements NetworkUtils.OnNetworkStatusChangedListener {
+ public static Context context;
+ private static MyApplication app;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ app = this;
+ ToastUtil.init(this);
+ context = getApplicationContext();
+ ToastUtil.init(this);
+ OkGo.getInstance().init(this);
+ NetworkUtils.registerNetworkStatusChangedListener(this);
+ Aria.init(this);
+ Aria.download(this).register();
+ Aria.download(this).resumeAllTask();
+
+ }
+
+ @Override
+ public void onTerminate() {
+ super.onTerminate();
+ NetworkUtils.unregisterNetworkStatusChangedListener(this);
+
+ }
+
+ public static MyApplication getInstance() {
+ return app;
+ }
+
+ public static Context getAppContext() {
+ if (context == null) {
+ context = getAppContext();
+ }
+ return context;
+ }
+
+ public static String getTaskPackname() {
+ String currentApp = "CurrentNULL";
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
+ UsageStatsManager usm = (UsageStatsManager) context.getSystemService("usagestats");
+ long time = System.currentTimeMillis();
+ List appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000 * 1000, time);
+ if (appList != null && appList.size() > 0) {
+ SortedMap mySortedMap = new TreeMap();
+ for (UsageStats usageStats : appList) {
+ mySortedMap.put(usageStats.getLastTimeUsed(), usageStats);
+ }
+ if (mySortedMap != null && !mySortedMap.isEmpty()) {
+ currentApp = mySortedMap.get(mySortedMap.lastKey()).getPackageName();
+ }
+ }
+ } else {
+ ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ List tasks = am.getRunningAppProcesses();
+ currentApp = tasks.get(0).processName;
+ }
+// LogUtils.e("TAG", "Current App in foreground is: " + currentApp);
+ return currentApp;
+ }
+
+ /**
+ * 实时获取电量
+ */
+ public static int getSystemBattery() {
+ int level = 0;
+ Intent batteryInfoIntent = context.getApplicationContext().registerReceiver(null,
+ new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+ level = batteryInfoIntent.getIntExtra("level", 0);
+ int batterySum = batteryInfoIntent.getIntExtra("scale", 100);
+ int percentBattery = 100 * level / batterySum;
+ LogUtils.i("getSystemBattery", "level = " + level);
+ LogUtils.i("getSystemBattery", "batterySum = " + batterySum);
+ LogUtils.i("getSystemBattery", "percent is " + percentBattery + "%");
+ return percentBattery;
+ }
+
+
+ //定义接收极光推送消息的类型。
+ //1.获取设备在线信息
+ // 2.获取当前正在运行得应用和电量
+ // 3.数据线传输管控
+ // 4.TF卡管控
+ // 5.蓝牙管控
+ // 6.浏览器上网管控
+ // 7.应用联网管控
+ // 8.应用锁管控
+ // 9.强制安装应用
+ // 10.强制卸载应用
+ private static final String JIGUANG_GET_DRIVELINE = "1";
+ private static final String JIGUANG_GET_STARTTIME = "2";
+ private static final String JIGUANG_USB_STATE = "3";
+ private static final String JIGUANG_TFCARD_STATE = "4";
+ private static final String JIGUANG_BLUETOOTH_STATE = "5";
+ private static final String JIGUANG_BROWSER_URLPATH = "6";
+ private static final String JIGUANG_APP_NETWORKSTATE = "7";
+ private static final String JIGUANG_APP_LOCKEDSTATE = "8";
+ private static final String JIGUANG_FORCE_INSTALLAPK = "9";
+ private static final String JIGUANG_FORCE_UNINSTALLAPK = "10";
+
+
+
+ synchronized public void manageCustomMessage(CustomMessage customMessage) {
+ String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
+ String member_id = (String) SPUtils.get(context, "member_id", "-1");
+ if (customMessage == null) {
+ LogUtils.e("jiguang", "customMessage is NULL");
+ } else {
+ String MESSAGE = customMessage.message;
+ //MESSAGE用作判断
+ String TITLE = customMessage.title;
+ String CONTENT_TYPE = customMessage.contentType;
+ String EXTRA = customMessage.extra;
+ LogUtils.e("EXTRA", EXTRA);
+ switch (MESSAGE) {
+ case JIGUANG_GET_DRIVELINE:
+ HTTPInterface.getDriveState(member_id, sn_id);
+ break;
+ case JIGUANG_GET_STARTTIME:
+ sendStartTime(EXTRA);
+ break;
+ case JIGUANG_USB_STATE:
+ setUsbState(EXTRA);
+ break;
+ case JIGUANG_TFCARD_STATE:
+ setTfcardState(EXTRA);
+ break;
+ case JIGUANG_BLUETOOTH_STATE:
+ setBluetoothState(EXTRA);
+ break;
+ case JIGUANG_BROWSER_URLPATH:
+ setBrowserUrlpath(EXTRA);
+ break;
+ case JIGUANG_APP_NETWORKSTATE:
+ setAppNetworkstate(EXTRA);
+ break;
+ case JIGUANG_APP_LOCKEDSTATE:
+ setAppLockedstate(EXTRA);
+ break;
+ case JIGUANG_FORCE_INSTALLAPK:
+ intallApk(EXTRA);
+ break;
+ case JIGUANG_FORCE_UNINSTALLAPK:
+ unintallApk(EXTRA);
+ break;
+ }
+
+
+ }
+ }
+
+
+ synchronized private void defaults(String jsonArray) {
+ if (jsonArray.length() > 0) {
+ try {
+ JSONObject extra = new JSONObject(jsonArray);
+ String packageName = extra.getString("package");
+ int is_network = extra.getInt("is_network");
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("defaults", e.getMessage());
+ }
+ } else {
+ ToastUtil.debugShow("defaults jsonArray is NULL");
+ }
+ }
+
+ //USB数据功能管控
+ //仅充电:usb_charge
+ //MTP模式:usb_mtp
+ //Midi模式:usb_midi
+ synchronized public static void sendStartTime() {
+ int battery = getSystemBattery();
+ HTTPInterface.sendStartTime(getAppContext(), 0, getTaskPackname(), battery, "111");
+ }
+
+
+ synchronized private void sendStartTime(String jsonArray) {
+ if (jsonArray.length() > 0) {
+ try {
+ JSONObject extra = new JSONObject(jsonArray);
+ String random = extra.getString("random");
+ int battery = getSystemBattery();
+ HTTPInterface.sendStartTime(getAppContext(), 0, getTaskPackname(), battery, random);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ synchronized private void setUsbState(String jsonArray) {
+ if (jsonArray.length() > 0) {
+ try {
+ JSONObject extra = new JSONObject(jsonArray);
+ int is_dataline = extra.getInt("is_dataline");
+ if (is_dataline == 1) {
+ boolean qch_usb_choose = Settings.System.putString(getContentResolver(), "qch_usb_choose", "usb_charge");
+ LogUtils.e("setUsbState:", Settings.System.getString(getContentResolver(), "qch_usb_choose"));
+ } else {
+ boolean qch_usb_choose = Settings.System.putString(getContentResolver(), "qch_usb_choose", "usb_mtp");
+ LogUtils.e("setUsbState:", Settings.System.getString(getContentResolver(), "qch_usb_choose"));
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("setUsbState", e.getMessage());
+ }
+ } else {
+ ToastUtil.debugShow("setUsbState jsonArray is NULL");
+ }
+ }
+
+ synchronized private void setTfcardState(String jsonArray) {
+ if (jsonArray.length() > 0) {
+ try {
+ JSONObject extra = new JSONObject(jsonArray);
+ int is_tf = extra.getInt("is_tf");
+ boolean qch_sdcard_forbid_on = Settings.System.putInt(getContentResolver(), "qch_sdcard_forbid_on", is_tf);
+ if (qch_sdcard_forbid_on) {
+ LogUtils.e("setTfcardState:", Settings.System.getString(getContentResolver(), "qch_sdcard_forbid_on"));
+ } else {
+ ToastUtil.debugShow("setTfcardState failed,state:" + is_tf);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("setTfcardState", e.getMessage());
+ }
+ } else {
+ ToastUtil.debugShow("setTfcardState jsonArray is NULL");
+ }
+ }
+
+ synchronized private void setBluetoothState(String jsonArray) {
+ if (jsonArray.length() > 0) {
+ try {
+ JSONObject extra = new JSONObject(jsonArray);
+ int is_bluetooth = extra.getInt("is_bluetooth");
+ boolean qch_bt_forbid_on = Settings.System.putInt(getContentResolver(), "qch_bt_forbid_on", is_bluetooth);
+ if (qch_bt_forbid_on) {
+ LogUtils.e("setBluetoothState:", Settings.System.getString(getContentResolver(), "qch_bt_forbid_on"));
+ } else {
+ ToastUtil.debugShow("setBluetoothState failed,state:" + is_bluetooth);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("setBluetoothState", e.getMessage());
+ }
+ } else {
+ ToastUtil.debugShow("setBluetoothState jsonArray is NULL");
+ }
+ }
+
+ synchronized private void setBrowserUrlpath(String jsonArray) {
+ if (jsonArray.length() > 0) {
+ try {
+ JSONObject extra = new JSONObject(jsonArray);
+ String browser = extra.getString("browser");
+ boolean setBrowserUrlpath = Settings.System.putString(getContentResolver(), "DeselectBrowserArray", browser);
+ LogUtils.e("setBrowserUrlpath:", String.valueOf(setBrowserUrlpath));
+ if (setBrowserUrlpath) {
+ LogUtils.e("getBrowserUrlpath:", Settings.System.getString(getContentResolver(), "DeselectBrowserArray"));
+ } else {
+ ToastUtil.debugShow("setBrowserUrlpath failed,url:" + browser);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("setBrowserUrlpath", e.getMessage());
+ }
+ } else {
+ boolean setBrowserUrlpath = Settings.System.putString(getContentResolver(), "DeselectBrowserArray", "invalid");
+
+ ToastUtil.debugShow("setBrowserUrlpath jsonArray is NULL,set default: " + setBrowserUrlpath);
+ }
+ }
+
+ synchronized private void setAppNetworkstate(String jsonArray) {
+ if (jsonArray.length() > 0) {
+ try {
+ JSONObject extra = new JSONObject(jsonArray);
+ String package0 = extra.getString("package0");
+ String package1 = extra.getString("package1");
+ if (package0.length() != 0) {
+ boolean qch_jgy_network_disallow = Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", package0);
+ LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(getContentResolver(), "qch_jgy_network_allow"));
+ } else {
+ boolean qch_jgy_network_disallow = Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", "invalid");
+ LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(getContentResolver(), "qch_jgy_network_allow"));
+ }
+ if (package1.length() != 0) {
+ boolean qch_jgy_network_disallow = Settings.System.putString(getContentResolver(), "qch_jgy_network_disallow", package1);
+ LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(getContentResolver(), "qch_jgy_network_disallow"));
+ } else {
+ boolean qch_jgy_network_disallow = Settings.System.putString(getContentResolver(), "qch_jgy_network_disallow", "invalid");
+ LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(getContentResolver(), "qch_jgy_network_disallow"));
+ }
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("setAppNetworkstate", e.getMessage());
+ }
+ } else {
+ ToastUtil.debugShow("setAppNetworkstate jsonArray is NULL");
+ }
+ }
+
+ synchronized private void setAppLockedstate(String jsonArray) {
+ if (jsonArray.length() > 0) {
+ try {
+ JSONObject extra = new JSONObject(jsonArray);
+ String packageName = extra.getString("package");
+ int is_lock = extra.getInt("is_lock");
+ ToastUtil.debugShow("收到应用锁管控消息:包名" + packageName + "is_lock_state:" + is_lock);
+ PackageManager pm = getPackageManager();
+ //后台为0可能传过来null
+ if (is_lock == 1) {
+ pm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
+ } else {
+ pm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("setAppLockedstate", e.getMessage());
+ }
+ } else {
+ ToastUtil.debugShow("setAppLockedstate jsonArray is NULL");
+ }
+
+ }
+
+ //静默安装应用,使用okgo,断网会出现问题,等待修改使用aria
+ synchronized private void intallApk(String jsondata) {
+ try {
+ JSONObject extra = new JSONObject(jsondata);
+ final String packages = extra.getString("package");
+ ToastUtil.debugShow("收到应用安装消息:包名" + packages);
+ String url = extra.getString("url");
+ File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/apk");
+ file.mkdirs();
+ Aria.download(this).load(url).setFilePath(file.getAbsolutePath() + "/" + packages + ".apk").ignoreFilePathOccupy().setExtendField(packages).create();
+// OkGo.get(url)
+// .execute(new FileCallback() {
+// @Override
+// public void onSuccess(Response response) {
+//// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
+// ApkUtils.installApkInSilence(response.body().getAbsolutePath(), packages);
+// LogUtils.e("onSuccess", "download file successful,now installing");
+// }
+//
+// @Override
+// public void onError(Response response) {
+// super.onError(response);
+// LogUtils.e("manageCustomMessage", "File download Failure");
+// }
+//
+// @Override
+// public void downloadProgress(Progress progress) {
+// super.downloadProgress(progress);
+// LogUtils.e("downloadProgress", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
+// }
+// });
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("intallApk", e.getMessage());
+ }
+ }
+
+
+ synchronized private void unintallApk(String json) {
+ String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
+
+ try {
+ JSONObject object = new JSONObject(json);
+ String packageName = object.getString("package");
+ ToastUtil.debugShow("收到应用卸载消息:包名" + packageName);
+ if (!packageName.equals("") && !packageName.equals(getApplicationContext().getPackageName())) {
+ if (!ApkUtils.isAvailable(getApplicationContext(), packageName)) {
+ HTTPInterface.setAppuninstallInfo(sn_id, packageName);
+ } else {
+ ApkUtils.deleteApkInSilence(packageName);
+ }
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("unintallApk", e.getMessage());
+ }
+ }
+
+ @Override
+ public void onDisconnected() {
+ LogUtils.e("onDisconnected", "网络断开");
+ }
+
+ @Override
+ public void onConnected(NetworkUtils.NetworkType networkType) {
+ Aria.download(this).resumeAllTask();
+ LogUtils.e("onConnected", "网络连接");
+
+ }
+
+
+ //在这里处理任务执行中的状态,如进度进度条的刷新
+ @Download.onTaskRunning
+ protected void running(DownloadTask task) {
+ Log.e("aria running", task.getState() + "--" + task.getPercent() + "--" + task.getExtendField());
+ }
+
+ @Download.onTaskComplete
+ void taskComplete(DownloadTask task) {
+ //在这里处理任务完成的状态
+ ApkUtils.installApkInSilence(task.getFilePath(), task.getExtendField());
+ }
+}
diff --git a/app/src/main/java/com/info/sn/bean/MessageWhat.java b/app/src/main/java/com/info/sn/bean/MessageWhat.java
new file mode 100644
index 0000000..e789550
--- /dev/null
+++ b/app/src/main/java/com/info/sn/bean/MessageWhat.java
@@ -0,0 +1,6 @@
+package com.info.sn.bean;
+
+public class MessageWhat {
+ public static int CODE_SUCCESSFUL = 200;
+
+}
diff --git a/app/src/main/java/com/info/sn/bean/UserInfo.java b/app/src/main/java/com/info/sn/bean/UserInfo.java
new file mode 100644
index 0000000..c8313b6
--- /dev/null
+++ b/app/src/main/java/com/info/sn/bean/UserInfo.java
@@ -0,0 +1,124 @@
+package com.info.sn.bean;
+
+import java.io.Serializable;
+
+public class UserInfo implements Serializable {
+ private String id;
+
+ private String sn_value;
+ private String sn_name;
+ private String sn_phone;
+ private String sn_grade;
+ private String sn_app;
+ private String sn_area;
+ private String member_id;
+ private String is_delete;
+ private String is_reset;
+ private String is_lock;
+ private String sn_school;
+ private String createtime;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getSn_value() {
+ return sn_value;
+ }
+
+ public void setSn_value(String sn_value) {
+ this.sn_value = sn_value;
+ }
+
+ public String getSn_name() {
+ return sn_name;
+ }
+
+ public void setSn_name(String sn_name) {
+ this.sn_name = sn_name;
+ }
+
+ public String getSn_phone() {
+ return sn_phone;
+ }
+
+ public void setSn_phone(String sn_phone) {
+ this.sn_phone = sn_phone;
+ }
+
+ public String getSn_grade() {
+ return sn_grade;
+ }
+
+ public void setSn_grade(String sn_grade) {
+ this.sn_grade = sn_grade;
+ }
+
+ public String getSn_app() {
+ return sn_app;
+ }
+
+ public void setSn_app(String sn_app) {
+ this.sn_app = sn_app;
+ }
+
+ public String getSn_area() {
+ return sn_area;
+ }
+
+ public void setSn_area(String sn_area) {
+ this.sn_area = sn_area;
+ }
+
+ public String getMember_id() {
+ return member_id;
+ }
+
+ public void setMember_id(String member_id) {
+ this.member_id = member_id;
+ }
+
+ public String getIs_delete() {
+ return is_delete;
+ }
+
+ public void setIs_delete(String is_delete) {
+ this.is_delete = is_delete;
+ }
+
+ public String getIs_reset() {
+ return is_reset;
+ }
+
+ public void setIs_reset(String is_reset) {
+ this.is_reset = is_reset;
+ }
+
+ public String getIs_lock() {
+ return is_lock;
+ }
+
+ public void setIs_lock(String is_lock) {
+ this.is_lock = is_lock;
+ }
+
+ public String getCreatetime() {
+ return createtime;
+ }
+
+ public void setCreatetime(String createtime) {
+ this.createtime = createtime;
+ }
+
+ public String getSn_school() {
+ return sn_school;
+ }
+
+ public void setSn_school(String sn_school) {
+ this.sn_school = sn_school;
+ }
+}
diff --git a/app/src/main/java/com/info/sn/jpush/ExampleApplication.java b/app/src/main/java/com/info/sn/jpush/ExampleApplication.java
new file mode 100644
index 0000000..875e635
--- /dev/null
+++ b/app/src/main/java/com/info/sn/jpush/ExampleApplication.java
@@ -0,0 +1,22 @@
+package com.info.sn.jpush;
+
+import android.app.Application;
+import cn.jpush.android.api.JPushInterface;
+
+/**
+ * For developer startup JPush SDK
+ *
+ * 一般建议在自定义 Application 类里初始化。也可以在主 Activity 里。
+ */
+public class ExampleApplication extends Application {
+ private static final String TAG = "JIGUANG-Example";
+
+ @Override
+ public void onCreate() {
+ Logger.d(TAG, "[ExampleApplication] onCreate");
+ super.onCreate();
+
+ JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
+ JPushInterface.init(this); // 初始化 JPush
+ }
+}
diff --git a/app/src/main/java/com/info/sn/jpush/ExampleUtil.java b/app/src/main/java/com/info/sn/jpush/ExampleUtil.java
new file mode 100644
index 0000000..651c151
--- /dev/null
+++ b/app/src/main/java/com/info/sn/jpush/ExampleUtil.java
@@ -0,0 +1,133 @@
+package com.info.sn.jpush;
+
+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 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);
+ }
+}
diff --git a/app/src/main/java/com/info/sn/jpush/LocalBroadcastManager.java b/app/src/main/java/com/info/sn/jpush/LocalBroadcastManager.java
new file mode 100644
index 0000000..20c7942
--- /dev/null
+++ b/app/src/main/java/com/info/sn/jpush/LocalBroadcastManager.java
@@ -0,0 +1,263 @@
+package com.info.sn.jpush;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.Uri;
+import android.os.Handler;
+import android.os.Message;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Set;
+
+/**
+ * Created by efan on 2017/4/14.
+ */
+
+public final class LocalBroadcastManager {
+ private static final String TAG = "JIGUANG-Example";
+ private static final boolean DEBUG = false;
+ private final Context mAppContext;
+ private final HashMap> mReceivers = new HashMap>();
+ private final HashMap> mActions = new HashMap> ();
+ private final ArrayList mPendingBroadcasts = new ArrayList();
+ static final int MSG_EXEC_PENDING_BROADCASTS = 1;
+ private final Handler mHandler;
+ private static final Object mLock = new Object();
+ private static LocalBroadcastManager mInstance;
+
+ public static LocalBroadcastManager getInstance(Context context) {
+ Object var1 = mLock;
+ synchronized (mLock) {
+ if (mInstance == null) {
+ mInstance = new LocalBroadcastManager(context.getApplicationContext());
+ }
+
+ return mInstance;
+ }
+ }
+
+ private LocalBroadcastManager(Context context) {
+ this.mAppContext = context;
+ this.mHandler = new Handler(context.getMainLooper()) {
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case 1:
+ LocalBroadcastManager.this.executePendingBroadcasts();
+ break;
+ default:
+ super.handleMessage(msg);
+ }
+
+ }
+ };
+ }
+
+ public void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
+ HashMap var3 = this.mReceivers;
+ synchronized (this.mReceivers) {
+ ReceiverRecord entry = new ReceiverRecord(filter, receiver);
+ ArrayList filters = (ArrayList) this.mReceivers.get(receiver);
+ if (filters == null) {
+ filters = new ArrayList(1);
+ this.mReceivers.put(receiver, filters);
+ }
+
+ filters.add(filter);
+
+ for (int i = 0; i < filter.countActions(); ++i) {
+ String action = filter.getAction(i);
+ ArrayList entries = (ArrayList) this.mActions.get(action);
+ if (entries == null) {
+ entries = new ArrayList(1);
+ this.mActions.put(action, entries);
+ }
+
+ entries.add(entry);
+ }
+
+ }
+ }
+
+ public void unregisterReceiver(BroadcastReceiver receiver) {
+ HashMap var2 = this.mReceivers;
+ synchronized (this.mReceivers) {
+ ArrayList filters = (ArrayList) this.mReceivers.remove(receiver);
+ if (filters != null) {
+ for (int i = 0; i < filters.size(); ++i) {
+ IntentFilter filter = (IntentFilter) filters.get(i);
+
+ for (int j = 0; j < filter.countActions(); ++j) {
+ String action = filter.getAction(j);
+ ArrayList receivers = (ArrayList) this.mActions.get(action);
+ if (receivers != null) {
+ for (int k = 0; k < receivers.size(); ++k) {
+ if (((ReceiverRecord) receivers.get(k)).receiver == receiver) {
+ receivers.remove(k);
+ --k;
+ }
+ }
+
+ if (receivers.size() <= 0) {
+ this.mActions.remove(action);
+ }
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ public boolean sendBroadcast(Intent intent) {
+ HashMap var2 = this.mReceivers;
+ synchronized (this.mReceivers) {
+ String action = intent.getAction();
+ String type = intent.resolveTypeIfNeeded(this.mAppContext.getContentResolver());
+ Uri data = intent.getData();
+ String scheme = intent.getScheme();
+ Set categories = intent.getCategories();
+ boolean debug = (intent.getFlags() & 8) != 0;
+ if (debug) {
+ Logger.v("LocalBroadcastManager", "Resolving type " + type + " scheme " + scheme + " of intent " + intent);
+ }
+
+ ArrayList entries = (ArrayList) this.mActions.get(intent.getAction());
+ if (entries != null) {
+ if (debug) {
+ Logger.v("LocalBroadcastManager", "Action list: " + entries);
+ }
+
+ ArrayList receivers = null;
+
+ int i;
+ for (i = 0; i < entries.size(); ++i) {
+ ReceiverRecord receiver = (ReceiverRecord) entries.get(i);
+ if (debug) {
+ Logger.v("LocalBroadcastManager", "Matching against filter " + receiver.filter);
+ }
+
+ if (receiver.broadcasting) {
+ if (debug) {
+ Logger.v("LocalBroadcastManager", " Filter\'s target already added");
+ }
+ } else {
+ int match = receiver.filter.match(action, type, scheme, data, categories, "LocalBroadcastManager");
+ if (match >= 0) {
+ if (debug) {
+ Logger.v("LocalBroadcastManager", " Filter matched! match=0x" + Integer.toHexString(match));
+ }
+
+ if (receivers == null) {
+ receivers = new ArrayList();
+ }
+
+ receivers.add(receiver);
+ receiver.broadcasting = true;
+ } else if (debug) {
+ String reason;
+ switch (match) {
+ case -4:
+ reason = "category";
+ break;
+ case -3:
+ reason = "action";
+ break;
+ case -2:
+ reason = "data";
+ break;
+ case -1:
+ reason = "type";
+ break;
+ default:
+ reason = "unknown reason";
+ }
+
+ Logger.v("LocalBroadcastManager", " Filter did not match: " + reason);
+ }
+ }
+ }
+
+ if (receivers != null) {
+ for (i = 0; i < receivers.size(); ++i) {
+ ((ReceiverRecord) receivers.get(i)).broadcasting = false;
+ }
+
+ this.mPendingBroadcasts.add(new BroadcastRecord(intent, receivers));
+ if (!this.mHandler.hasMessages(1)) {
+ this.mHandler.sendEmptyMessage(1);
+ }
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ public void sendBroadcastSync(Intent intent) {
+ if (this.sendBroadcast(intent)) {
+ this.executePendingBroadcasts();
+ }
+
+ }
+
+ private void executePendingBroadcasts() {
+ while (true) {
+ BroadcastRecord[] brs = null;
+ HashMap i = this.mReceivers;
+ synchronized (this.mReceivers) {
+ int br = this.mPendingBroadcasts.size();
+ if (br <= 0) {
+ return;
+ }
+
+ brs = new BroadcastRecord[br];
+ this.mPendingBroadcasts.toArray(brs);
+ this.mPendingBroadcasts.clear();
+ }
+
+ for (int var6 = 0; var6 < brs.length; ++var6) {
+ BroadcastRecord var7 = brs[var6];
+
+ for (int j = 0; j < var7.receivers.size(); ++j) {
+ ((ReceiverRecord) var7.receivers.get(j)).receiver.onReceive(this.mAppContext, var7.intent);
+ }
+ }
+ }
+ }
+
+ private static class BroadcastRecord {
+ final Intent intent;
+ final ArrayList receivers;
+
+ BroadcastRecord(Intent _intent, ArrayList _receivers) {
+ this.intent = _intent;
+ this.receivers = _receivers;
+ }
+ }
+
+ private static class ReceiverRecord {
+ final IntentFilter filter;
+ final BroadcastReceiver receiver;
+ boolean broadcasting;
+
+ ReceiverRecord(IntentFilter _filter, BroadcastReceiver _receiver) {
+ this.filter = _filter;
+ this.receiver = _receiver;
+ }
+
+ public String toString() {
+ StringBuilder builder = new StringBuilder(128);
+ builder.append("Receiver{");
+ builder.append(this.receiver);
+ builder.append(" filter=");
+ builder.append(this.filter);
+ builder.append("}");
+ return builder.toString();
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/info/sn/jpush/Logger.java b/app/src/main/java/com/info/sn/jpush/Logger.java
new file mode 100644
index 0000000..e747ddc
--- /dev/null
+++ b/app/src/main/java/com/info/sn/jpush/Logger.java
@@ -0,0 +1,40 @@
+package com.info.sn.jpush;
+
+import android.util.Log;
+
+/**
+ * Created by efan on 2017/4/13.
+ */
+
+public class Logger {
+
+ //设为false关闭日志
+ private static final boolean LOG_ENABLE = true;
+
+ public static void i(String tag, String msg){
+ if (LOG_ENABLE){
+ Log.i(tag, msg);
+ }
+ }
+ public static void v(String tag, String msg){
+ if (LOG_ENABLE){
+ Log.v(tag, msg);
+ }
+ }
+ public static void d(String tag, String msg){
+ if (LOG_ENABLE){
+ Log.d(tag, msg);
+ }
+ }
+ public static void w(String tag, String msg){
+ if (LOG_ENABLE){
+ Log.w(tag, msg);
+ }
+ }
+ public static void e(String tag, String msg){
+ if (LOG_ENABLE){
+ Log.e(tag, msg);
+ }
+ }
+
+}
diff --git a/app/src/main/java/com/info/sn/jpush/MyJPushMessageReceiver.java b/app/src/main/java/com/info/sn/jpush/MyJPushMessageReceiver.java
new file mode 100644
index 0000000..fcd1ff0
--- /dev/null
+++ b/app/src/main/java/com/info/sn/jpush/MyJPushMessageReceiver.java
@@ -0,0 +1,47 @@
+package com.info.sn.jpush;
+
+import android.content.Context;
+
+import com.info.sn.MyApplication;
+
+import cn.jpush.android.api.CustomMessage;
+import cn.jpush.android.api.JPushMessage;
+import cn.jpush.android.service.JPushMessageReceiver;
+
+/**
+ * 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)
+ */
+public class MyJPushMessageReceiver 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);
+ }
+
+ @Override
+ public void onMessage(Context context, CustomMessage customMessage) {
+ super.onMessage(context, customMessage);
+ MyApplication.getInstance().manageCustomMessage(customMessage);
+ }
+
+
+}
diff --git a/app/src/main/java/com/info/sn/jpush/MyReceiver.java b/app/src/main/java/com/info/sn/jpush/MyReceiver.java
new file mode 100644
index 0000000..4103437
--- /dev/null
+++ b/app/src/main/java/com/info/sn/jpush/MyReceiver.java
@@ -0,0 +1,129 @@
+package com.info.sn.jpush;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextUtils;
+
+import com.info.sn.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();
+ Logger.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);
+ Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
+ //send the Registration Id to your server...
+
+ } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
+ Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
+ processCustomMessage(context, bundle);
+
+ } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
+ Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知");
+ int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
+ Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
+
+ } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
+ Logger.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())) {
+ Logger.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);
+ Logger.w(TAG, "[MyReceiver]" + intent.getAction() +" connected state change to "+connected);
+ } else {
+ Logger.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))) {
+ Logger.i(TAG, "This message has no Extra data");
+ continue;
+ }
+
+ try {
+ JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
+ Iterator it = json.keys();
+
+ while (it.hasNext()) {
+ String myKey = it.next();
+ sb.append("\nkey:" + key + ", value: [" +
+ myKey + " - " +json.optString(myKey) + "]");
+ }
+ } catch (JSONException e) {
+ Logger.e(TAG, "Get message extra JSON error!");
+ }
+
+ } else {
+ sb.append("\nkey:" + key + ", value:" + bundle.get(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);
+ }
+ }
+}
diff --git a/app/src/main/java/com/info/sn/jpush/PushService.java b/app/src/main/java/com/info/sn/jpush/PushService.java
new file mode 100644
index 0000000..b3d0d29
--- /dev/null
+++ b/app/src/main/java/com/info/sn/jpush/PushService.java
@@ -0,0 +1,7 @@
+package com.info.sn.jpush;
+
+import cn.jpush.android.service.JCommonService;
+
+public class PushService extends JCommonService {
+
+}
diff --git a/app/src/main/java/com/info/sn/jpush/TagAliasOperatorHelper.java b/app/src/main/java/com/info/sn/jpush/TagAliasOperatorHelper.java
new file mode 100644
index 0000000..20051e2
--- /dev/null
+++ b/app/src/main/java/com/info/sn/jpush/TagAliasOperatorHelper.java
@@ -0,0 +1,338 @@
+package com.info.sn.jpush;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Message;
+import android.util.SparseArray;
+
+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