想呼叫android自帶的的分享功能,發送一個data.db檔案到微信,在微信里檔案名變了,加了后綴..octet-stream,

但是分享到qq就沒事,而且用系統自帶的檔案管理器分享到微信也沒問題

代碼如下:
public static void shareFile(Context context, String fileName) {
File file = new File(fileName);
if (null != file && file.exists()) {
Intent share = new Intent(Intent.ACTION_SEND);
//android7以上用FileProvider
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri contentUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", 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, "分享檔案"));
} else {
Toast.makeText(context, "分享檔案不存在", Toast.LENGTH_SHORT).show();
}
}uj5u.com熱心網友回復:
如果你把 share.setType("application/octet-stream"); 改成 share.setType("application/db"); 這樣,它會是什么情況?
uj5u.com熱心網友回復:
還是不行
uj5u.com熱心網友回復:
application/octet-stream一般是在不知道檔案型別的時候,提交為二進制檔案。你這知道是資料庫檔案了,換個型別吧
uj5u.com熱心網友回復:
試試用multipart/form-datauj5u.com熱心網友回復:
改成multipart/form-data,沒有微信和qq的選項了

uj5u.com熱心網友回復:
啊這。。。。。不setType呢?轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/254586.html
標籤:Android
上一篇:關于給控制元件設定陰影的問題
