gpt4 book ai didi

android - 如何显示一个窗口,用户可以在其中选择他们想要运行的应用程序

转载 作者:行者123 更新时间:2023-11-30 01:38:20 25 4
gpt4 key购买 nike

我有一个应用程序,用户可以在其中选择一个日期,然后它会打开日历,然后他们会向其中添加事件或提醒。

现在我正在使用 com.google.android.calendar 应用程序。但我正在检查是否已安装。如果不是,它应该让他们选择他们想要打开的应用程序。谁能告诉我该怎么做?我几乎可以肯定我听说过这件事,但我记不起它叫什么了。

最佳答案

阅读this tutorial .

Once you have created your Intent and set the extra info, call startActivity() to send it to the system. If the system identifies more than one activity that can handle the intent, it displays a dialog for the user to select which app to use... If there is only one activity that handles the intent, the system immediately starts it.

此对话框中还有一个选项可以默认使用选定的操作。

However, if the action to be performed could be handled by multiple apps and the user might prefer a different app each time—such as a "share" action, for which users might have several apps through which they might share an item—you should explicitly show a chooser dialog...

此选择器对话框也称为应用程序选择器。

简而言之,您可以通过以下方式显示应用选择器:

String title = getResources().getString(R.string.chooser_title);
Intent chooser = Intent.createChooser(intent, title);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}

intent 是您的日历 Intent ,例如:

Intent calendarIntent = new Intent(Intent.ACTION_INSERT, Events.CONTENT_URI);
Calendar beginTime = Calendar.getInstance().set(2012, 0, 19, 7, 30);
Calendar endTime = Calendar.getInstance().set(2012, 0, 19, 10, 30);
calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis());
calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis());
calendarIntent.putExtra(Events.TITLE, "New event");
calendarIntent.putExtra(Events.EVENT_LOCATION, "My house");

关于android - 如何显示一个窗口,用户可以在其中选择他们想要运行的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34832176/

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