Не удается отправить аудиофайл в WhatsApp на эмуляторе Android Jelly Bean.Мой код в настоящее время работает на Lollipop и более поздних версиях, но я не мог понять, почему эта ошибка возникает на более низких устройствах.
val share = Intent(Intent.ACTION_SEND)
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
//Audio MIME type
share.type = "audio/*"
//File uri (from file provider on api level 24 or higher)
share.putExtra(Intent.EXTRA_STREAM, fileUri(context))
context.startActivity(Intent.createChooser(share, context.getString(R.string.share_title)))
внутри метода fileUri
if (Build.VERSION.SDK_INT < 24)
return Uri.fromFile(this)
return FileProvider.getUriForFile(context, context.applicationContext.packageName
+ ".[myprovidername].provider", this)
logs
04-21 19:08:25.653 2840-2840/com.whatsapp W/Bundle: Key android.intent.extra.STREAM expected ArrayList but value was a android.net.Uri$HierarchicalUri. The default value <null> was returned.
04-21 19:08:25.653 2840-2840/com.whatsapp W/Bundle: Attempt to cast generated internal exception:
java.lang.ClassCastException: android.net.Uri$HierarchicalUri cannot be cast to java.util.ArrayList
at android.os.Bundle.getParcelableArrayList(Bundle.java:1223)
at com.whatsapp.ContactPickerFragment.ga(:250573)
at com.whatsapp.ContactPickerFragment.a(:249616)
at c.j.a.u.a(:178380)
at c.j.a.u.f(:178956)
at c.j.a.u.a(:177973)
at c.j.a.u.b(:178772)
at c.j.a.u.j(:179098)
at c.j.a.j.onStart(:246644)
at c.a.a.m.onStart(:267332)
at d.f.qJ.onStart(:296953)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1164)
at android.app.Activity.performStart(Activity.java:5114)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)