How can I handle a “share via” dialog request from another application?

I added an intent filter in ApplicationManifest.xml to transfer my application to the Share Through dialog:

<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
</intent-filter>

How can I process a request from another application.

1 Is it possible to distinguish between direct application launch and sharing?

2 How to access shared data?

+3
source share
2 answers

In onCreate, you can call getIntent () to find out if there is any data in the bundle. Use the getData () method to retrieve a Uri or one of the retrieval methods ... Additional methods to retrieve any other expected data.

void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.id.main);
    ...
    Intent i = getIntent();
    Uri data = i.getUri(); 
    if(data != null) {
    // do something interesting
    }
    /* or */
    String text = i.getStringExtra(Intent.EXTRA_TEXT);
    / * do something interesting with the text */
}
+4

1: SEND.

2 . .

0

Source: https://habr.com/ru/post/1793874/


All Articles