update:2020.05.22

fix:toast显示问题,唤醒服务问题
add:
This commit is contained in:
2020-05-22 16:48:28 +08:00
parent a9dbcb17a6
commit 3bd4a64371
12 changed files with 223 additions and 69 deletions

View File

@@ -15,8 +15,8 @@ android {
minSdkVersion 20 minSdkVersion 20
targetSdkVersion 29 targetSdkVersion 29
versionCode 131 versionCode 134
versionName "2.8.8"//测试jiaoguanyi.cn versionName "2.9.1"//测试jiaoguanyi.cn
// versionCode 127 // versionCode 127
// versionName "2.0.0.7"// 正式jiaoguanyi.com 双数正式 单数测试 // versionName "2.0.0.7"// 正式jiaoguanyi.com 双数正式 单数测试
multiDexEnabled true multiDexEnabled true

View File

@@ -9,9 +9,7 @@
<uses-permission android:name="android.permission.MASTER_CLEAR" /> <uses-permission android:name="android.permission.MASTER_CLEAR" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.ACTION_SCREEN_ON" /> <uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACTION_SCREEN_OFF" />
<!--静默安装权限--> <!--静默安装权限-->
<uses-permission <uses-permission
android:name="android.permission.INSTALL_PACKAGES" android:name="android.permission.INSTALL_PACKAGES"
@@ -69,7 +67,16 @@
<service <service
android:name=".server.StepService" android:name=".server.StepService"
android:exported="true" /> android:exported="true" />
<service android:name=".server.InitJpushServer" /> <service android:name=".server.InitJpushServer"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
<data android:scheme="package" />
</intent-filter>
</service>
<receiver <receiver
android:name=".receiver.NewAppReceiver" android:name=".receiver.NewAppReceiver"

View File

@@ -1,7 +1,10 @@
package com.mjsheng.myappstore; package com.mjsheng.myappstore;
import android.app.Activity; import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
@@ -25,6 +28,9 @@ import com.mjsheng.myappstore.activity.MainActivity;
import com.mjsheng.myappstore.comm.CommonDatas; import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.jpush.TagAliasOperatorHelper; import com.mjsheng.myappstore.jpush.TagAliasOperatorHelper;
import com.mjsheng.myappstore.network.HTTPInterface; import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.server.GuardService;
import com.mjsheng.myappstore.server.InitJpushServer;
import com.mjsheng.myappstore.server.MyDownloadService;
import com.mjsheng.myappstore.utils.Configure; import com.mjsheng.myappstore.utils.Configure;
import com.mjsheng.myappstore.utils.MySQLData; import com.mjsheng.myappstore.utils.MySQLData;
import com.mjsheng.myappstore.utils.ToastUtil; import com.mjsheng.myappstore.utils.ToastUtil;
@@ -109,7 +115,6 @@ public class MyApplication extends MultiDexApplication {
.build() .build()
); );
// 设置开启日志,发布时请关闭日志 // 设置开启日志,发布时请关闭日志
JPushInterface.setDebugMode(true); JPushInterface.setDebugMode(true);
JPushInterface.requestPermission(this); JPushInterface.requestPermission(this);
@@ -132,11 +137,57 @@ public class MyApplication extends MultiDexApplication {
NetStateChangeReceiver.registerReceiver(this); NetStateChangeReceiver.registerReceiver(this);
ToastUtil.init(this); ToastUtil.init(this);
if (!BuildConfig. DEBUG){ if (!BuildConfig.DEBUG) {
catchException(); catchException();
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//8.0之后需要在
registerTimeReceiver();
}
} }
private receiver receiver;
//监听时间和日期变化
public void registerTimeReceiver() {
receiver = new receiver();
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(Intent.ACTION_USER_PRESENT);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_UNLOCKED);
registerReceiver(receiver, filter);
}
Long time1 = 0L;
Long time2 = 0L;
public class receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.e("fht", "receiver action:" + action);
if (action.equals(Intent.ACTION_USER_PRESENT)
|| action.equals(Intent.ACTION_SCREEN_ON)
|| action.equals(Intent.ACTION_SCREEN_OFF)
) {
time2 = System.currentTimeMillis();
if ((time2 - time1) > 60 * 1000) {
//可能会多次触发1分钟之内不执行
//application中启动服务,startcommand执行会两次
startService(new Intent(context, InitJpushServer.class));
startService(new Intent(context, GuardService.class));
time1 = time2;
Log.e("fht", "onReceive");
} else {
}
}
}
}
public void onTagOperatorResult(JPushMessage jPushMessage) { public void onTagOperatorResult(JPushMessage jPushMessage) {
if (jPushMessage == null) { if (jPushMessage == null) {

View File

@@ -530,11 +530,8 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
// fromNetToUpdate(); // fromNetToUpdate();
String registrationID = JPushInterface.getRegistrationID(MainActivity.this); String registrationID = JPushInterface.getRegistrationID(MainActivity.this);
Log.e("mjsheng", registrationID + "------------------------"); Log.e("mjsheng", registrationID + "------------------------");
List<String> list = SaveListUtils.getList(); SaveListUtils.getList();
if (list == null) {
return;
}
LogUtils.e(list.toString() + "-----------------------------");
} }
}); });
} }
@@ -1104,6 +1101,9 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
} else { } else {
Aria.download(this).resumeAllTask(); Aria.download(this).resumeAllTask();
} }
case -200:
boolean qch_force_app = Settings.System.putString(MainActivity.this.getContentResolver(), "qch_force_app", "invalid");
Log.e("fht", "qch_force_app:" + qch_force_app);
break; break;
default: default:
LogUtils.e("getForceDownload is error:" + forceDownloadBean.getMsg()); LogUtils.e("getForceDownload is error:" + forceDownloadBean.getMsg());
@@ -1145,24 +1145,19 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
return; return;
} }
getSelfDownload(data); getSelfDownload(data);
List<String> list = SaveListUtils.getList(); List<String> list = new ArrayList<>();
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
ForceDownloadData forceDownloadData = data.get(i); ForceDownloadData forceDownloadData = data.get(i);
String app_package = forceDownloadData.getApp_package(); String app_package = forceDownloadData.getApp_package();
String app_url = forceDownloadData.getApp_url(); String app_url = forceDownloadData.getApp_url();
Log.e("fht ", "packageName=" + app_package + ",URL= " + app_url); Log.e("fht ", "packageName=" + app_package + ",URL= " + app_url);
if (data.get(i).getApp_package().equals("com.jiaoguanyi.store")) { if (data.get(i).getApp_package().equals("com.jiaoguanyi.store")) {
continue;//为自身的跳过下载 continue;//为自身的跳过下载
} }
if (list != null) {
if (!list.contains(app_package)) { if (!list.contains(app_package)) {
SaveListUtils.addToList(app_package); list.add(app_package);
}
} else {
SaveListUtils.addToList(app_package);
} }
if (!AppUtils.isAppInstalled(app_package)) { if (!AppUtils.isAppInstalled(app_package)) {
Log.e("fht ", "download URL " + app_url); Log.e("fht ", "download URL " + app_url);
// if (!SaveListUtils.isDownLoading(app_package)) { // if (!SaveListUtils.isDownLoading(app_package)) {
@@ -1175,6 +1170,8 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
// } // }
} }
} }
SaveListUtils.setList(list);
SaveListUtils.sendForceAPP(this);
} }
private void getSelfDownload(List<ForceDownloadData> forceDownloadDataList) { private void getSelfDownload(List<ForceDownloadData> forceDownloadDataList) {

View File

@@ -39,6 +39,7 @@ public class Network {
// public static final String ROOT_URL = "http://www.as.xueshibao.com.cn/api/"; 弃用 // public static final String ROOT_URL = "http://www.as.xueshibao.com.cn/api/"; 弃用
// public static final String ROOT_URL = "https://www.jiaoguanyi.com/api/";//正式 弃用 // public static final String ROOT_URL = "https://www.jiaoguanyi.com/api/";//正式 弃用
// public static final String ROOT_URL = "https://partner.jiaoguanyi.com/api/";//正式 // public static final String ROOT_URL = "https://partner.jiaoguanyi.com/api/";//正式
// public static final String WebsocketURL = "ws://47.107.133.19:1234"; // public static final String WebsocketURL = "ws://47.107.133.19:1234";
public static final String ROOT_URL = "http://www.jiaoguanyi.cn/api/";//测试 public static final String ROOT_URL = "http://www.jiaoguanyi.cn/api/";//测试

View File

@@ -17,10 +17,7 @@ public class BootReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.e("BootReceiver", intent.getAction()); Log.e("BootReceiver", intent.getAction());
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
context.startService(new Intent(context, InitJpushServer.class)); startService(context);
context.startService(new Intent(context, StepService.class));
context.startService(new Intent(context, GuardService.class));
context.startService(new Intent(context, MyDownloadService.class));
} else if ( } else if (
intent.getAction().equals("android.intent.action.BATTERY_CHANGED") intent.getAction().equals("android.intent.action.BATTERY_CHANGED")
|| intent.getAction().equals("android.intent.action.BATTERY_CHANGED") || intent.getAction().equals("android.intent.action.BATTERY_CHANGED")
@@ -33,12 +30,17 @@ public class BootReceiver extends BroadcastReceiver {
|| intent.getAction().equals("android.intent.action.SCREEN_ON") || intent.getAction().equals("android.intent.action.SCREEN_ON")
|| intent.getAction().equals("android.intent.action.SCREEN_OFF") || intent.getAction().equals("android.intent.action.SCREEN_OFF")
) { ) {
Log.e("fht", "BootReceiver MSG" + intent.getAction()); //除了USER_PRESENT应该都收不到
Log.e("fht", "BootReceiver MSG:" + intent.getAction());
startService(context);
}
}
private void startService(Context context) {
context.startService(new Intent(context, InitJpushServer.class)); context.startService(new Intent(context, InitJpushServer.class));
context.startService(new Intent(context, StepService.class)); context.startService(new Intent(context, StepService.class));
context.startService(new Intent(context, GuardService.class)); context.startService(new Intent(context, GuardService.class));
context.startService(new Intent(context, MyDownloadService.class)); context.startService(new Intent(context, MyDownloadService.class));
} }
}
} }

