skip to Main Content

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.

2

Answers


  1. -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"));
    
    Login or Signup to reply.
  2. <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;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search