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.bluetooth.BluetoothAdapter; 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.os.Message; import android.provider.Settings; import android.text.TextUtils; import android.util.Log; import android.view.WindowManager; import com.alibaba.fastjson.JSON; 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.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.util.ArrayList; import java.util.Arrays; 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"; @Override public void onReceive(Context context, Intent intent) { 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()); } } // 打印所有的 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(); } //定义接收极光推送消息的类型。 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); HTTPInterface.checkDevicesInfo(context); 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(context, extras); break; case JIGUANG_FORCE_UNINSTALLAPK: unintallApk(context, extras); break; case JIGUANG_BIND_DEVIVES: bindService(context, extras); break; case JIGUANG_TFMEDIA: setTFmedia(context, extras); break; case JIGUANG_CAMRERA: setCameta(context, extras); break; case JIGUANG_PHONE: setPhone(context, extras); break; case JIGUANG_DISABLE_UPDATAE: setAppUpdate(context, extras); break; case JIGUANG_APP_WEBSITE: break; } } private int changeNum(int paramInt) { switch (paramInt) { default: return 1; case 0: return 1; case 1: break; } return 0; } private void setPhone(Context context, String json) { com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(json); int setting_phone = jsonObject.getInteger("setting_phone"); Log.e("setting_phone", String.valueOf(setting_phone)); boolean qch_call_forbid = Settings.System.putInt(context.getContentResolver(), "qch_call_forbid", setting_phone); boolean qch_white_list_on = Settings.System.putInt(context.getContentResolver(), "qch_white_list_on", setting_phone); boolean qch_white_list_Array = Settings.System.putString(context.getContentResolver(), "qch_white_list_Array", "981964879"); Log.e("SystemSetting", "qch_call_forbid---------" + setting_phone); Log.e("SystemSetting", "qch_call_forbid---------" + qch_call_forbid); Log.e("SystemSetting", "qch_call_forbid---------" + qch_white_list_on); Log.e("SystemSetting", "qch_call_forbid---------" + qch_white_list_Array); } private void setCameta(Context context, String json) { com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(json); //摄像头开关 int setting_camera = jsonObject.getInteger("setting_camera"); Settings.System.putInt(context.getContentResolver(), "qch_app_camera", setting_camera); ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera"); Log.e("SystemSetting", "setting_camera---------" + setting_camera); String cameraStatus = ""; switch (setting_camera) { case 0: cameraStatus = "qch_camera_open"; break; case 1: cameraStatus = "qch_camera_forbid"; break; } Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings"); context.sendBroadcast(cameraIntent); } String tftype = ".png,.bmp,.jpg,.mpo,.jpeg,.gif,.tif,.tiff,.dib,.jpe,.jfif,.psd,.pdd,.rle,.dcm,.dic,.dc3,.eps,.iff,.tdi,.jpf,.jpx,.jp2,.j2c,.jpc,.jps,.j2k,.pcx,.pdp,.raw,.pns,.aac,.ac3,.aiff,.amr,.ape,.au,.fla,.flac,.imy,.m4r,.mid,.mka,.mmf,.mp2,.mp3,.mxmf,.ogg,.ra,.ts,.wma,.wv,.xmf,.m4a,.wav,.3gpp,.mp4,.3gp,.as,.asf,.avi,.dat,.f4v,.flv,.mkv,.mov,.mpg,.rmvb,.swf,.trp,.vob,.webm,.wmv,.navi,.video,.ram,.qsv,.xv,.rm,.vcd,.svcd,.mlv,.mpe,.mpeg,.m2v,.iso,.html,.htm,.txt,.xls,.doc,.docx,.docm,.pdf,.xps,.dot,.dotx,.dotm,.mht,.mhtml,.rft,.xml,.xlsx,.xlsm,.xlsb,.xltx,.xltm,.xlt,.wps,.wpt,.rtf,.et,.ett,.dps,.dpt,.wpp,.ppt,.pptx,.pptm,.pps,.pot,.potm,.ppsx,.ppsm,.odp"; private void setTFmedia(Context context, String json) { com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(json); //影音管控开关 int setting_tfmedia = jsonObject.getInteger("setting_tfmedia"); Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", setting_tfmedia); Log.e("SystemSetting", "qch_tfmedia_forbid---------" + setting_tfmedia); if (setting_tfmedia == 1) { String s = Settings.System.getString(context.getContentResolver(), "qch_tfmedia_filetypes");//影音管控 Log.e("SystemSetting", "qch_tfmedia_filetypes old" + s); boolean b = Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", tftype);//影音管控 Log.e("SystemSetting", "qch_tfmedia_filetypes---------" + b + ":" + tftype); } else { Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0); } } private void setAppUpdate(Context context, String json) { com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(json); String is_upgrade = jsonObject.getString("is_upgrade"); String packageName = jsonObject.getString("package"); String nowApplist = Settings.System.getString(context.getContentResolver(), "qch_app_forbid"); List applist = new ArrayList<>(Arrays.asList(nowApplist.split(","))); if (is_upgrade.equals("0")) { if (applist.contains(packageName)) { applist.remove(packageName); } else { Log.e("setAppUpdate", "app已经存在"); } } else if (is_upgrade.equals("1")) { if (!applist.contains(packageName)) { applist.add(packageName); } } String packageString = ""; for (String s : applist) { if (s.equals("")) { continue; } packageString += s + ","; } if (!packageString.equals("")) { packageString = packageString.substring(0, packageString.length() - 1); } Settings.System.putString(context.getContentResolver(), "qch_app_forbid", packageString); Log.e("setAppUpdate", Settings.System.getString(context.getContentResolver(), "qch_app_forbid")); } 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")); } String usbStatus = ""; switch (is_dataline) { case 1: usbStatus = "qch_action_usb_usb_charge"; break; case 0: usbStatus = "qch_action_usb_usb_mtp"; break; // case "usb_midi": // usbStatus = "qch_action_usb_usb_midi"; // break; } Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); context.sendBroadcast(usbIntent); } 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"); } } private BluetoothAdapter mBluetoothAdapter; synchronized private void setBluetoothState(Context context, String jsonArray) { if (jsonArray.length() > 0) { if (null == mBluetoothAdapter) { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();//获取默认蓝牙适配器 } try { JSONObject extra = new JSONObject(jsonArray); int is_bluetooth = extra.getInt("is_bluetooth"); if (is_bluetooth==1){ mBluetoothAdapter.disable();//设置关闭时关闭蓝牙 } boolean qch_bt_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_bht_forbid_on", is_bluetooth); if (qch_bt_forbid_on) { LogUtils.e("setBluetoothState:", Settings.System.getString(context.getContentResolver(), "qch_bht_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" + whiteList + ":" + white); } else { Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " "); } Log.e("whiteList", Settings.System.getString(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" + blackList + ":" + black); } else { Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " "); } Log.e("blackList", Settings.System.getString(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", "qch_jgy_network_allow::" + 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", "qch_jgy_network_allow::" + 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", "qch_jgy_network_disallow::" + 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", "qch_jgy_network_disallow::" + 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(Context context, String jsondata) { HTTPInterface.getAllAppPackageName(context); 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.uninstallApp(context, 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()); } }); } }