update:2019.04.22
fix:增加绑定确认 add:
This commit is contained in:
@@ -1,31 +1,49 @@
|
||||
package com.info.sn;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Application;
|
||||
import android.app.usage.UsageStats;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
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 android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.info.sn.jpush.LocalBroadcastManager;
|
||||
import com.info.sn.network.UrlPath;
|
||||
import com.info.sn.network.api.HTTPInterface;
|
||||
import com.info.sn.service.MyDownloadService;
|
||||
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.info.sn.view.InfoDialog;
|
||||
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.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
@@ -49,7 +67,6 @@ public class MyApplication extends Application {
|
||||
OkGo.getInstance().init(this);
|
||||
// NetworkUtils.registerNetworkStatusChangedListener(this);
|
||||
Aria.init(this);
|
||||
Aria.download(this).register();
|
||||
Aria.download(this).resumeAllTask();
|
||||
|
||||
}
|
||||
@@ -80,7 +97,7 @@ public class MyApplication extends Application {
|
||||
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");
|
||||
@SuppressLint("WrongConstant") UsageStatsManager usm = (UsageStatsManager) context.getSystemService("usagestats");
|
||||
long time = System.currentTimeMillis();
|
||||
List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000 * 1000, time);
|
||||
if (appList != null && appList.size() > 0) {
|
||||
@@ -139,6 +156,7 @@ public class MyApplication extends Application {
|
||||
private static final String JIGUANG_APP_LOCKEDSTATE = "8";
|
||||
private static final String JIGUANG_FORCE_INSTALLAPK = "9";
|
||||
private static final String JIGUANG_FORCE_UNINSTALLAPK = "10";
|
||||
private static final String JIGUANG_BIND_DEVIVES = "11";
|
||||
|
||||
|
||||
synchronized public void manageCustomMessage(CustomMessage customMessage) {
|
||||
@@ -184,6 +202,8 @@ public class MyApplication extends Application {
|
||||
case JIGUANG_FORCE_UNINSTALLAPK:
|
||||
unintallApk(EXTRA);
|
||||
break;
|
||||
case JIGUANG_BIND_DEVIVES:
|
||||
bindService(EXTRA);
|
||||
}
|
||||
|
||||
|
||||
@@ -320,11 +340,11 @@ public class MyApplication extends Application {
|
||||
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"));
|
||||
boolean qch_jgy_network_allow = Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", package0);
|
||||
LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_allow + ":" + 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"));
|
||||
boolean qch_jgy_network_allow = Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", "invalid");
|
||||
LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_allow + ":" + 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);
|
||||
@@ -369,11 +389,21 @@ public class MyApplication extends Application {
|
||||
|
||||
//静默安装应用,使用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<DownloadEntity> 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)
|
||||
@@ -402,7 +432,7 @@ public class MyApplication extends Application {
|
||||
// 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());
|
||||
@@ -430,6 +460,97 @@ public class MyApplication extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void bindService(String json) {
|
||||
ToastUtil.debugShow("收到绑定设备请求");
|
||||
|
||||
try {
|
||||
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(getAppContext());
|
||||
dialog.setMessage(phoneNum + "的用户请求绑定你的平板")
|
||||
.setTitle("绑定请求")
|
||||
.setPositive("允许")
|
||||
.setNegtive("拒绝")
|
||||
// .setSingle(true)
|
||||
.setOnClickBottomListener(new CustomDialog.OnClickBottomListener() {
|
||||
@Override
|
||||
public void onPositiveClick() {
|
||||
bind(id);
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegtiveClick() {
|
||||
ToastUtil.show("设备取消绑定");
|
||||
dialog.dismiss();
|
||||
}
|
||||
}).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(String id) {
|
||||
OkGo.<String>post(UrlPath.BIND_DEVICES)
|
||||
.params("id", id)
|
||||
.params("sn", Utils.getSerial())
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> 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);
|
||||
sendBroadcast(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
Log.e("bind", response.getException().getMessage());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
// @Override
|
||||
// public void onDisconnected() {
|
||||
// LogUtils.e("onDisconnected", "网络断开");
|
||||
@@ -443,15 +564,4 @@ public class MyApplication extends Application {
|
||||
// }
|
||||
|
||||
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user