简体   繁体   English

Android 主屏幕小部件,从活动创建

[英]Android home screen widget, create from activity

I am trying to craete my first home screen widget.我正在尝试创建我的第一个主屏幕小部件。 I create it and adjust, and all is ok.我创建并调整它,一切都很好。 But I can't find there is a way to create widget from activity.但我找不到从活动创建小部件的方法。 For example I have a button on my main activity.例如,我的主要活动上有一个按钮。 User hasn't created widget on his screen.用户尚未在其屏幕上创建小部件。 Can I create programmatically widget?我可以以编程方式创建小部件吗? For example by button click listener?例如通过按钮点击监听器?

As per the Pinning App Widgets documentation , on API 26+ devices, allows your app to launch the widget interface to pin a specific widget by using the requestPinAppWidget() API.根据Pinning App Widgets 文档,在 API 26+ 设备上,允许您的应用程序启动小部件界面以使用requestPinAppWidget() API 固定特定小部件。 Apps must use isRequestPinAppWidgetSupported() to check to make sure the launcher supports this functionality.应用程序必须使用isRequestPinAppWidgetSupported()来检查以确保启动器支持此功能。

There's no equivalent on earlier versions of Android. Android 的早期版本没有等效项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM