在没有 bindAppWidgetId() 的情况下将小部件添加到启动器页面 [英] Adding widgets to a launcher page without bindAppWidgetId()

查看:30
本文介绍了在没有 bindAppWidgetId() 的情况下将小部件添加到启动器页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将股票 ICS 启动器变成一个独立的应用程序.我快到了 - 唯一不起作用的是搜索图标和将小部件拖放到屏幕上,这会导致崩溃.

I'm trying to turn the stock ICS launcher into a standalone app. I'm nearly there - the only things not working are the search icon and dropping widgets onto the screen, which causes a crash.

崩溃是因为股票启动器使用 appWidgetManager.bindAppWidgetId(appWidgetId, componentName); 添加小部件,其中 显然只有系统应用才有权限.

The crash is because the stock launcher uses appWidgetManager.bindAppWidgetId(appWidgetId, componentName); to add widgets, which apparently only system apps have permission to do.

所以我的问题是,非系统应用程序添加小部件并获得与股票 ICS 启动器相同的 UI 体验的正确方法是什么?

So my question is, what is the correct way for a non-system app to add widgets and acheive the same UI experience as the stock ICS launcher?

推荐答案

我现在知道了最终的答案.在 Android 4.0 中,你不能这样做.我最终让我的用户选择了两次小部件,这很糟糕,但没有办法解决.

I now know the definitive answer. In Android 4.0, you can't do it. I ended up making my users pick the widget twice, which sucks, but there is no way around it.

在 Android 4.1 中他们解决了这个问题!

SDK 应用程序现在可以托管小部件,而不必使用垃圾小部件选择器 API!你可以查看Jellybean Launcher2源码了解详情,但基本上,当你第一次尝试绑定一个widget时,Android会弹出一个对话框说你想允许这个应用绑定widget吗",然后用户可以决定是否允许.

SDK apps can now host widgets and don't have to use the rubbish widget picker API! You can look into the Jellybean Launcher2 source code for details, but basically, when you first try to bind a widget, Android will pop up a dialog box saying "Do you want to allow this app to bind widgets", and then the user can decide to give it permission or not.

我不确定他们为什么选择模式权限授予对话框,而不是他们用于其他所有内容的安装时所有权限模型,但无论如何,它有效!

I'm not sure why they went for the modal permission-granting dialog box rather than the all-permissions-on-install model they've used for everything else, but whatever, it works!

现在我们只需要等待 4 或 5 年,直到每个人都拥有 Android 4.1 或更高版本!

Now we just have to wait 4 or 5 years until everyone has Android 4.1 or greater!

这篇关于在没有 bindAppWidgetId() 的情况下将小部件添加到启动器页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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