开发者

Display Applications that can handle a particular filetype

开发者 https://www.devze.com 2023-02-16 16:27 出处:网络
So, I have the file path of a file in an application & I want to give the user the ability to select from all applications on the phon开发者_开发问答e that can handle/open that file type and then

So, I have the file path of a file in an application & I want to give the user the ability to select from all applications on the phon开发者_开发问答e that can handle/open that file type and then open the file in that applicaton. How do I do this? - performs a similar function to a file manager.


First you have to pick the type of Intent you want. This code picks applications that can send the data through SMS/email/etc utilizing ACTION_SEND.

Intent intent = new Intent(Intent.ACTION_SEND);

Next you need to use putExtra to get the file/message to the Intent.

Uri uri = Uri.fromFile(new File(myFile)); 
intent.putExtra(Intent.EXTRA_STREAM, uri);

Finally you create a chooser.

Intent chooser = Intent.createChooser(intent, "A Custom Message");
startActivity(chooser);
0

精彩评论

暂无评论...
验证码 换一张
取 消