如何在android中制作正在运行的应用程序的小部件?
我想制作我正在运行的应用程序的小部件。我的意思是我想通过主屏幕上的小部件访问我的应用程序。我想拨打电话,向存储在我的应用程序中的特定号码发送短信。
在安卓上可以吗?我被困在这个问题上,如果有人有任何类型的想法,请建议我。
编辑:-
我想制作像电源控制这样的小部件。在这里我们可以通过widget来操作设置的所有功能。以同样的方式,我想通过小部件控制我的应用程序,为此我必须将我的应用程序与小部件同步,反之亦然。所以我不明白我该怎么做。任何人都可以以这种方式帮助我吗?
谢谢。
I want to make my running application's widget. I mean I want to access my application through widget on home screen. I want to dial a call, send sms to particular number which is stored in my application.
Is it possible in android? I am stuck on this if anyone has any type of idea then please suggest me..
Edit:-
I want to make widget like Power Control. In this we can operate all features of settings through widget. At the same ways I want to control my application through widget and for that I have to sync my application with widget or visa-versa. So I am not able to understand how can I do that.. Can anyone help me in this manner?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以创建广播接收器来使用所有广播事件,并且无论您是从应用程序还是从小部件触发广播事件,它们都将在您的广播侦听器中处理。
You can create broadcast receiver to consume all the broadcast events, and it doesn't matter if you fire broadcast events from your application of from your widget, they all will be handled at your broadcast listener.
没有将应用程序转换为小部件的快捷方式。
对不起,伙计。
There is no shortcut to convert an app to widget.
Sorry buddy.
您应该为您的应用程序添加一个附加组件。该组件将是小部件。在 Eclipse 中,您可以通过向导将一个新类添加到您的包中,并说它将是一个小部件。
它应该有简单的布局 - 检查您在视图中使用的元素。仅允许 FrameLayout、LinearLayout、RelativeLayout、AnalogClock、Button、Chronometer、ImageButton、ImageView、ProgressBar、TextView、ViewFlipper。使用禁止的元素会导致“加载小部件时出现问题”消息。提防!
我想,您已经看过该页面了解如何放置小部件在清单中以及如何制作应用程序小部件提供程序。
在设备或模拟器上安装后,您需要将小部件安装到屏幕上。长按将引导您进入设备/模拟器的小部件安装向导。您只需要执行一次 - 在每次调试启动时,您都会自动在正确的位置获得新版本。
不过,不要忘记更新所有重要的视图 - 它不会自动完成。 (检查什么本身不刷新并在代码中刷新它们)。
我想,您已经知道如何从小部件主体调用您的启动活动。只是现在它还不是启动活动,而是首先从小部件启动的活动。该小部件将在清单中声明为启动。
You should do an additional component to your application. That component will be widget. In Eclipse you could add a new class to your package through the wizard and say that it will be a widget.
It should have simple layout - check elements you used in the view. only FrameLayout, LinearLayout, RelativeLayout, AnalogClock, Button, Chronometer, ImageButton, ImageView, ProgressBar, TextView, ViewFlipper are allowed. Using forbidden elements causes "Problem Loading Widget" message. Beware!
I think, you have already seen that page about how to place a widget in Manifest and how to make an appwidget-provider.
After installing on the device or emulator you whould install widget to the screen. Long touch will conduct you to the widget install wizard of the device/emulator. You will need to do it only once - at every debug launch you'll have the new version on the right place automatically.
Don't forget to renew all important views though - it will not be done automatically. (check what is not refreshing by itself and refresh them in code).
I think, you already know, how to call your launch Activity from the widget body. Only now it won't be launch activity already, but the activity to be first launched from the widget. The widget will be declared as launch in the Manifest.
系统设置:只需将您的设置修改逻辑本地化在一个类中(例如 PowerControlHelper 等),找出您的方法将采用哪些参数,然后在小部件和完整 UI 应用程序中重用它。没有太大区别,您可以从小部件逻辑以及活动逻辑中访问所有相同的 Android API。
您的应用程序自己的设置:只要是同一个应用程序,您在哪里访问您的私人数据并不重要。请参阅http://developer.android.com/guide/topics/ data/data-storage.html#pref 有关共享首选项的更多详细信息。
System settings: just localize your settings-modifying logic in one class (like PowerControlHelper or something), figure out what parameters your methods will take and reuse it both in widget and in full-UI application. Not much difference there, you can access all the same android APIs from within widget logic as well as from activity logic.
Your application's own settings: it doesn't matter where you access your private data as long as it's the same application. See http://developer.android.com/guide/topics/data/data-storage.html#pref for more details on Shared Preferences.