Daedalus.java 文件源码

java
阅读 31 收藏 0 点赞 0 评论 0

项目:Daedalus 作者:
public static void updateShortcut(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        Log.d("Daedalus", "Updating shortcut");
        //shortcut!
        String notice = context.getString(R.string.button_text_activate);
        boolean activate = true;
        ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (DaedalusVpnService.class.getName().equals(service.service.getClassName())) {
                notice = context.getString(R.string.button_text_deactivate);
                activate = false;
            }
        }
        ShortcutInfo info = new ShortcutInfo.Builder(context, Daedalus.SHORTCUT_ID_ACTIVATE)
                .setLongLabel(notice)
                .setShortLabel(notice)
                .setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher))
                .setIntent(new Intent(context, MainActivity.class).setAction(Intent.ACTION_VIEW)
                        .putExtra(MainActivity.LAUNCH_ACTION, activate ? MainActivity.LAUNCH_ACTION_ACTIVATE : MainActivity.LAUNCH_ACTION_DEACTIVATE))
                .build();

        ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(SHORTCUT_SERVICE);
        shortcutManager.addDynamicShortcuts(Collections.singletonList(info));
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号