Intent-filter: How to accept only “text/plain” int

2019-08-15 00:02发布

问题:

My app is about spaghetti, and it should allow you to share any text/plain content provided it's about spaghetti. So I need an intent-filter that accepts only such content.

In case it helps, these are example spaghetti:

Unfortunately, I only found a way to accept text/plain content, but I couldn't find anything in the docs to filter via the text itself.

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

Is this possible at all? Workarounds are welcome.

回答1:

Is this possible at all?

No.

Workarounds are welcome.

Accept all text, and if the text does not contain references to suitable pasta products, show an error and possibly finish() your activity to return the user to wherever they came from.

You could invent your own MIME type (e.g., application/vnd.cprcrack.al.dente), but since approximately zero other apps will be sharing things with that MIME type, the user will get hungry.