本文主要是介绍android选择图片分享微信好友和朋友圈,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、true分享好友,false分享朋友圈
class ShareActivity : AppCompatActivity() {private val imageUris: ArrayList<Uri> = ArrayList()override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.layout_test)tv.setOnClickListener {startActivityForResult(Intent("android.intent.action.GET_CONTENT").apply {type = "image/*"}, 101)}}private fun Boolean.setIntent() {val intent = Intent()val cls: Stringval pkg = "com.tencent.mm"if (this) {cls = "com.tencent.mm.ui.tools.ShareImgUI"intent.action = Intent.ACTION_SEND_MULTIPLEintent.putExtra(Intent.EXTRA_STREAM, imageUris)} else {cls = "com.tencent.mm.ui.tools.ShareToTimeLineUI"intent.action = Intent.ACTION_SENDintent.putExtra(Intent.EXTRA_STREAM, imageUris[0])}if (imageUris.isNotEmpty()) {intent.component = ComponentName(pkg, cls)intent.type = "image/*"startActivity(intent)}}override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {super.onActivityResult(requestCode, resultCode, data)when (requestCode) {101 -> {if (resultCode == RESULT_OK) {val uri = data?.datauri?.let {imageUris.add(uri)}false.setIntent()}}}}}
这篇关于android选择图片分享微信好友和朋友圈的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!