是否有可能得到启动的快捷键布局和在我们自己的小部件使用它呢? [英] Is it possible to get the shortcut layout of Launcher and use it in our own widget?

查看:135
本文介绍了是否有可能得到启动的快捷键布局和在我们自己的小部件使用它呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,Dropbox的快捷方式,窗口小部件一样对指定的文件夹中appearience是快捷键的布局无论哪个发射我们使用一致的:

I've noticed that the appearience of Dropbox shortcut-like widget to specified folder is consistent with shortcut layout no matter which launcher we use:


所以我想做出这样的行为方式,看起来像快捷方式,并与用户的启动相一致的部件。

So I want to make such a widget that behaves and looks like shortcut and is consistent with user's launcher.

时有可能得到启动的快捷键布局和在我们自己的小部件使用它?

Is it possible to get the shortcut layout of Launcher and use it in our own widget?

推荐答案

除了 AppWidgets ,机器人也有经常在窗口小部件分组启动快捷方式的概念 标签。这Dropbox的文件夹是一个启动程序快捷方式。

Aside from AppWidgets, Android also has a concept of Launcher Shortcuts that are often grouped under the "Widget" label. That Dropbox folder is a Launcher Shortcut.

快捷方式很简单,所有的数据(图标,标签,意图)是静态的,在创建时确定的。它们不能被动态更新,或调整,或滚动。但它们匹配的发射器造型(可以放在里面的文件夹或码头),并使用更少的资源比 AppWidget 秒。

Shortcuts are simple, all data (icon, label, intent) is static, determined at creation time. They can't be updated dynamically, or resized, or scroll. But they match the launcher styling (and can be placed inside folders or the dock) and use less resources than AppWidgets.

可悲的是他们不良记录。你可以找到在ApiDemos / src目录/ COM /例子/安卓/的API /应用/ LauncherShortcuts.java(<一个样本href=\"https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.java\" rel=\"nofollow\">https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.java ),并在https://developer.android.com/reference/android/content/Intent.html#EXTRA_SHORTCUT_ICON (所有EXTRA_SHORTCUT _...项目)。

Sadly they're poorly documented. You can find a sample in the ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.java ( https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.java ) and references to them at https://developer.android.com/reference/android/content/Intent.html#EXTRA_SHORTCUT_ICON (all the EXTRA_SHORTCUT_... items).

您需要一个活动 AndroidManifest 意图过滤器来处理创建快捷方式:

You need an Activity and AndroidManifest intent-filter to handle creating the shortcuts:

的Andr​​oidManifest.xml

<activity
    android:name=".LauncherShortcutActivity" >
    <intent-filter>
        <action android:name="android.intent.action.CREATE_SHORTCUT" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

此活动将被发射被称为与 startActivityForResult ,您可以present接口(例如让用户选择一个文件夹的快捷方式应该是)但最终还是要回到一个图标,标签和意图发射。

This activity will be called by the launcher with startActivityForResult, you may present an interface (for example let the user select a folder the shortcut should be to) but ultimately must return an icon, label and intent to the launcher.

void setResult(CharSequence title, int iconResourceId, Intent targetIntent) {
    Intent data = new Intent();
    data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, iconResourceId));
    data.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);
    setResult(Activity.RESULT_OK, data);
    finish();
}

在这种情况下,该图标被指定为我的应用程序的资源。另外该图标可以是位图(例如联系人照片):

In this case, the icon is specified as a resource of my app. Alternatively the icon can be a bitmap (for example a contact photo):

    data.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);

这篇关于是否有可能得到启动的快捷键布局和在我们自己的小部件使用它呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