【问题标题】:Create Widget on Application Installation在应用程序安装上创建小部件
【发布时间】:2011-02-24 08:14:56
【问题描述】:

我只是想知道,当用户安装我的应用程序时,有什么方法可以让一个 android 小部件显示在用户的主屏幕上?另外,我可以让他们选择在我的应用程序中创建小部件吗?

【问题讨论】:

标签: android android-widget


【解决方案1】:

我只是想知道,当用户安装我的应用程序时,有什么方法可以让一个 android 小部件显示在用户的主屏幕上?

不,对不起。您的任何代码都不会在安装时执行。

另外,我可以让他们选择在我的应用程序中创建小部件吗?

不,对不起。只有主屏幕可以将应用小部件添加到主屏幕。

【讨论】:

  • 好吧,我同意你的回答,但我很惊讶这个应用程序如何让这个功能发挥作用play.google.com/store/apps/details?id=com.cleanmaster.mguard
  • 当点击主屏幕上的图标时,它具有一键提升功能我已经问过一个关于微笑功能的问题,你可以回答这个..吗? stackoverflow.com/questions/23004624/…
  • @Hardik,我认为,clean master 不会创建任何小部件,而是创建应用程序的快捷方式
  • @ErKimmiDhingra 是的清洁大师创建应用程序的快捷方式,但我的问题是他们如何为快捷方式图标设置动画。在上面的链接中查看我的答案
  • @CommonsWare 如果我的应用是启动器怎么办?
【解决方案2】:

安装时无法获得回调。但在 Android O 中,您可以在应用程序首次启动时固定您的小部件。

AppWidgetManager mAppWidgetManager =
    context.getSystemService(AppWidgetManager.class);

AppWidgetProviderInfo myWidgetProviderInfo = new AppWidgetProviderInfo();
ComponentName myProvider = myWidgetProviderInfo.provider;

if (mAppWidgetManager.isRequestPinAppWidgetSupported()) {
  // Create the PendingIntent object only if your app needs to be notified
  // that the user allowed the widget to be pinned. Note that, if the pinning
  // operation fails, your app isn't notified.
  Intent pinnedWidgetCallbackIntent = new Intent( ... );

  // Configure the intent so that your app's broadcast receiver gets
  // the callback successfully. This callback receives the ID of the
  // newly-pinned widget (EXTRA_APPWIDGET_ID).
  PendingIntent successCallback = PendingIntent.createBroadcast(context, 0,
          pinnedWidgetCallbackIntent);

  mAppWidgetManager.requestPinAppWidget(myProvider, null,
           successCallback.getIntentSender());
}

另请查看谷歌官方documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-19
    • 1970-01-01
    • 2012-06-25
    相关资源
    最近更新 更多