如何绕过“使用...完成操作”?

发布于 2024-08-13 17:47:01 字数 322 浏览 3 评论 0原文

当在 Android 中显示“使用完成操作”对话框时,我有一个与以编程方式选择应用程序相关的问题。

示例如下: 在我的代码中,我有这样的声明:

startActivity(new Intent(Intent.ACTION_VIEW,
                         Uri.parse("http://www.youtube.com/watch?v=98yl260nMEA")));

然后我将看到一个包含两个选项的对话框: 使用浏览器或 YouTube 完成操作

您知道如何在不显示对话框的情况下选择 YouTube吗?

I have a question related to choosing an application programmatically when shown the dialog "Complete Action Using" in Android.

An example would be as follows:
In my code, I have this statement:

startActivity(new Intent(Intent.ACTION_VIEW,
                         Uri.parse("http://www.youtube.com/watch?v=98yl260nMEA")));

I will then be shown a dialog box with two options:
to complete the action using the Browser or YouTube

Any idea how can I choose YouTube without being shown the dialog box?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄风 2024-08-20 17:47:01

我认为您将需要有关您要默认启动的应用程序(在本例中为 youtube 应用程序)的意图过滤器的更多信息。该目标应用程序可能有多个意图过滤器,其中之一可能更具体。您可以根据该特定意图调用 startActivity,然后将直接启动预期的应用程序。但是,这需要您对目标应用程序有更多的了解(这在大多数情况下(例如 Youtube 应用程序)很困难)。

除此之外,我认为您在应用程序中不能做太多事情。意图解析是由 Android 框架完成的,因此如果用户应用程序可以以某种方式覆盖它,那么这将是安全方面的缺陷。

I think you will need more information about the intent-filter of the app you want to launch by default (in this case youtube app). That target app might have multiple intent-filters and one of them might be more specific. You can call startActivity with that specific intent, and then the intended app will be launched directly. However, this requires you to have more knowledge of the target app (which is difficult in most cases like Youtube app).

Other than that, I don't think you can do much from within your app. Intent resolution is done by the Android framework, so if a user app could override it somehow, that would be a flaw in terms of security.

微凉徒眸意 2024-08-20 17:47:01
PackageManager pm = getPackageManager(); 
List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(Intent.ACTION_VIEW, Uri.parse(youtube.com/watch?v=Zi_XLOBDo_Y)), 0); 
Iterator<ResolveInfo> actList = activities.iterator(); 
while(actList.hasNext()) { 
   ResolveInfo curr = actList.next(); 
   Log.d("Intents =====> ", curr.toString() + " " + curr.match + " " + curr.isDefault); 
}
PackageManager pm = getPackageManager(); 
List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(Intent.ACTION_VIEW, Uri.parse(youtube.com/watch?v=Zi_XLOBDo_Y)), 0); 
Iterator<ResolveInfo> actList = activities.iterator(); 
while(actList.hasNext()) { 
   ResolveInfo curr = actList.next(); 
   Log.d("Intents =====> ", curr.toString() + " " + curr.match + " " + curr.isDefault); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文