();
+ if (Build.VERSION.SDK_INT >= 23
+ && getApplicationInfo().targetSdkVersion >= 23){
+ try {
+ for (String perm : permissions) {
+ Method checkSelfMethod = getClass().getMethod("checkSelfPermission", String.class);
+ Method shouldShowRequestPermissionRationaleMethod = getClass().getMethod("shouldShowRequestPermissionRationale",
+ String.class);
+ if ((Integer)checkSelfMethod.invoke(this, perm) != PackageManager.PERMISSION_GRANTED
+ || (Boolean)shouldShowRequestPermissionRationaleMethod.invoke(this, perm)) {
+ if(!needCheckBackLocation
+ && BACKGROUND_LOCATION_PERMISSION.equals(perm)) {
+ continue;
+ }
+ needRequestPermissonList.add(perm);
+ }
+ }
+ } catch (Throwable e) {
+
+ }
+ }
+ return needRequestPermissonList;
+ }
+
+ /**
+ * 检测是否所有的权限都已经授权
+ * @param grantResults
+ * @return
+ * @since 2.5.0
+ *
+ */
+ private boolean verifyPermissions(int[] grantResults) {
+ for (int result : grantResults) {
+ if (result != PackageManager.PERMISSION_GRANTED) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ @TargetApi(23)
+ public void onRequestPermissionsResult(int requestCode,
+ String[] permissions, int[] paramArrayOfInt) {
+ if (requestCode == PERMISSON_REQUESTCODE) {
+ if (!verifyPermissions(paramArrayOfInt)) {
+ showMissingPermissionDialog();
+ isNeedCheck = false;
+ }
+ }
+ }
+
+ /**
+ * 显示提示信息
+ *
+ * @since 2.5.0
+ *
+ */
+ private void showMissingPermissionDialog() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.notifyTitle);
+ builder.setMessage(R.string.notifyMsg);
+
+ // 拒绝, 退出应用
+ builder.setNegativeButton(R.string.cancel,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ finish();
+ }
+ });
+
+ builder.setPositiveButton(R.string.setting,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ startAppSettings();
+ }
+ });
+
+ builder.setCancelable(false);
+
+ builder.show();
+ }
+
+ /**
+ * 启动应用的设置
+ *
+ * @since 2.5.0
+ *
+ */
+ private void startAppSettings() {
+ Intent intent = new Intent(
+ Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
+ intent.setData(Uri.parse("package:" + getPackageName()));
+ startActivity(intent);
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if(keyCode == KeyEvent.KEYCODE_BACK){
+ this.finish();
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
+}
diff --git a/app/src/main/java/com/info/sn/jpush/MyJPushMessageReceiver.java b/app/src/main/java/com/info/sn/jpush/MyJPushMessageReceiver.java
index fcd1ff0..73fb926 100644
--- a/app/src/main/java/com/info/sn/jpush/MyJPushMessageReceiver.java
+++ b/app/src/main/java/com/info/sn/jpush/MyJPushMessageReceiver.java
@@ -29,6 +29,7 @@ public class MyJPushMessageReceiver extends JPushMessageReceiver {
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context, jPushMessage);
super.onAliasOperatorResult(context, jPushMessage);
+ MyApplication.getInstance().onAliasOperatorResult(jPushMessage);
}
@Override
@@ -40,7 +41,7 @@ public class MyJPushMessageReceiver extends JPushMessageReceiver {
@Override
public void onMessage(Context context, CustomMessage customMessage) {
super.onMessage(context, customMessage);
- MyApplication.getInstance().manageCustomMessage(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
index 4103437..a496c2a 100644
--- a/app/src/main/java/com/info/sn/jpush/MyReceiver.java
+++ b/app/src/main/java/com/info/sn/jpush/MyReceiver.java
@@ -1,129 +1,614 @@
package com.info.sn.jpush;
+import android.annotation.SuppressLint;
+import android.app.ActivityManager;
+import android.app.usage.UsageStats;
+import android.app.usage.UsageStatsManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.os.Environment;
+import android.provider.Settings;
import android.text.TextUtils;
+import android.util.Log;
+import android.view.WindowManager;
+import com.arialyy.aria.core.Aria;
+import com.arialyy.aria.core.download.DownloadEntity;
import com.info.sn.MainActivity;
+import com.info.sn.network.UrlPath;
+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.info.sn.utils.Utils;
+import com.info.sn.view.CustomDialog;
+import com.lzy.okgo.OkGo;
+import com.lzy.okgo.callback.StringCallback;
+import com.lzy.okgo.model.Response;
import org.json.JSONException;
import org.json.JSONObject;
+import java.io.File;
import java.util.Iterator;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
import cn.jpush.android.api.JPushInterface;
/**
* 自定义接收器
- *
+ *
* 如果不定义这个 Receiver,则:
* 1) 默认用户会打开主界面
* 2) 接收不到自定义消息
*/
public class MyReceiver extends BroadcastReceiver {
- private static final String TAG = "JIGUANG-Example";
+ 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));
+ @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...
+ 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_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_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] 用户点击打开了通知");
+ } 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);
+ //打开自定义的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_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){
+ } 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;
- }
+ // 打印所有的 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();
+ 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!");
- }
+ 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) {
+ } else {
+ sb.append("\nkey:" + key + ", value:" + bundle.get(key));
+ }
+ }
+ return sb.toString();
+ }
+
+ //定义接收极光推送消息的类型。
+ private static final String JIGUANG_GET_DRIVELINE = "1";
+ //1.获取设备在线信息
+ private static final String JIGUANG_GET_STARTTIME = "2";
+ // 2.获取当前正在运行得应用和电量
+ private static final String JIGUANG_USB_STATE = "3";
+ // 3.数据线传输管控
+ private static final String JIGUANG_TFCARD_STATE = "4";
+ // 4.TF卡管控
+ private static final String JIGUANG_BLUETOOTH_STATE = "5";
+ // 5.蓝牙管控
+ private static final String JIGUANG_BROWSER_URLPATH = "6";
+ // 6.浏览器上网管控
+ private static final String JIGUANG_APP_NETWORKSTATE = "7";
+ // 7.应用联网管控
+ private static final String JIGUANG_APP_LOCKEDSTATE = "8";
+ // 8.应用锁管控
+ private static final String JIGUANG_FORCE_INSTALLAPK = "9";
+ // 9.强制安装应用
+ private static final String JIGUANG_FORCE_UNINSTALLAPK = "10";
+ // 10.强制卸载应用
+ private static final String JIGUANG_BIND_DEVIVES = "11";
+ // 11.绑定设备
+ private static final String JIGUANG_TFMEDIA = "12";
+ //12.影音格式管控
+ private static final String JIGUANG_CAMRERA = "13";
+ //13.摄像头管控
+ private static final String JIGUANG_PHONE = "14";
+ //14.电话管控管控
+ private static final String JIGUANG_DISABLE_UPDATAE = "15";
+ //14.电话管控管控
+ private static final String JIGUANG_APP_WEBSITE = "16";
+ //16.app内部网址管控
+
+ //
+ //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);
+// }
+ String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
+ String member_id = (String) SPUtils.get(context, "member_id", "-1");
+ String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
+ String title = bundle.getString(JPushInterface.EXTRA_TITLE);
+ String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE);
+ String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
+
+ switch (message) {
+ case JIGUANG_GET_DRIVELINE:
+ HTTPInterface.getDriveState(member_id, sn_id);
+ break;
+ case JIGUANG_GET_STARTTIME:
+ sendStartTime(context, extras);
+ break;
+ case JIGUANG_USB_STATE:
+ setUsbState(context, extras);
+ break;
+ case JIGUANG_TFCARD_STATE:
+ setTfcardState(context, extras);
+ break;
+ case JIGUANG_BLUETOOTH_STATE:
+ setBluetoothState(context, extras);
+ break;
+ case JIGUANG_BROWSER_URLPATH:
+ setBrowserUrlpath(context, extras);
+ break;
+ case JIGUANG_APP_NETWORKSTATE:
+ setAppNetworkstate(context, extras);
+ break;
+ case JIGUANG_APP_LOCKEDSTATE:
+ setAppLockedstate(context, extras);
+ break;
+ case JIGUANG_FORCE_INSTALLAPK:
+ intallApk(extras);
+ break;
+ case JIGUANG_FORCE_UNINSTALLAPK:
+ unintallApk(context, extras);
+ break;
+ case JIGUANG_BIND_DEVIVES:
+ bindService(context, extras);
+ break;
+ case JIGUANG_TFMEDIA:
+
+ break;
+ case JIGUANG_CAMRERA:
+ break;
+ case JIGUANG_PHONE:
+ break;
+ case JIGUANG_DISABLE_UPDATAE:
+ break;
+ case JIGUANG_APP_WEBSITE:
+ break;
+ }
+
+ }
+
+ synchronized private void sendStartTime(Context context, String jsonArray) {
+ if (jsonArray.length() > 0) {
+ try {
+ JSONObject extra = new JSONObject(jsonArray);
+ String random = extra.getString("random");
+ int battery = getSystemBattery(context);
+ HTTPInterface.sendStartTime(context, 0, getTaskPackname(context), battery, random);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 实时获取电量
+ */
+ public static int getSystemBattery(Context context) {
+ 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;
+ }
+
+ public static String getTaskPackname(Context context) {
+ String currentApp = "CurrentNULL";
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
+ @SuppressLint("WrongConstant") 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;
+ }
+
+ synchronized private void setUsbState(Context context, 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(context.getContentResolver(), "qch_usb_choose", "usb_charge");
+ LogUtils.e("setUsbState:", Settings.System.getString(context.getContentResolver(), "qch_usb_choose"));
+ } else {
+ boolean qch_usb_choose = Settings.System.putString(context.getContentResolver(), "qch_usb_choose", "usb_mtp");
+ LogUtils.e("setUsbState:", Settings.System.getString(context.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(Context context, 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(context.getContentResolver(), "qch_sdcard_forbid_on", is_tf);
+ if (qch_sdcard_forbid_on) {
+ LogUtils.e("setTfcardState:", Settings.System.getString(context.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(Context context, 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(context.getContentResolver(), "qch_bt_forbid_on", is_bluetooth);
+ if (qch_bt_forbid_on) {
+ LogUtils.e("setBluetoothState:", Settings.System.getString(context.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(Context context, String jsonArray) {
+ if (jsonArray.length() > 0) {
+ try {
+ JSONObject extra = new JSONObject(jsonArray);
+ String white = extra.getString("white");
+ if (white != null && !white.equals("")) {
+ boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white);
+ Log.e("SystemSetting", "setBrowserList---------" + whiteList + ":" + white);
+ } else {
+ Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " ");
+ }
+ String black = extra.getString("black");
+ if (black != null && !black.equals("")) {
+ boolean blackList = Settings.System.putString(context.getContentResolver(), "qch_webblack_url", black);
+ Log.e("SystemSetting", "setBrowserList---------" + blackList + ":" + black);
+ } else {
+ Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " ");
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("setBrowserUrlpath", e.getMessage());
+ }
+ } else {
+ boolean setBrowserUrlpath = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", "invalid");
+ ToastUtil.debugShow("setBrowserUrlpath jsonArray is NULL,set default: " + setBrowserUrlpath);
+ }
+ }
+
+ synchronized private void setAppNetworkstate(Context context, 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_allow = Settings.System.putString(context.getContentResolver(), "qch_jgy_network_allow", package0);
+ LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_allow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_allow"));
+ } else {
+ boolean qch_jgy_network_allow = Settings.System.putString(context.getContentResolver(), "qch_jgy_network_allow", "invalid");
+ LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_allow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_allow"));
+ }
+ if (package1.length() != 0) {
+ boolean qch_jgy_network_disallow = Settings.System.putString(context.getContentResolver(), "qch_jgy_network_disallow", package1);
+ LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_disallow"));
+ } else {
+ boolean qch_jgy_network_disallow = Settings.System.putString(context.getContentResolver(), "qch_jgy_network_disallow", "invalid");
+ LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(context.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(Context context, 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 = context.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");
+
+ if (Aria.download(this).taskExists(url)) {
+
+ List entity = Aria.download(this).getDownloadEntity(url);
+ for (DownloadEntity downloadEntity : entity) {
+ Aria.download(this).load(downloadEntity.getId()).cancel(true);
+ }
+ }
+
+ 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);
+// }
+// });
+ Aria.download(this).resumeAllTask();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("intallApk", e.getMessage());
+ }
+ }
+
+
+ synchronized private void unintallApk(Context context, 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(context.getApplicationContext().getPackageName())) {
+ if (!ApkUtils.isAvailable(context.getApplicationContext(), packageName)) {
+ HTTPInterface.setAppuninstallInfo(sn_id, packageName);
+ } else {
+ ApkUtils.deleteApkInSilence(packageName);
+ }
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("unintallApk", e.getMessage());
+ }
+ }
+
+ synchronized void bindService(final Context context, String json) {
+ ToastUtil.debugShow("收到绑定设备请求");
+
+ try {
+// com.alibaba.fastjson.JSONObject jsonObject= JSON.parseObject(json);
+// String userName =jsonObject.getString("member_name");
+// final String id =jsonObject.getString("id");
+// String phoneNum =jsonObject.getString("member_phone");
+ JSONObject object = new JSONObject(json);
+ String userName = object.getString("member_name");
+ final String id = object.getString("id");
+ String phoneNum = object.getString("member_phone");
+ final CustomDialog dialog = new CustomDialog(context);
+ dialog.setMessage(phoneNum + "的用户请求绑定你的平板")
+ .setTitle("绑定请求")
+ .setPositive("允许")
+ .setNegtive("拒绝")
+// .setSingle(true)
+ .setOnClickBottomListener(new CustomDialog.OnClickBottomListener() {
+ @Override
+ public void onPositiveClick() {
+ bind(context, id);
+ dialog.dismiss();
+ }
+
+ @Override
+ public void onNegtiveClick() {
+ ToastUtil.show("设备取消绑定");
+ dialog.dismiss();
+ }
+ });
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.show();
+// AlertDialog.Builder builder = new AlertDialog.Builder(this)
+// .setTitle("设备绑定")
+// .setIcon(R.mipmap.ic_launcher)
+// .setCancelable(false)
+// .setMessage("用户:“" + userName + "”" + "\n手机:“" + phoneNum + "”" + "\n请求绑定此设备")
+// .setPositiveButton("确认绑定", new DialogInterface.OnClickListener() {
+// @Override
+// public void onClick(DialogInterface dialogInterface, int i) {
+// bind(id);
+// }
+// })
+// .setNegativeButton("取消", new DialogInterface.OnClickListener() {
+// @Override
+// public void onClick(DialogInterface dialog, int which) {
+// dialog.dismiss();
+// ToastUtil.show("设备取消绑定");
+// }
+// });
+// AlertDialog ad = builder.create();
+// ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+// ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
+// ad.show();
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ LogUtils.e("bindService", e.getMessage());
+ }
+
+
+ }
+
+ synchronized private void bind(final Context context, String id) {
+ OkGo.post(UrlPath.BIND_DEVICES)
+ .params("id", id)
+ .params("sn", Utils.getSerial())
+ .execute(new StringCallback() {
+ @Override
+ public void onSuccess(Response response) {
+ String s = response.body();
+ try {
+ JSONObject jsonObject = new JSONObject(s);
+ int code = jsonObject.getInt("code");
+ String msg = jsonObject.getString("msg");
+ if (code == 200) {
+ ToastUtil.show("绑定成功");
+ } else {
+ ToastUtil.show(msg);
+ }
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ Intent intent = new Intent(MainActivity.REFRESHACTION);
+ context.sendBroadcast(intent);
+ }
+
+ @Override
+ public void onError(Response response) {
+ super.onError(response);
+ Log.e("bind", response.getException().getMessage());
+ }
+
+ });
+ }
- }
- }
- LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
- }
- }
}
diff --git a/app/src/main/java/com/info/sn/network/UrlPath.java b/app/src/main/java/com/info/sn/network/UrlPath.java
index b6b851e..f052b69 100644
--- a/app/src/main/java/com/info/sn/network/UrlPath.java
+++ b/app/src/main/java/com/info/sn/network/UrlPath.java
@@ -23,5 +23,6 @@ public class UrlPath {
//获取所有应用包名
public final static String BIND_DEVICES = HOMEPATHRUL + "Member/binding";
//绑定设备消息
-
+ public final static String SET_BROWSER_URL = HOMEPATHRUL + "Contorl/snbrower";
+ //浏览器网址管控
}
diff --git a/app/src/main/java/com/info/sn/network/api/HTTPInterface.java b/app/src/main/java/com/info/sn/network/api/HTTPInterface.java
index 40b6bdc..901c1ac 100644
--- a/app/src/main/java/com/info/sn/network/api/HTTPInterface.java
+++ b/app/src/main/java/com/info/sn/network/api/HTTPInterface.java
@@ -6,14 +6,17 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.provider.Settings;
import android.util.Log;
import androidx.annotation.RequiresApi;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.info.sn.bean.MessageWhat;
import com.info.sn.bean.UserInfo;
+import com.info.sn.jpush.TagAliasOperatorHelper;
import com.info.sn.network.UrlPath;
import com.info.sn.utils.LogUtils;
import com.info.sn.utils.SPUtils;
@@ -24,15 +27,20 @@ import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
import java.util.Random;
+import java.util.Set;
+
+import okhttp3.Call;
+import okhttp3.internal.Util;
public class HTTPInterface {
//获取设备信息接口
public static synchronized void checkDevicesInfo(final Handler handler) {
OkGo.post(UrlPath.SNINFO)
- .params("sn", Utils.getSn())
+ .params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
public void onSuccess(Response response) {
@@ -161,6 +169,7 @@ public class HTTPInterface {
}
});
}
+
synchronized public static void checkUpdateByself(final Handler handler, String packageName, String versionCode) {
OkGo.post(UrlPath.GET_APP_UPDATE)
.params("code", versionCode)
@@ -279,6 +288,7 @@ public class HTTPInterface {
}
});
}
+
synchronized public static void getAllAppPackageName(final Handler handler) {
OkGo.get(UrlPath.GET_ALL_PACKAGENAME).execute(new StringCallback() {
@Override
@@ -318,4 +328,42 @@ public class HTTPInterface {
}
+ private void setBrowser(final Context context) {
+ OkGo.post(UrlPath.SET_BROWSER_URL)
+ .params("sn", Utils.getSerial())
+ .execute(new StringCallback() {
+ @Override
+ public void onSuccess(Response response) {
+ try {
+ JSONObject jsonObject = JSON.parseObject(response.body());
+ int code = jsonObject.getInteger("code");
+ String msg = jsonObject.getString("msg");
+ if (code == 200) {
+ JSONObject data = JSON.parseObject(jsonObject.getString("data"));
+ String white = data.getString("white");
+ if (white != null && !white.equals("")) {
+ boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white);
+ Log.e("SystemSetting", "setBrowserList---------" + whiteList + ":" + white);
+ } else {
+ Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " ");
+ }
+ String black = data.getString("black");
+ if (black != null && !black.equals("")) {
+ boolean blackList = Settings.System.putString(context.getContentResolver(), "qch_webblack_url", black);
+ Log.e("SystemSetting", "setBrowserList---------" + blackList + ":" + black);
+ } else {
+ Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " ");
+ }
+ } else {
+ Log.e("fht", "setBrowserList" + msg);
+ }
+ } catch (JSONException e) {
+ Log.e("fht", "setBrowserList" + e.getMessage());
+
+ }
+ }
+ });
+ }
+
+
}
diff --git a/app/src/main/java/com/info/sn/service/MyDownloadService.java b/app/src/main/java/com/info/sn/service/MyDownloadService.java
index 1235bea..65f6439 100644
--- a/app/src/main/java/com/info/sn/service/MyDownloadService.java
+++ b/app/src/main/java/com/info/sn/service/MyDownloadService.java
@@ -176,7 +176,7 @@ public class MyDownloadService extends Service implements NetworkUtils.OnNetwork
public void onSuccess(final Response response) {
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
// ApkUtils.installApkInSilence(response.body().getAbsolutePath(), Launcher.this.getPackageName());
-// AlertDialog.Builder builder = new AlertDialog.Builder(MyDownloadService.this)
+// AlertDialog.Builder builder = new AlertDialog.Builder(MyDownFile download FailureloadService.this)
// .setTitle("软件更新")
// .setIcon(R.mipmap.ic_launcher)
// .setCancelable(false)
diff --git a/app/src/main/java/com/info/sn/utils/amapUtils.java b/app/src/main/java/com/info/sn/utils/amapUtils.java
new file mode 100644
index 0000000..ae9ab1b
--- /dev/null
+++ b/app/src/main/java/com/info/sn/utils/amapUtils.java
@@ -0,0 +1,119 @@
+/**
+ *
+ */
+package com.info.sn.utils;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.text.TextUtils;
+
+import com.amap.api.location.AMapLocation;
+
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+
+/**
+ * 辅助工具类
+ * @创建时间: 2015年11月24日 上午11:46:50
+ * @项目名称: AMapLocationDemo2.x
+ * @author hongming.wang
+ * @文件名称: amapUtils.java
+ * @类型名称: amapUtils
+ */
+public class amapUtils {
+ /**
+ * 开始定位
+ */
+ public final static int MSG_LOCATION_START = 0;
+ /**
+ * 定位完成
+ */
+ public final static int MSG_LOCATION_FINISH = 1;
+ /**
+ * 停止定位
+ */
+ public final static int MSG_LOCATION_STOP= 2;
+
+ public final static String KEY_URL = "URL";
+ public final static String URL_H5LOCATION = "file:///android_asset/sdkLoc.html";
+ /**
+ * 根据定位结果返回定位信息的字符串
+ * @param location
+ * @return
+ */
+ public synchronized static String getLocationStr(AMapLocation location){
+ if(null == location){
+ return null;
+ }
+ StringBuffer sb = new StringBuffer();
+ //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明
+ if(location.getErrorCode() == 0){
+ sb.append("定位成功" + "\n");
+ sb.append("定位类型: " + location.getLocationType() + "\n");
+ sb.append("经 度 : " + location.getLongitude() + "\n");
+ sb.append("纬 度 : " + location.getLatitude() + "\n");
+ sb.append("精 度 : " + location.getAccuracy() + "米" + "\n");
+ sb.append("提供者 : " + location.getProvider() + "\n");
+
+ sb.append("速 度 : " + location.getSpeed() + "米/秒" + "\n");
+ sb.append("角 度 : " + location.getBearing() + "\n");
+ // 获取当前提供定位服务的卫星个数
+ sb.append("星 数 : " + location.getSatellites() + "\n");
+ sb.append("国 家 : " + location.getCountry() + "\n");
+ sb.append("省 : " + location.getProvince() + "\n");
+ sb.append("市 : " + location.getCity() + "\n");
+ sb.append("城市编码 : " + location.getCityCode() + "\n");
+ sb.append("区 : " + location.getDistrict() + "\n");
+ sb.append("区域 码 : " + location.getAdCode() + "\n");
+ sb.append("地 址 : " + location.getAddress() + "\n");
+ sb.append("兴趣点 : " + location.getPoiName() + "\n");
+ //定位完成的时间
+ sb.append("定位时间: " + formatUTC(location.getTime(), "yyyy-MM-dd HH:mm:ss") + "\n");
+ } else {
+ //定位失败
+ sb.append("定位失败" + "\n");
+ sb.append("错误码:" + location.getErrorCode() + "\n");
+ sb.append("错误信息:" + location.getErrorInfo() + "\n");
+ sb.append("错误描述:" + location.getLocationDetail() + "\n");
+ }
+ //定位之后的回调时间
+ sb.append("回调时间: " + formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n");
+ return sb.toString();
+ }
+
+ private static SimpleDateFormat sdf = null;
+ public static String formatUTC(long l, String strPattern) {
+ if (TextUtils.isEmpty(strPattern)) {
+ strPattern = "yyyy-MM-dd HH:mm:ss";
+ }
+ if (sdf == null) {
+ try {
+ sdf = new SimpleDateFormat(strPattern, Locale.CHINA);
+ } catch (Throwable e) {
+ }
+ } else {
+ sdf.applyPattern(strPattern);
+ }
+ return sdf == null ? "NULL" : sdf.format(l);
+ }
+
+ /**
+ * 获取app的名称
+ * @param context
+ * @return
+ */
+ public static String getAppName(Context context) {
+ String appName = "";
+ try {
+ PackageManager packageManager = context.getPackageManager();
+ PackageInfo packageInfo = packageManager.getPackageInfo(
+ context.getPackageName(), 0);
+ int labelRes = packageInfo.applicationInfo.labelRes;
+ appName = context.getResources().getString(labelRes);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ return appName;
+ }
+}
diff --git a/app/src/main/java/com/info/sn/view/CustomDialog.java b/app/src/main/java/com/info/sn/view/CustomDialog.java
index 8508c94..7595d95 100644
--- a/app/src/main/java/com/info/sn/view/CustomDialog.java
+++ b/app/src/main/java/com/info/sn/view/CustomDialog.java
@@ -3,6 +3,8 @@ package com.info.sn.view;
import android.app.Dialog;
import android.content.Context;
+import android.content.res.Configuration;
+import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
@@ -237,4 +239,5 @@ public class CustomDialog extends Dialog {
return this;
}
+
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 818e054..698071e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -3,4 +3,10 @@
打开
打开失败!
请输入应用名称或关键字
+
+ 提示
+ 当前应用缺少必要权限。\n\n请点击\"设置\"-\"权限\"-打开所需权限。
+ 设置
+ 取消
+