Android 打算将音频数据共享到 google 驱动器中?

Android intent to share the audio data into the google drive?

我尝试使用以下方法将音频文件共享到 google 驱动器 method.Is 可以使用 Intent.createChooser() 方法将文件共享到 google 驱动器以及要添加到 Androidmanifest 文件中的任何权限。 错误是我无法将文件共享到 google drive.Please 帮我解决这个问题。

    Uri uri = Uri.parse(MEDIA_PATH);
    Intent share = new Intent(Intent.ACTION_SEND);
    share.putExtra(Intent.EXTRA_STREAM, uri);
    share.setType("audio/*");
    share.setPackage("com.google.android.apps.docs");
    share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(Intent.createChooser(share, "Share audio File"));

我不认为你可以那样做。首先,您需要 setup your Android to for Drive API. Then check the Creating Files 文档以了解如何创建文件。

"You can create files in two ways with the Drive Android API: using the CreateFileActivityBuilder class, or using the createFile() method of the DriveFolder interface"

这是一个驱动器 Android demo 供您参考代码。

试试这个对我有用的方法,使用 Intent.createChooser() 分享数据。

  File files = new File(MEDIA_PATHS);
            Uri u = Uri.fromFile(files);
            arrayList2.add(u);

 Intent share = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
                    share.setType("audio/mpeg");
                    share.putExtra(android.content.Intent.EXTRA_EMAIL, TO);
                    share.putExtra(android.content.Intent.EXTRA_CC, CC);
                    share.putExtra(android.content.Intent.EXTRA_SUBJECT, "Your subject");
                    share.putExtra(android.content.Intent.EXTRA_STREAM, arrayList2);
                    try {
                        startActivity(Intent.createChooser(share, "Share..."));
                        finish();
                        Log.i("Finished sharing.", "");
                    } catch (android.content.ActivityNotFoundException ex) {
                        Toast.makeText(CallRecordsActivity.this, "nothing shared.", Toast.LENGTH_SHORT).show();
                    }