-1

I'm actually trying to send a data which is coming from an API(as a text not as a file) to me and I want to send that data as a text file by many apps which includes sharing of files like WhatsApp, hike, telegram, shareit, etc.

Arun Sriramula
  • 124
  • 1
  • 13

2 Answers2

0

-Can you try this code and see if it is working with you:

Intent shareIntent = new Intent("android.intent.action.SEND");
shareIntent.setType("text/plain");               
shareIntent.putExtra("android.intent.extra.SUBJECT",
                     "Codes Easy");              
shareIntent.putExtra("android.intent.extra.SUBJECT",
         "Add a text to be shared here");
startActivity(Intent.createChooser(shareIntent, "Share with"));
Osama Abdelaziz
  • 132
  • 2
  • 8
  • I already tried this it can only send a text as plain text it doesn't create a file with .txt extension and I want to send that .txt file using intent and can you suggest an MIME for .txt? – Arun Sriramula May 31 '19 at 11:08
0
<data android:scheme="file" /> //Means local file
<data android:mimeType="*/*"/> //This accept any mimeType
<data android:pathPattern=".*\\.txt" /> //Your excepted extention

Try this code:

private Uri getUriForFile() {
  Intent intent = getIntent();
  String action = intent.getAction();
  String type = intent.getType();
  if (TextUtils.equals(Intent.ACTION_SEND, action) 
           && !TextUtils.isEmpty(type)) {
     Uri uri = 
         intent.getParcelableExtra(Intent.EXTRA_STREAM);
     if (uri != null) {
        Log.e("uri",uri.toString());
        return  uri;
     }
  }
  return null;
}
Osama Abdelaziz
  • 132
  • 2
  • 8