如何通过intent发送csv文件



这是启动共享意图的函数当Shairing共享框打开时,我可以选择所有选项,如whatsapp,gmail,同时选择这些选项,文件不会被附加

private void OpenShare(String filename) {

Uri uri = Uri.parse(( getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getPath()+filename));

Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.setDataAndType(uri, "text/*");
startActivity(Intent.createChooser(sharingIntent, "share file with"));

}

共享框正在打开,请帮助我解决此

eror消息

2020-02-28 20:09:19.821 14722-14903/com.digicita.digiflow E/ActivityThread: Failed to find provider info for cn.teddymobile.free.anteater.den.provider
2020-02-28 20:09:20.719 14722-14821/com.digicita.digiflow E/Parcel: Reading a NULL string not supported here.
2020-02-28 20:09:21.484 14722-14722/com.digicita.digiflow E/Parcel: Reading a NULL string not supported here.
2020-02-28 20:09:24.422 14722-14722/com.digicita.digiflow E/ANR_LOG: >>> msg's executing time is too long
2020-02-28 20:09:24.422 14722-14722/com.digicita.digiflow E/ANR_LOG: Blocked msg = { when=-2s378ms what=100 target=android.app.ActivityThread$H obj=ActivityRecord{40b44d2 token=android.os.BinderProxy@67a38f1 {com.digicita.digiflow/com.digicita.digiflow.MainActivity}} } , cost  = 2328 ms
2020-02-28 20:09:24.422 14722-14722/com.digicita.digiflow E/ANR_LOG: >>>Current msg List is:
2020-02-28 20:09:24.422 14722-14722/com.digicita.digiflow E/ANR_LOG: Current msg <1>  = { when=-2s350ms what=101 target=android.app.ActivityThread$H obj=com.android.internal.os.SomeArgs@43079a3 }
2020-02-28 20:09:24.423 14722-14722/com.digicita.digiflow E/ANR_LOG: Current msg <2>  = { when=-2s325ms what=109 target=android.app.ActivityThread$H arg1=1 obj=android.os.BinderProxy@929e1d }
2020-02-28 20:09:24.423 14722-14722/com.digicita.digiflow E/ANR_LOG: Current msg <3>  = { when=-1s845ms what=103 target=android.app.ActivityThread$H obj=com.android.internal.os.SomeArgs@4c5a4a0 }
2020-02-28 20:09:24.423 14722-14722/com.digicita.digiflow E/ANR_LOG: Current msg <4>  = { when=-1s845ms what=137 target=android.app.ActivityThread$H arg1=1 obj=android.os.BinderProxy@67a38f1 }
2020-02-28 20:09:24.423 14722-14722/com.digicita.digiflow E/ANR_LOG: Current msg <5>  = { when=-1s468ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2020-02-28 20:09:24.424 14722-14722/com.digicita.digiflow E/ANR_LOG: Current msg <6>  = { when=-1s402ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2020-02-28 20:09:24.424 14722-14722/com.digicita.digiflow E/ANR_LOG: Current msg <7>  = { when=-1s162ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2020-02-28 20:09:24.424 14722-14722/com.digicita.digiflow E/ANR_LOG: Current msg <8>  = { when=-1s100ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2020-02-28 20:09:24.424 14722-14722/com.digicita.digiflow E/ANR_LOG: Current msg <9>  = { when=-1s92ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2020-02-28 20:09:24.425 14722-14722/com.digicita.digiflow E/ANR_LOG: Current msg <10>  = { when=-1s84ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2020-02-28 20:09:24.425 14722-14722/com.digicita.digiflow E/ANR_LOG: >>>CURRENT MSG DUMP OVER<<<
2020-02-28 20:09:38.731 14722-14722/com.digicita.digiflow E/Parcel: Reading a NULL string not supported here.
2020-02-28 20:09:47.514 14722-14722/com.digicita.digiflow E/Parcel: Reading a NULL string not supported here.
2020-02-28 20:10:19.139 14722-14722/com.digicita.digiflow E/Parcel: Reading a NULL string not supported here.
2020-02-28 20:14:01.323 14722-14722/com.digicita.digiflow E/Parcel: Reading a NULL string not supported here.
2020-02-28 20:14:24.794 14722-14722/com.digicita.digiflow E/Parcel: Reading a NULL string not supported here.

将以下代码添加到清单中的意向过滤器中。

<data android:mimeType="text/comma_separated_values/csv" />

并将MIME类型更改为text/plaintext/csvtext/comma-separated-values

尝试使用

intent.setType("text/*");

请确保在测试设备上安装了足够的应用程序。("text/csv")是正确的格式,但您可以尝试使用("text/plain"),它也会打开安装的所有文本编辑器。

最新更新