Home > Mobile >  Turn to call the android native sharing function, send the file to WeChat, change file name
Turn to call the android native sharing function, send the file to WeChat, change file name

Time:01-31

Want to invoke the android's built-in sharing function, sends a data. The db files to WeChat, file name changed in WeChat, add the suffix.. Octet stream,

But share the qq is ok, and use system share own file manager to WeChat sure


The code is as follows:
 public static void shareFile (Context Context, String fileName) {
The File File=new File (fileName);
if (null !=the file & amp; & File. The exists ()) {
Intent share=new Intent (Intent. ACTION_SEND);
//above android7 FileProvider
If (Build) VERSION) SDK_INT & gt;=Build. VERSION_CODES. N) {
Uri contentUri=FileProvider. GetUriForFile (context, BuildConfig APPLICATION_ID + ". FileProvider ", the file).
Share. PutExtra (Intent. EXTRA_STREAM contentUri);
} else {
Share. PutExtra (Intent. EXTRA_STREAM, Uri fromFile (file));
}
Share. SetType (" application/octet - stream ");
Share. SetFlags (Intent. FLAG_ACTIVITY_NEW_TASK);
Share. AddFlags (Intent. FLAG_GRANT_READ_URI_PERMISSION);
Context. StartActivity (Intent. CreateChooser (share, "file sharing"));
} else {
Toast. MakeText (context, "Shared file does not exist," Toast. LENGTH_SHORT), show ();
}
}


CodePudding user response:

If you put the share. SetType (" application/octet - stream "); to share. SetType (" application/db "); in this way, it would be?

CodePudding user response:

reference 1st floor coolestingx response:
if you put the share. SetType (" application/octet stream - "); to share. SetType (" application/db "); in this way, it would be?

Still won't do

CodePudding user response:

Application/octet stream - usually when I don't know the file type, submit for binary file,
You know this is a database file, change the type

CodePudding user response:

Try to use multipart/form - the data

CodePudding user response:

reference 5 floor can't write code monkey's reply:
try multipart/form - data

Into a multipart/form - data, no WeChat and QQ options

CodePudding user response:

This,,,,,,, not setType?
  • Related