在分享前,先创建一个ArrayList<Uri>用来存储需要分享文件的Uri,必须是content://类型的
然后
var intent = Intent() intent.setAction(Intent.ACTION_IMAGE_CAPTURE) intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris) intent.setPackage("com.whatsapp") intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.addCategory("android.intent.category.DEFAULT") val type = intent.type intent.setType("audio/*") try { startActivity(Intent.createChooser(intent, mContext!!.getResources().getString(R.string.shareRecord_titleName))) } catch (e: Exception) { e.printStackTrace() }
其中fileUris为我们存数Uri的ArrayList<Uri>
MediaStore.ACTION_IMAGE_CAPTURE
intent.putParcelableArrayListExtra(,)可以分享多个文件
intent.putExtra(Intent.EXTRA_STREAM,uri)可以分享单个文件