0

I'm trying to get the text when a .txt file is selected. But im only getting this back content://com.android.providers.downloads.documents/document/msf%3A52139. Im just barely getting to uri's and dont quite understand them yet Thanks I have this in on create of MainActivity

Intent i = getIntent();
String act = i.getAction();
if (act.equals("android.intent.action.VIEW")){t.setText 
(i.getData().toString());

And this in manifest

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category. 
BROWSER"/>
<data android:scheme="content"/>
<data android:mimeType="text/plain">
<data android:mimeType="image/*">
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.
BROWSER"/>
<data android:scheme="content"/>
<data android:mimeType="text/plain">
<data android:mimeType="image/*">
</intent-filter>
</activity>

       

David Wasser
  • 93,459
  • 16
  • 209
  • 274
J. M.
  • 9
  • 3
  • What you get isn't the text, what you get is a content provider URL. You need to open that and read in the text. See answers to this for an example: https://stackoverflow.com/questions/31069556/android-read-text-file-from-uri – David Wasser Jan 18 '22 at 09:39
  • 1
    Yes that worked forgot to add Intent i = getIntent(); then change data to i, at beginning they should have included that also thanks – J. M. Jan 18 '22 at 17:09
  • Can you answer this one also https://stackoverflow.com/questions/70702522/what-storage-method-2-use-4-saving-and-deleting-txt-files-programmatically-on-s?noredirect=1#comment125019585_70702522 – J. M. Jan 18 '22 at 23:59

0 Answers0