简体   繁体   English

如何将文件从Google云端硬盘上传到我的应用?

[英]How to upload files from Google Drive to my app?

Hello in my application i need to backUp my Database file to google Drive account via the Intent class, i just create the file and send it on "Intent.ACTION_SEND" and the user need to choose Google drive . 您好,在我的应用程序中,我需要通过Intent类将数据库文件备份到google Drive帐户,我只需创建该文件并将其发送到“ Intent.ACTION_SEND”,用户就需要选择Google drive。 now, i want to import it from the google drive to my app again.that is possible? 现在,我想再次将其从Google驱动器导入到我的应用中。可以吗? and one more thing.. there is a way to upload it directly to google drive ? 还有一件事..有一种方法可以将其直接上传到Google Drive? because the intent chooser give the user all the options. 因为意图选择器为用户提供了所有选项。

here is my code how i save it: 这是我的代码如何保存它:

@SuppressLint("SdCardPath")
private void exportDB() throws IOException {
    // Open your local db as the input stream
    try {
        String inFileName = "/data/data/com.appsa.work/databases/"+DbHandler.DB_NAME;
        File dbFile = new File(inFileName);
        FileInputStream fis = new FileInputStream(dbFile);

        String outFileName = Environment.getExternalStorageDirectory() + "/work/MyDatabase";

        // Open the empty db as the output stream
        OutputStream output = new FileOutputStream(outFileName);
        // transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = fis.read(buffer)) > 0) {
            output.write(buffer, 0, length);
        }
        // Close the streams
        output.flush();
        output.close();
        fis.close();

    } catch (Exception e) {
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG)
                .show();
    }
    Toast.makeText(context,
            "Uploaded.",
            Toast.LENGTH_LONG).show();
}


public void sendDb(String mailAddres){

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] {mailAddres});
    intent.putExtra(Intent.EXTRA_SUBJECT, "my file");

    File root = Environment.getExternalStorageDirectory();
    File file = new File(root, "/work/MyDatabase");
    if (!file.exists() || !file.canRead()) {
        Toast.makeText(context, "no sd_card", Toast.LENGTH_SHORT).show();
        return;
    }
    Uri uri = Uri.parse("file://" + file.getAbsolutePath());
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    context.startActivity(Intent.createChooser(intent, "Send"));
}

You can do this using the Drive Android API. 您可以使用Drive Android API来执行此操作。 See creating files and working with file contents. 请参阅创建文件使用文件内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Drive Android API如何将音频文件上传到我的驱动器? 如何同步驱动器文件? - Google Drive Android API how to upload a audio file to my drive ? How to sync drive files? 如何从Google Drive或Onedrive将文件上传到HTML5 Web App? - How to upload files to HTML5 Web App from Google Drive or Onedrive? 如何将图像从我的Android应用程序上传到Google驱动器上的特定文件夹 - how to upload an image from my android app to a specific folder on google drive 我的应用程序用户可以在不提供Gmail用户名或密码的情况下将文件上传到我的Google云端硬盘吗? - Can my app users upload files to my Google Drive, without giving my gmail user nor password? 如何使用静态凭据从Google驱动器上载和检索文件 - How to upload and retrieve the files from Google drive with static credentials android 通过文件扩展名在我的 Android 应用程序中打开来自 Google Drive 的文件 - Opening files from Google Drive in my Android app by file extension 如何在我的cordova phonegap android应用上从Google云端硬盘获取文件和文件夹列表? - How to get list of files and folders from Google Drive on my cordova phonegap android app? 将文件从Android应用上传到Google驱动器 - Upload file from android app to google drive 如何使用Google Drive API上传文件? - How to upload files using the Google Drive API? 在我的Android应用中管理Google云端硬盘上的文件 - Managing files on Google Drive in my Android app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM