Android receives a text file for sharing, but does not transfer text content

I am making an application that can upload one or more files or folders. The intent filter is defined as follows:

<activity android:name=".UploadActivity" android:launchMode="singleTop" android:theme="@style/Theme.Sherlock"> <intent-filter android:label="@string/upload_intent"> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:mimeType="application/*" /> <data android:mimeType="audio/*" /> <data android:mimeType="image/*" /> <data android:mimeType="media/*" /> <data android:mimeType="multipart/*" /> <data android:mimeType="text/*" /> <data android:mimeType="video/*" /> </intent-filter> <intent-filter android:label="@string/upload_intent"> <action android:name="android.intent.action.SEND_MULTIPLE" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:mimeType="*/*" /> </intent-filter> </activity> 

This works great with Blackmoon File Explorer and Android 4.0.3 Gallery. My application is displayed in the Share menu. However, it also appears in the browser when you click the URL for a long time and select Share Page.

When I send a text file to my application, I get the following:

 getIntent().getAction() returns Intent.ACTION_SEND getIntent().getType() returns "text/plain" getIntent().getScheme() returns null getIntent().getExtras().getString(Intent.EXTRA_STREAM) returns the filename 

However, sending the URL from the browser returns the same minus Intent.EXTRA_STREAM. I can easily find it in the code and say "hey, I can’t load the text!" but I would prefer to change the intent filter so that it only works when EXTRA_STREAM is present. Can this be done?

(I tried using the android: scheme, but this will not distinguish between the file and the common text string, as both of them are null ...)

+4
source share
1 answer

You have:

 getIntent().getExtras().getString(Intent.EXTRA_STREAM) returns the filename 

AFAIK, Android never sends you an open fh or socket file to a file. Just a simple, old file path with which you are then processing:

 File somefile = new File(filename); 

And then read or write on it, and what not.

As for the incoming text EXTRA_TEXT or STREAM, just check for both and process it accordingly. Hope this helps.

+2
source

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


All Articles