I read the documentation on receiving simple data. I want to receive an URL,i.e. text/plain from other apps.
So, I declared only this intent filter:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
In my MainActivity.class:
void onCreate (Bundle savedInstanceState) {
...
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
}
I'm handling the received text as:
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// Update UI to reflect text being shared
textBox.setText(sharedText);
}
}
But, the document reads that I should handle MIME types of other types carefully.
1) But, since I only registered for plain/text, do I need any more type handling code?
2) Moreover, citing documentation :
Keep in mind that if this activity can be started from other parts of the system, such as the launcher, then you will need to take this into consideration when examining the intent.
The MainActivity.java is also started by LAUNCHER. How do I handle that?
3) Once, user selects my app from the dialog, does it open that app, in all cases? I don't need my app to be opened. Can I circumvent that?
EDIT : I don't need my app's UI to be opened. But I want to receive the text.