如何把这段java改造成AutoJS,实现打开桌面快捷方式的功能?

现在当然是不能,希望有打开快捷方式的功能。比如打开微信发送到桌面的联系人快捷方式。
目前只能回到桌面点击图标了。如果能直接打开桌面快捷方式,会方便很多。

下面是用java实现的,调用安卓快捷方式的代码,可以有点启发

//获取到所有快捷方式 
Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
List < ResolveInfo > shortcuts = getPackageManager().queryIntentActivities(shortcutsIntent, 0);
for (ResolveInfo resolveInfo : shortcuts)
{
    String name = resolveInfo.activityInfo.applicationInfo.packageName;
    String activityName = resolveInfo.activityInfo.name;
    String label = resolveInfo.activityInfo.applicationInfo.name;
    int flags = resolveInfo.activityInfo.flags;
    Log.i(TAG, "updatePackages: " + name + " " + activityName + " " + flags + " " + label);
}
//启动方式如下 
ActivityInfo ai = shortcuts.get(7).activityInfo;
String pkgName = ai.applicationInfo.packageName;
String activityName = ai.name; int flag = ai.flags;
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(pkgName, activityName);
intent.addFlags(flag); startActivity(intent);
//获取对应icon方法如下 
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(pkgName, activityName);
intent.addFlags(flag);
try {
    Drawable dw = pm.getActivityIcon(intent);
} catch (PackageManager.NameNotFoundException e)
{
    e.printStackTrace();
}
最后由 basking 编辑

运用微信url协议 直接跳转到指定联系人

@吾小牛 很新奇的方法,我搜了一下是
weixin://开头的链接吧? 打开指定联系人可能需要token,而可惜这个token是会变化的。还请指点一二。

另外,如何launch小米双开的APP呢?

/**

  • 微信跳转相关工具类

  • Created by Spencer on 7/18/16.
    */
    public final class WeChatUtils {

    /**

    • 扫一扫
      */
      public static final String SCAN = "weixin://dl/scan";

    /**

    • 反馈
      */
      public static final String FEEDBACK = "weixin://dl/feedback";

    /**

    • 朋友圈
      */
      public static final String MOMENTS = "weixin://dl/moments";

    /**

    • 设置
      */
      public static final String SETTINGS = "weixin://dl/settings";

    /**

    • 消息通知设置
      */
      public static final String NOTIFICATIONS = "weixin://dl/notifications";

    /**

    • 聊天设置
      */
      public static final String CHAT = "weixin://dl/chat";

    /**

    • 通用设置
      */
      public static final String GENERAL = "weixin://dl/general";

    /**

    • 公众号
      */
      public static final String OFFICIALACCOUNTS = "weixin://dl/officialaccounts";

    /**

    • 游戏
      */
      public static final String GAMES = "weixin://dl/games";

    /**

    • 帮助
      */
      public static final String HELP = "weixin://dl/help";

    /**

    • 个人信息
      */
      public static final String PROFILE = "weixin://dl/profile";

    /**

    • 功能插件
      */
      public static final String FEATURES = "weixin://dl/features";

    /**

    • 修改用户名
      */
      public static final String SET_NAME = "weixin://dl/setname";

    /**

    • 我的二维码
      */
      public static final String MY_QRCODE = "weixin://dl/myQRcode";

    /**

    • 我的地址
      */
      public static final String MY_ADDRESS = "weixin://dl/myaddress";

    /**

    • 相册
      */
      public static final String POSTS = "weixin://dl/posts";

    /**

    • 收藏
      */
      public static final String FAVORITES = "weixin://dl/favorites";

    /**

    • 优惠券
      */
      public static final String CARD = "weixin://dl/card";

    private WeChatUtils() {
    // no instance
    }

    /**

    • 跳转到微信某页面

    • @param context
      */
      public static void jump(Context context, String wechatScheme) {
      if (context == null) {
      throw new NullPointerException("context is null.");
      } else if (TextUtils.isEmpty(wechatScheme)) {
      throw new NullPointerException("wechat scheme is empty or null");
      }

      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setData(Uri.parse(wechatScheme));
      intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
      context.startActivity(intent);
      }

    /**

    • 打开微信
      */
      public static void open(Context context) {
      Intent intent = new Intent();
      ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
      intent.setAction(Intent.ACTION_MAIN);
      intent.addCategory(Intent.CATEGORY_LAUNCHER);
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setComponent(cmp);
      context.startActivity(intent);
      }
      }

下面是用java实现的,调用安卓快捷方式的代码,可以有点启发

//获取到所有快捷方式 
Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
List < ResolveInfo > shortcuts = getPackageManager().queryIntentActivities(shortcutsIntent, 0);
for (ResolveInfo resolveInfo : shortcuts)
{
    String name = resolveInfo.activityInfo.applicationInfo.packageName;
    String activityName = resolveInfo.activityInfo.name;
    String label = resolveInfo.activityInfo.applicationInfo.name;
    int flags = resolveInfo.activityInfo.flags;
    Log.i(TAG, "updatePackages: " + name + " " + activityName + " " + flags + " " + label);
}
//启动方式如下 
ActivityInfo ai = shortcuts.get(7).activityInfo;
String pkgName = ai.applicationInfo.packageName;
String activityName = ai.name; int flag = ai.flags;
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(pkgName, activityName);
intent.addFlags(flag); startActivity(intent);
//获取对应icon方法如下 
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(pkgName, activityName);
intent.addFlags(flag);
try {
    Drawable dw = pm.getActivityIcon(intent);
} catch (PackageManager.NameNotFoundException e)
{
    e.printStackTrace();
}
  • 6
    帖子
  • 618
    浏览

与 Auto.js 的连接断开,我们正在尝试重连,请耐心等待