|
@@ -1,5 +1,6 @@
|
|
|
package com.sheep.jiuyan.samllsheep.utils;
|
|
package com.sheep.jiuyan.samllsheep.utils;
|
|
|
|
|
|
|
|
|
|
+import android.Manifest;
|
|
|
import android.app.ActivityManager;
|
|
import android.app.ActivityManager;
|
|
|
import android.app.usage.UsageEvents;
|
|
import android.app.usage.UsageEvents;
|
|
|
import android.app.usage.UsageStatsManager;
|
|
import android.app.usage.UsageStatsManager;
|
|
@@ -12,7 +13,11 @@ import android.content.pm.ResolveInfo;
|
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
|
import android.support.v4.content.FileProvider;
|
|
import android.support.v4.content.FileProvider;
|
|
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
+import com.mylhyl.acp.Acp;
|
|
|
|
|
+import com.mylhyl.acp.AcpListener;
|
|
|
|
|
+import com.mylhyl.acp.AcpOptions;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
@@ -59,7 +64,13 @@ public class PackageUtil {
|
|
|
public static boolean isAppInstalled(Context context, String packagename) {
|
|
public static boolean isAppInstalled(Context context, String packagename) {
|
|
|
PackageInfo packageInfo;
|
|
PackageInfo packageInfo;
|
|
|
try {
|
|
try {
|
|
|
- packageInfo = context.getPackageManager().getPackageInfo(packagename, 0);
|
|
|
|
|
|
|
+ PackageManager manager=context.getPackageManager();
|
|
|
|
|
+ if(manager==null){
|
|
|
|
|
+ return false;
|
|
|
|
|
+
|
|
|
|
|
+ }else {
|
|
|
|
|
+ packageInfo = manager.getPackageInfo(packagename, 0);
|
|
|
|
|
+ }
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
|
packageInfo = null;
|
|
packageInfo = null;
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -74,11 +85,8 @@ public class PackageUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- /*
|
|
|
|
|
- * 安装
|
|
|
|
|
- * install app
|
|
|
|
|
- */
|
|
|
|
|
- public static void installApk(Context context, String path) {
|
|
|
|
|
|
|
+ public static void install(Context context, String path){
|
|
|
|
|
+
|
|
|
File file = new File(path);
|
|
File file = new File(path);
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
@@ -90,8 +98,45 @@ public class PackageUtil {
|
|
|
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
|
|
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
|
|
|
}
|
|
}
|
|
|
context.startActivity(intent);
|
|
context.startActivity(intent);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 安装
|
|
|
|
|
+ * install app
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void installApk(final Context context,final String path) {
|
|
|
|
|
+
|
|
|
|
|
+ if (Build.VERSION.SDK_INT >= 26) {//判读版本是否在8.0以上
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Acp.getInstance(context).request(new AcpOptions.Builder()
|
|
|
|
|
+ .setPermissions(Manifest.permission.REQUEST_INSTALL_PACKAGES
|
|
|
|
|
+ )
|
|
|
|
|
+ .build(),
|
|
|
|
|
+ new AcpListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onGranted() {
|
|
|
|
|
+ install(context, path);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDenied(List<String> permissions) {
|
|
|
|
|
+ Toast.makeText(context, "亲!权限拒绝将无法安装游戏,进行赚钱...", Toast.LENGTH_LONG).show();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ }else{
|
|
|
|
|
+
|
|
|
|
|
+ install(context, path);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
/*
|
|
/*
|
|
|
* 启动
|
|
* 启动
|
|
|
* install app
|
|
* install app
|