WeChat7.0以降の複数の写真の共有の偽装実現

最初のコード:

 public void callSystemShare(String imgUrl) {
        Intent intent = new Intent();
        /*
        *  //微信手动发朋友圈的界面
        intent.setComponent(new ComponentName("com.tencent.mm", 
                "com.tencent.mm.ui.tools.ShareScreenToTimeLineUI"));
                */
        Uri uri;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = getImageContentUri(this, new File(imgUrl));
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        } else {
            uri = Uri.fromFile(new File(imgUrl));
        }
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/*");
        this.startActivity(Intent.createChooser(intent, ""));
    }

    private Uri getImageContentUri(Context context, File imageFile) {
        String filePath = imageFile.getAbsolutePath();
        Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                new String[]{MediaStore.Images.Media._ID}, MediaStore.Images.Media.DATA + "=? ",
                new String[]{filePath}, null);
        Uri uri = null;

        if (cursor != null) {
            if (cursor.moveToFirst()) {
                int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
                Uri baseUri = Uri.parse("content://media/external/images/media");
                uri = Uri.withAppendedPath(baseUri, "" + id);
            }

            cursor.close();
        }

        if (uri == null) {
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.DATA, filePath);
            uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        }

        return uri;

アイデア:n枚の写真を共有するには、最初にn-1枚の写真をアルバムに追加し、次に1枚の写真をWeChatのMomentsインターフェイスへの手動投稿に取り、ユーザーにアルバムに移動して選択するように促します。

おすすめ

転載: blog.csdn.net/genmenu/article/details/86551986