标签: android-shortcutmanager

更新android SDK:安装最新平台实现新的API,如"ShortcutManager"

在这里,我正在为Android nougat 应用程序快捷方式中的 Android快捷方式执行演示

我使用以下代码来创建应用程序快捷方式

ShortcutManager shortcutManager;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
    shortcutManager = getSystemService(ShortcutManager.class);
    ShortcutInfo shortcut;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
        shortcut = new ShortcutInfo.Builder(this, "second_shortcut")
                .setShortLabel(getString(R.string.str_shortcut_two))
                .setLongLabel(getString(R.string.str_shortcut_two_desc))
                .setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                .setIntent(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://www.google.co.in")))
                .build();
        shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
    }
}
Run Code Online (Sandbox Code Playgroud)

但在这里我得到编译时错误 cannot resolve symbol ShortcutManager.

这是我的build.gradle档案

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        ...
        minSdkVersion 9
        targetSdkVersion 24
        ...
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies { …
Run Code Online (Sandbox Code Playgroud)

android android-7.0-nougat android-shortcutmanager

10
推荐指数
1
解决办法
520
查看次数

Android 快速快捷方式 [在 Shortcuts.xml 中传递额外意图(或一些数据)]

在使用 Shortcut.xml 实现静态快捷方式时,我想根据我的意图传递一些捆绑包附加内容。

启动应用程序后,需要传递额外的内容来决定目标类中的一些功能。

是否可以访问额外内容?如何以及在哪里访问它?

任何线索将不胜感激

android-shortcut android-shortcutmanager

5
推荐指数
2
解决办法
2207
查看次数

在 android O 中固定快捷方式时接收回调/广播

我正在尝试一次添加两个快捷方式。但是 android 8 显示一个对话框并请求用户允许添加快捷方式,并且其中两个对话框无法同时显示。

因此,我需要一种方法,可以在第一个对话框关闭时获得回调或广播,以便之后添加另一个快捷方式。目前,当用户允许请求时,我能够获得广播。但我想知道用户是否取消了对话框。

我正在使用以下代码:

@RequiresApi(api = Build.VERSION_CODES.O)
private static void addShortcutNew(Context context, Intent shortcutIntent, String label, int iconRes, int color) {
    ShortcutManager manager = context.getSystemService(ShortcutManager.class);
    if (manager != null && manager.isRequestPinShortcutSupported()) {

        ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, label)
                .setIcon(prepareIcon(context, iconRes, color)) // prepareIcon is my own method which returns an Icon.
                .setIntent(shortcutIntent)
                .setShortLabel(label)
                .setLongLabel(label)
                .build();

        context.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Toast.makeText(context, "Broadcast", Toast.LENGTH_SHORT).show();
                context.unregisterReceiver(this);
            }
        }, new IntentFilter("test_action"));

        Intent …
Run Code Online (Sandbox Code Playgroud)

java android android-broadcast android-shortcut android-shortcutmanager

5
推荐指数
0
解决办法
1240
查看次数

三星 A10 android 11 如何从我的应用程序以编程方式创建其他应用程序固定快捷方式

三星 A10 android 11 更新,Galaxy S9 和 Galaxy S10 在这些设备上进行了测试,但无法正常工作

此代码仅适用于 Android Oreo 及以上版本

这是我用于以编程方式在 android 中创建快捷方式的代码。在所有其他设备中,它工作得很好,但在这个特定设备上,它创建了简短的内容,但生成了我自己的应用程序快捷方式,但不符合要求。

val shortcutIntent = finalPackageName?.let {
            context?.packageManager!!.getLaunchIntentForPackage(
                it
            )
        }
        val shortcutManager: ShortcutManager? = context?.getSystemService(ShortcutManager::class.java)
        if (shortcutManager != null) {
            if (shortcutManager.isRequestPinShortcutSupported) {
                val shortcut = ShortcutInfo.Builder(context, "unique_id")
                    .setShortLabel(finalAppName)
                    .setLongLabel("Open the Android Docu")
                    .setIcon(Icon.createWithBitmap(finalBitmap))
                    .setIntent(shortcutIntent!!)
                    .build()

                ((activity) as MainActivity).registerReceiver(object : BroadcastReceiver() {
                    override fun onReceive(context: Context, intent: Intent) {
                        findNavController().navigate(R.id.resultFragment)
                        context.unregisterReceiver(this)
                    }
                }, IntentFilter("test_action"))

                val intent = Intent("test_action")
                val pendingIntent = PendingIntent.getBroadcast(context, 123, intent, …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-shortcutmanager android-11

4
推荐指数
1
解决办法
1181
查看次数