Bläddra i källkod

8.0 安装的BUG

xiongxiaohe 8 år sedan
förälder
incheckning
78d25a1ea6

+ 2 - 0
.idea/modules.xml

@@ -5,6 +5,8 @@
       <module fileurl="file://$PROJECT_DIR$/SamllSheepPlugin.iml" filepath="$PROJECT_DIR$/SamllSheepPlugin.iml" />
       <module fileurl="file://D:/Dlg/AndroidStudioProjects/small_sheep_android/SamllSheepPlugin.iml" filepath="D:/Dlg/AndroidStudioProjects/small_sheep_android/SamllSheepPlugin.iml" />
       <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
+      <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
+      <module fileurl="file://$PROJECT_DIR$/small_sheep_android.iml" filepath="$PROJECT_DIR$/small_sheep_android.iml" />
       <module fileurl="file://$PROJECT_DIR$/small_sheep_android.iml" filepath="$PROJECT_DIR$/small_sheep_android.iml" />
     </modules>
   </component>

+ 5 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/floatwindow/FloatService.java

@@ -178,7 +178,11 @@ public class FloatService extends Service implements View.OnClickListener {
                 pkg = TopService.PackName;
             }
             if (TextUtils.isEmpty(pkg)) {
-                Toast.makeText(this, "自动截屏失败,请手动截图从任务攻略界面上传", Toast.LENGTH_LONG).show();
+                Toast.makeText(this, "自动截屏失败,已为你跳转到手动截图界面上传", Toast.LENGTH_LONG).show();
+//                intent = new Intent(FloatService.this, ShotScreenActivity.class);
+//                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+//                intent.putExtra("pkg", pkg);
+//                startActivity(intent);
                 return;
             }
             intent = new Intent(FloatService.this, ShotScreenActivity.class);

+ 51 - 6
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/PackageUtil.java

@@ -1,5 +1,6 @@
 package com.sheep.jiuyan.samllsheep.utils;
 
+import android.Manifest;
 import android.app.ActivityManager;
 import android.app.usage.UsageEvents;
 import android.app.usage.UsageStatsManager;
@@ -12,7 +13,11 @@ import android.content.pm.ResolveInfo;
 import android.net.Uri;
 import android.os.Build;
 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 java.io.File;
@@ -59,7 +64,13 @@ public class PackageUtil {
     public static boolean isAppInstalled(Context context, String packagename) {
         PackageInfo packageInfo;
         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) {
             packageInfo = null;
             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);
         Intent intent = new Intent(Intent.ACTION_VIEW);
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -90,8 +98,45 @@ public class PackageUtil {
             intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
         }
         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