创建发送广播的快捷方式 [英] Create a shortcut that sends a broadcast

查看:107
本文介绍了创建发送广播的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序创建主屏幕快捷方式的选项。

我创建这样的快捷方式:

 意向意图=新的Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
新意图(ShortcutCreateActivity.this,ShortcutCreateActivity.class).putExtra(EXTRA_PROFILE_ID,提供ProfileID).putExtra(EXTRA_PROFILE_ACTION,项目));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,profileTitle);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,位图);

这按预期工作......当用户点击该快捷方式,ShortcutCreateActivity启动,我做什么,我需要的。

不过!我想避免需要打开活动。相反,我想创建一个发送一个广播的快捷方式。

我试图取代意图:

  intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
    新意图(INTENT_ACTION_THAT_I_WANT)

但是,当我单击该快捷方式,则显示应用程序未安装敬酒。

是否有可能创建一个发送一个广播,而不是发动活动的主屏幕快捷方式?

(启动活动,并迅速完​​成它不是一个选项)。

感谢您!


解决方案

  

是否有可能创建一个发送一个广播,而不是发动活动的主屏幕快捷方式?


严格说来,没有。

不过,你可以把它指向设置了 Theme.NoDisplay 的活动,凡在活动的的onCreate()您发送广播,并呼吁完成()无需调用的setContentView()。从外观上看,这是从具有快捷方式发送广播本身没有区别。

My application has the option to create home screen shortcuts.

I create the shortcut like this:

Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new Intent(ShortcutCreateActivity.this, ShortcutCreateActivity.class).putExtra(EXTRA_PROFILE_ID, profileId).putExtra(EXTRA_PROFILE_ACTION, item));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, profileTitle);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);

This works as expected... when the user clicks the shortcut, the ShortcutCreateActivity is launched and I do what I need.

However! I would like to avoid the need to open an activity. Instead, I want to create a shortcut that sends a broadcast.

I tried replacing the intent with:

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
    new Intent(INTENT_ACTION_THAT_I_WANT)

But when I click the shortcut, it shows a Toast "App isn't installed".

Is it possible to create a home screen shortcut that sends a broadcast instead of launching an Activity?

(Starting the activity and quickly finishing it is not an option).

Thank you!

解决方案

Is it possible to create a home screen shortcut that sends a broadcast instead of launching an Activity?

Strictly speaking, no.

However, you can have it point to an activity that is set up with Theme.NoDisplay, where in the activity's onCreate() you send your broadcast and call finish() without calling setContentView(). Visually, this is indistinguishable from having the shortcut send the broadcast itself.

这篇关于创建发送广播的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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