0

the following code is the sharing pdf with UNTITLED.pdf how to name the pdf

 Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.setType("application/pdf");
                String shareMessage= "dummy";
               shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
              sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(targetPdf));
                startActivity(Intent.createChooser(sendIntent, "dummy"));

what I should put in putextra to change the shared pdf from UNTITLTED to dummy?

john Doe
  • 19
  • 5
  • You can't change name of the PDF by using `Intent` try this https://stackoverflow.com/a/32155722/4394827 – Hemanth S Apr 02 '19 at 10:50
  • Hello Hemanth, I have tried some of the codes from the above link which u have suggested me for renaming the file but it wasn’t helpful. I would like to brief you with my question again. I have pdf file location which saved into pdffile. Then checking file path exists or not. Over here I wrote if file path exists then renameTo method and saving it. Can you write what I am missing here plz – john Doe Apr 02 '19 at 17:40

1 Answers1

0

The activity that handles the ACTION_SEND Intent can do what it wants. There is no way to force it to do anything, in part because there are thousands of ACTION_SEND activities, each created by a different development team. So,

  • Some might pay attention to your EXTRA_TEXT, and some might not, as the ACTION_SEND specification only supports either EXTRA_TEXT or EXTRA_STREAM, and you are using both

  • Some might look at the last path segment of the Uri and assume that it is some sort of filename; others might not

So, populate the Intent as you are, perhaps tweak the values a bit, and otherwise just live with it.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491