with some files (e.g. images) it is possible to press a "share" button. Then a list of application opens that can be used to share this file. When one of these applications is chosen, the file (or pathname?) is handed over to this app for further processing.

My questions here: how is this implemented? How can I register my app to be listed for some specific file types? And how would the app receive the information a file has to be shared with this app?

Thanks!

有帮助吗?

解决方案

Sharing works with the specific intent filter action ACTION_SEND.

Any app that wants to register for a specific type of data can declare the appropriate intent filter in its manifest file.

On the other hand, applications that want to trigger a share action need to start an activity with an appropriate intent, such as described here: http://developer.android.com/training/sharing/send.html#send-binary-content

E.g to share an image:

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top