gpt4 book ai didi

Android - 打开小部件上下文菜单的 Intent

转载 作者:太空宇宙 更新时间:2023-11-03 10:28:06 26 4
gpt4 key购买 nike

在我的应用程序中,我希望当用户单击按钮时应用程序自行关闭并自动打开添加新的小部件上下文菜单。我正在做这个:

if (viewId == R.id.bt_homeScreen) {
finish();
try {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this.getApplicationContext(), getResources().getString(R.string.homeClientAlert), Toast.LENGTH_SHORT).show();
}
}

此代码的问题是我只转到手机主屏幕:

http://cdn.androidtapp.com/wp-content/uploads/2009/02/rc33-google-voice-search-for-android-on-home-screen.jpg
(来源:androidtapp.com)

我希望当我启动 Intent 时它会转到主屏幕并打开小部件上下文菜单:

http://www.taosoftware.co.jp/en/android/calendarwidget/img/choosewidget.png
(来源:taosoftware.co.jp)

最佳答案

看看 Commonsware 对这个问题的回答:Add widget to homescreen from Android application

您将能够显示小部件选择菜单,但您将无法在普通应用程序中处理该选择。使用 appwidget 选择的应用程序必须实现 AppWidgetHost。主屏幕应用属于此类,没有普通应用。

关于Android - 打开小部件上下文菜单的 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10113645/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com