View File

@@ -295,19 +295,10 @@ public class MyJPushReceiver extends BroadcastReceiver {
String str = jSONObject.optString("app_url"); String str = jSONObject.optString("app_url");
Log.e("mymjsheng", "app_package::" + s); Log.e("mymjsheng", "app_package::" + s);
Log.e("mymjsheng", "app_url::" + str); Log.e("mymjsheng", "app_url::" + str);
SaveListUtils.addToList(s); SaveListUtils.addList(s);
List<String> list = SaveListUtils.getList(); SaveListUtils.sendForceAPP(mContext);
if (list != null) {
if (!list.contains(s)) {
SaveListUtils.addToList(s);
}
} else {
SaveListUtils.addToList(s);
}
if (!AppUtils.isAppInstalled(s)) { if (!AppUtils.isAppInstalled(s)) {
if (!SaveListUtils.isDownLoading(s)) { if (!SaveListUtils.isDownLoading(s)) {
(Aria.download(this) (Aria.download(this)
.load(str) .load(str)
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(s) + ".apk").setExtendField(s)) .setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(s) + ".apk").setExtendField(s))
@@ -316,7 +307,6 @@ public class MyJPushReceiver extends BroadcastReceiver {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return;
} }
} }
@@ -493,7 +483,12 @@ public class MyJPushReceiver extends BroadcastReceiver {
switch (message) { switch (message) {
case MSG_DELETE: case MSG_DELETE:
if (!TextUtils.isEmpty(title)) { if (!TextUtils.isEmpty(title)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (SaveListUtils.getlist().contains(title)) {
SaveListUtils.getlist().remove(title);
}
SaveListUtils.sendForceAPP(mContext);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ApkUtils.uninstall(mContext, title); ApkUtils.uninstall(mContext, title);
} else { } else {
ApkUtils.deleteApkInSilence(title); ApkUtils.deleteApkInSilence(title);

View File

@@ -88,11 +88,18 @@ public class GuardService extends Service implements NetStateChangeObserver {
return START_STICKY; return START_STICKY;
} }
long time1 = 0L;
long time2 = 0L;
//在这里处理任务执行中的状态,如进度进度条的刷新 //在这里处理任务执行中的状态,如进度进度条的刷新
@Download.onTaskRunning @Download.onTaskRunning
protected void running(DownloadTask task) { protected void running(DownloadTask task) {
Log.e("aria", "正在下载=--------------::" + task.getState() + "-------" + task.getPercent() + "-------" + task.getExtendField()); Log.e("aria", "正在下载=--------------::" + task.getState() + "-------" + task.getPercent() + "-------" + task.getExtendField());
time2 = System.currentTimeMillis();
if ((time2 - time1) > 3499) {
ToastUtil.show("正在下载:" + task.getExtendField() + "--" + task.getPercent() + "%" + "\t" + Formatter.formatFileSize(GuardService.this, task.getSpeed()) + "/s"); ToastUtil.show("正在下载:" + task.getExtendField() + "--" + task.getPercent() + "%" + "\t" + Formatter.formatFileSize(GuardService.this, task.getSpeed()) + "/s");
time1 = time2;
}
} }
@Download.onTaskComplete @Download.onTaskComplete

View File

@@ -1,7 +1,10 @@
package com.mjsheng.myappstore.server; package com.mjsheng.myappstore.server;
import android.app.Service; import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Handler; import android.os.Handler;
@@ -46,7 +49,9 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushInterface;
@@ -84,6 +89,8 @@ public class InitJpushServer extends Service {
super.onCreate(); super.onCreate();
} }
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
// 初始化 JPush // 初始化 JPush
@@ -91,12 +98,10 @@ public class InitJpushServer extends Service {
timerImitate(); timerImitate();
// getNetworkState(); // getNetworkState();
Log.e("InitJpushServer", "onStartCommand"); Log.e("InitJpushServer", "onStartCommand");
// return super.onStartCommand(intent, flags, startId); // return super.onStartCommand(intent, flags, startId);
return START_STICKY; return START_STICKY;
} }
private void initJpush() { private void initJpush() {
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean(); TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
tagAliasBean.action = ACTION_SET; tagAliasBean.action = ACTION_SET;
@@ -134,7 +139,7 @@ public class InitJpushServer extends Service {
//重新设置jpush //重新设置jpush
private void timerImitate() { synchronized private void timerImitate() {
Observable.timer(15000, TimeUnit.MILLISECONDS) Observable.timer(15000, TimeUnit.MILLISECONDS)
.observeOn(rx.android.schedulers.AndroidSchedulers.mainThread()) .observeOn(rx.android.schedulers.AndroidSchedulers.mainThread())
.subscribe(new Action1<Long>() { .subscribe(new Action1<Long>() {
@@ -382,6 +387,10 @@ public class InitJpushServer extends Service {
Aria.download(this).resumeAllTask(); Aria.download(this).resumeAllTask();
} }
break; break;
case -200:
boolean qch_force_app = Settings.System.putString(InitJpushServer.this.getContentResolver(), "qch_force_app", "invalid");
Log.e("fht", "qch_force_app:" + qch_force_app);
break;
default: default:
LogUtils.e("getForceDownload is error:" + forceDownloadBean.getMsg()); LogUtils.e("getForceDownload is error:" + forceDownloadBean.getMsg());
} }
@@ -404,8 +413,7 @@ public class InitJpushServer extends Service {
return; return;
} }
getSelfDownload(data); getSelfDownload(data);
List<String> list = SaveListUtils.getList(); List<String> list = new ArrayList<>();
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
ForceDownloadData forceDownloadData = data.get(i); ForceDownloadData forceDownloadData = data.get(i);
String app_package = forceDownloadData.getApp_package(); String app_package = forceDownloadData.getApp_package();
@@ -413,13 +421,8 @@ public class InitJpushServer extends Service {
if (data.get(i).getApp_package().equals("com.jiaoguanyi.appstore")) { if (data.get(i).getApp_package().equals("com.jiaoguanyi.appstore")) {
continue;//为自身的跳过下载 continue;//为自身的跳过下载
} }
LogUtils.e(list);
if (list != null) {
if (!list.contains(app_package)) { if (!list.contains(app_package)) {
SaveListUtils.addToList(app_package); list.add(app_package);
}
} else {
SaveListUtils.addToList(app_package);
} }
if (!AppUtils.isAppInstalled(app_package)) { if (!AppUtils.isAppInstalled(app_package)) {
if (!SaveListUtils.isDownLoading(app_package)) { if (!SaveListUtils.isDownLoading(app_package)) {
@@ -432,6 +435,8 @@ public class InitJpushServer extends Service {
} }
} }
} }
SaveListUtils.setList(list);
SaveListUtils.sendForceAPP(this);
} }
private void getSelfDownload(List<ForceDownloadData> forceDownloadDataList) { private void getSelfDownload(List<ForceDownloadData> forceDownloadDataList) {
@@ -947,4 +952,10 @@ public class InitJpushServer extends Service {
} }
@Override
public void onDestroy() {
super.onDestroy();
Log.e("fht", "InitJpushServer onDestroy");
}
} }

View File

@@ -52,7 +52,7 @@ public class InstallResultReceiver extends BroadcastReceiver {
// Log.e("fht", SESSION_ID); // Log.e("fht", SESSION_ID);
// Log.e("fht", LEGACY_STATUS); // Log.e("fht", LEGACY_STATUS);
// Log.e("fht", STATUS_MESSAGE); // Log.e("fht", STATUS_MESSAGE);
if (STATUS_MESSAGE.equals("INSTALL_SUCCEEDED")) { if (STATUS_MESSAGE != null && STATUS_MESSAGE.equals("INSTALL_SUCCEEDED")) {
ToastUtil.show(PACKAGE_NAME + "安装成功"); ToastUtil.show(PACKAGE_NAME + "安装成功");
} }
} }

View File

@@ -8,6 +8,7 @@ import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Binder; import android.os.Binder;
import android.os.Build; import android.os.Build;
import android.provider.Settings;
import android.support.v4.content.FileProvider; import android.support.v4.content.FileProvider;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@@ -42,17 +43,21 @@ import rx.schedulers.Schedulers;
public class SaveListUtils { public class SaveListUtils {
private static List<String> downLoadList = new ArrayList<>(); private static List<String> downLoadList = new ArrayList<>();
private static List<String> forceList = new ArrayList<>();
public static List<String> getList() { public static List<String> getList() {
String data = SPStaticUtils.getString(CommonDatas.FORCE_INSTALL); String data = SPStaticUtils.getString(CommonDatas.FORCE_INSTALL);
Log.e("mjshenglistdata", data); Log.e("mjshenglistdata", data);
Gson gson = new Gson(); Gson gson = new Gson();
Type listType = new TypeToken<List<String>>() { Type listType = new TypeToken<List<String>>() {
}.getType(); }.getType();
List<String> list = gson.fromJson(data, listType); List<String> list = gson.fromJson(data, listType);
// Log.e("mjshenglist1", list.toString()); // Log.e("mjshenglist1", list.toString());
if (list != null && list.size() > 0) {
Log.e("fht", "getList:" + list.toString());
} else {
list = new ArrayList<>();
}
return list; return list;
} }
@@ -69,6 +74,54 @@ public class SaveListUtils {
String gsonData = gson.toJson(list); String gsonData = gson.toJson(list);
SPStaticUtils.put(CommonDatas.FORCE_INSTALL, gsonData); SPStaticUtils.put(CommonDatas.FORCE_INSTALL, gsonData);
} }
Log.e("fht", "addToList:" + list.toString());
}
public static void setList(List<String> strings) {
forceList.clear();
forceList = strings;
Gson gson = new Gson();
String gsonData = gson.toJson(forceList);
SPStaticUtils.put(CommonDatas.FORCE_INSTALL, gsonData);
Log.e("fht", "setList:" + forceList.toString());
}
public static void addList(String s) {
if (!forceList.contains(s)) {
forceList.add(s);
}
Log.e("fht", "addList:" + forceList.toString());
}
public static void setList() {
Gson gson = new Gson();
String gsonData = gson.toJson(forceList);
SPStaticUtils.put(CommonDatas.FORCE_INSTALL, gsonData);
}
public static List<String> getlist() {
return forceList;
}
public static void sendForceAPP(Context context) {
String txt = "";
for (String s : forceList) {
txt += s + ",";
}
if (txt.length() > 0) {
txt = txt.substring(0, txt.length() - 1);
boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_force_app", txt);
Log.e("fht", "qch_force_app:" + qch_force_app + ":" + txt);
} else {
boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_force_app", "invalid");
Log.e("fht", "qch_force_app:" + qch_force_app + ":" + txt);
}
setList();
} }
public static List<String> getDownLoadList() { public static List<String> getDownLoadList() {

View File

@@ -2,8 +2,10 @@ package com.mjsheng.myappstore.utils;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import com.mjsheng.myappstore.BuildConfig; import com.mjsheng.myappstore.BuildConfig;
@@ -14,13 +16,15 @@ import com.mjsheng.myappstore.BuildConfig;
*/ */
public class ToastUtil { public class ToastUtil {
static Handler mainHandler = new Handler(Looper.getMainLooper()); private static Handler mainHandler = new Handler(Looper.getMainLooper());
static Toast toast; private static Toast toast;
private static Context mContext;
@SuppressLint("ShowToast") @SuppressLint("ShowToast")
public static void init(Context context) { public static void init(Context context) {
toast = Toast.makeText(context, "", Toast.LENGTH_SHORT); mContext = context;
debugToast = Toast.makeText(context, "", Toast.LENGTH_SHORT); toast = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
debugToast = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
} }
@@ -28,12 +32,38 @@ public class ToastUtil {
mainHandler.post(new Runnable() { mainHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
showToast(mContext, msg, Toast.LENGTH_LONG);
Log.e("fht", "LENGTH_LONG");
} else {
if (toast != null) { if (toast != null) {
toast.setText(msg); toast.setText(msg);
toast.show(); toast.show();
} }
} }
}
}); });
}
private static Toast mToast = null;
//android 8.0以后限制
//https://www.jianshu.com/p/d9813ad03d59
//https://www.jianshu.com/p/050ce052b873
public static void showToast(Context context, String text, int duration) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.P) {
Toast.makeText(context, text, duration).show();
} else {
if (mToast == null) {
mToast = Toast.makeText(context, text, duration);
} else {
mToast.setText(text);
mToast.setDuration(duration);
}
mToast.show();
}
} }
// public static void showInCenter(String msg) { // public static void showInCenter(String msg) {