从我的应用程序调用另一个appllication [英] Call another appllication from my application

查看:139
本文介绍了从我的应用程序调用另一个appllication的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个应用程序,我需要调用已安装在按钮单击该设备的另一个应用程序。

I am creating an application where I need to call another application that is already installed in the device on button click.

我已经做了一些关于它的研究,我明白,我需要调用的相同的意图。我不明白是我不为我想调用应用程序有一个类名。例如,如果我想从我的按钮单击应用程序调用设备的画廊,我怎么做呢?

I have done some research on it and I understand that I will need to call an intent for the same. What I dont understand is I do not have a class name for the application I want to call. For example, if I want to call the device's gallery from my application on button click, how do I do that?

Uri uri = Uri.parse("file:///sdcard/");
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setType("application/pdf");
startActivity(intent);
return true;

谢谢你们。我已经试过这code,但它说,文件无法打开。

Thanks guys. I have tried this code but it said document could not be opened.

推荐答案

如果确切的应用是不太重要的,你只需要的东西,会显示你的内容,你可以完全忽略组件名称了。只需设定的动作,数据,和(可选)的输入意图,让操作系统做的工作。

If the exact application is less important, and you just need something that will display your content, you can omit the component name entirely, too. Just set the action, data, and (optionally) type on the intent and let the OS do the work.

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(/*your data uri*/);
intent.setType(/*your data's MIME type*/);
startActivity(intent);

这意图将已注册的视图操作和相应的MIME类型的意图一些应用程序进行处理。这是一个隐含的意图,像阿迪尔提及。

This intent will be handled by some app that has registered for intents with the view action and the appropriate MIME type. This is an implicit intent, like Adil mentioned.

这篇关于从我的应用程序调用另一个appllication的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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