|
|
@@ -23,7 +23,9 @@ import android.graphics.drawable.Icon;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
import android.provider.AlarmClock;
|
|
|
-import android.provider.Settings;
|
|
|
+import android.support.v4.content.pm.ShortcutInfoCompat;
|
|
|
+import android.support.v4.content.pm.ShortcutManagerCompat;
|
|
|
+import android.support.v4.graphics.drawable.IconCompat;
|
|
|
import android.text.TextUtils;
|
|
|
import android.text.format.Formatter;
|
|
|
import android.util.Log;
|
|
|
@@ -31,6 +33,7 @@ import android.view.Gravity;
|
|
|
import android.view.View;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.allen.android.lib.rom.HuaweiUtils;
|
|
|
import com.allen.android.lib.rom.MeizuUtils;
|
|
|
import com.allen.android.lib.rom.MiuiUtils;
|
|
|
@@ -47,7 +50,6 @@ import com.sheep.gamegroup.model.entity.DialogConfig;
|
|
|
import com.sheep.gamegroup.model.entity.Version;
|
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.gamegroup.view.activity.ActWebX5YF;
|
|
|
-import com.sheep.jiuyan.samllsheep.BuildConfig;
|
|
|
import com.sheep.jiuyan.samllsheep.Config;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
@@ -838,11 +840,29 @@ public class SysAppUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //使用自定义图标创建快捷方式
|
|
|
+ public static boolean installShortCut(Context context) {
|
|
|
+ if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
|
|
|
+ IconCompat iconCompat = IconCompat.createWithResource(context, R.drawable.icon_yf);
|
|
|
+ Intent intent = getShortCutIntent(context);
|
|
|
+ intent.setAction(Intent.ACTION_MAIN);
|
|
|
+ String name = Config.YF_SHOP_NAME;//context.getString(R.string.app_name_yf);
|
|
|
+ ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(context, "9527").setShortLabel(name).setLongLabel(name).setIntent(intent).setIcon(iconCompat).build();
|
|
|
+ Intent pinnedShortcutCallbackIntent = ShortcutManagerCompat.createShortcutResultIntent(context, pinShortcutInfo);
|
|
|
|
|
|
+ PendingIntent successCallback = PendingIntent.getBroadcast(context, 0, pinnedShortcutCallbackIntent, 0);
|
|
|
+
|
|
|
+ ShortcutManagerCompat.requestPinShortcut(context, pinShortcutInfo, successCallback.getIntentSender());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
//添加有范商城快捷入口
|
|
|
public static void addShortcutTest(Activity activity) {
|
|
|
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
|
|
|
+ if(installShortCut(activity)){
|
|
|
+
|
|
|
+ } else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
|
|
|
SysAppUtil.addShortcutTest8(activity);
|
|
|
} else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1){
|
|
|
SysAppUtil.addShortcutTest7(activity);
|
|
|
@@ -868,7 +888,7 @@ public class SysAppUtil {
|
|
|
|
|
|
ShortcutInfo info = new ShortcutInfo.Builder(activity, String.valueOf(mShortcutName.hashCode()))
|
|
|
.setIcon(Icon.createWithResource(activity, R.drawable.icon_yf))
|
|
|
- .setShortLabel(mShortcutName.substring(0,2))
|
|
|
+ .setShortLabel(mShortcutName)
|
|
|
.setLongLabel(mShortcutName)
|
|
|
.setIntent(shortcutInfoIntent)
|
|
|
.build();
|
|
|
@@ -928,7 +948,7 @@ public class SysAppUtil {
|
|
|
//设置ID
|
|
|
ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(activity, String.valueOf(mShortcutName.hashCode()))
|
|
|
//设置短标题
|
|
|
- .setShortLabel(mShortcutName.substring(0,2))
|
|
|
+ .setShortLabel(mShortcutName)
|
|
|
//设置长标题
|
|
|
.setLongLabel(mShortcutName)
|
|
|
//设置icon
|
|
|
@@ -959,11 +979,11 @@ public class SysAppUtil {
|
|
|
// ShortcutSuperUtils.addShortcutByPackageName(this, this.getPackageName());
|
|
|
}
|
|
|
public static final Class<? extends Activity> yfCls = ActWebX5YF.class;
|
|
|
- private static Intent getShortCutIntent(Activity activity) {
|
|
|
+ private static Intent getShortCutIntent(Context context) {
|
|
|
// 使用MAIN,可以避免部分手机(比如华为、HTC部分机型)删除应用时无法删除快捷方式的问题
|
|
|
Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
|
|
- intent.setClass(activity, yfCls);
|
|
|
+ intent.setClass(context, yfCls);
|
|
|
return intent;
|
|
|
}
|
|
|
|
|
|
@@ -981,6 +1001,10 @@ public class SysAppUtil {
|
|
|
long end = System.currentTimeMillis() - start;
|
|
|
Log.e("Finals", end + " eee");
|
|
|
String url = "content://" + authority + "/favorites?notify=true";
|
|
|
+ return hasShortcut(context, appName, url);
|
|
|
+ }
|
|
|
+ //是否有快捷方式的权限
|
|
|
+ public static boolean hasShortcut(Context context, String appName, String url) {
|
|
|
Cursor cursor = null;
|
|
|
try {
|
|
|
Uri CONTENT_URI = Uri.parse(url);
|
|
|
@@ -1011,12 +1035,14 @@ public class SysAppUtil {
|
|
|
}
|
|
|
List<ProviderInfo> info = mPackageManager.queryContentProviders(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.applicationInfo.uid, PackageManager.GET_PROVIDERS);
|
|
|
if (info != null) {
|
|
|
+ LogUtil.println("getAuthorityFromPermission", JSON.toJSONString(info));
|
|
|
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)) {
|
|
|
+ LogUtil.println("getAuthorityFromPermission", j, provider.authority);
|
|
|
return provider.authority;
|
|
|
}
|
|
|
}
|