|
|
@@ -5,14 +5,17 @@ import android.app.Dialog;
|
|
|
import android.app.PendingIntent;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.ComponentName;
|
|
|
+import android.content.ContentResolver;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
import android.content.pm.PackageInfo;
|
|
|
import android.content.pm.PackageManager;
|
|
|
+import android.content.pm.ProviderInfo;
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
import android.content.pm.ShortcutInfo;
|
|
|
import android.content.pm.ShortcutManager;
|
|
|
+import android.database.Cursor;
|
|
|
import android.graphics.BitmapFactory;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
import android.graphics.drawable.Icon;
|
|
|
@@ -22,6 +25,7 @@ import android.provider.AlarmClock;
|
|
|
import android.provider.Settings;
|
|
|
import android.text.TextUtils;
|
|
|
import android.text.format.Formatter;
|
|
|
+import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.View;
|
|
|
import android.widget.TextView;
|
|
|
@@ -69,6 +73,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
import io.reactivex.Observable;
|
|
|
@@ -881,7 +886,8 @@ public class SysAppUtil {
|
|
|
//展示提示框
|
|
|
private static void showShortcutTip(Activity activity) {
|
|
|
ViewUtil.showMsgDialog(activity, new DialogConfig().setTitle("已尝试添加有范商城到桌面").setMsg("若添加失败,请前往系统设置为小绵羊打开\"创建桌面快捷方式\"的权限")
|
|
|
- .setBtnLeftText("取消").setBtnRightText("前往设置").setBtnRightOnClickListener(view -> {
|
|
|
+ .setBtnLeftText("重新添加").setBtnLeftOnClickListener(view -> CommonUtil.getInstance().addYouFanLauncher())
|
|
|
+ .setBtnRightText("前往设置").setBtnRightOnClickListener(view -> {
|
|
|
try {
|
|
|
startAppSettings(activity);
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
@@ -893,7 +899,7 @@ public class SysAppUtil {
|
|
|
if(TestUtil.isDev())
|
|
|
G.showToast(e);
|
|
|
}
|
|
|
- }));
|
|
|
+ }).setBtnRightNotDissDialog(true));
|
|
|
}
|
|
|
|
|
|
class CallBackReceiver extends BroadcastReceiver {
|
|
|
@@ -953,4 +959,61 @@ public class SysAppUtil {
|
|
|
intent.setClass(activity, yfCls);
|
|
|
return intent;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //是否有快捷方式的权限
|
|
|
+ public static boolean hasShortcut(Context context, String appName) {
|
|
|
+ LogUtil.println("hasShortcut appName = " + appName);
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ String authority = getAuthorityFromPermission(context);
|
|
|
+ if (authority == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ long end = System.currentTimeMillis() - start;
|
|
|
+ Log.e("Finals", end + " eee");
|
|
|
+ String url = "content://" + authority + "/favorites?notify=true";
|
|
|
+ Cursor cursor = null;
|
|
|
+ try {
|
|
|
+ Uri CONTENT_URI = Uri.parse(url);
|
|
|
+ ContentResolver contentResolver = context.getContentResolver();
|
|
|
+ if(contentResolver != null) {
|
|
|
+ cursor = contentResolver.query(CONTENT_URI, null, " title= ? ", new String[]{appName}, null);
|
|
|
+ if (cursor != null && cursor.moveToNext()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception ignore) {
|
|
|
+ } finally {
|
|
|
+ if(cursor != null){
|
|
|
+ cursor.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getAuthorityFromPermission(Context context) {
|
|
|
+ // 先得到默认的Launcher
|
|
|
+ Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
|
+ intent.addCategory(Intent.CATEGORY_HOME);
|
|
|
+ PackageManager mPackageManager = context.getPackageManager();
|
|
|
+ ResolveInfo resolveInfo = mPackageManager.resolveActivity(intent, 0);
|
|
|
+ if (resolveInfo == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<ProviderInfo> info = mPackageManager.queryContentProviders(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.applicationInfo.uid, PackageManager.GET_PROVIDERS);
|
|
|
+ if (info != null) {
|
|
|
+ for (int j = 0; j < info.size(); j++) {
|
|
|
+ ProviderInfo provider = info.get(j);
|
|
|
+ if (provider.readPermission == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (Pattern.matches(".*launcher.*READ_SETTINGS", provider.readPermission)) {
|
|
|
+ return provider.authority;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|