本文介绍了使用驱动器api将sql数据库上传到谷歌驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我可以将数据库文件备份到/ sdcard / schoolbinder / backups / notes

我以此网站作为开始:

但它确实是图片而不是文件。关于如何上传文件的任何想法

解决方案

您所引用的演示已经有选择文件的示例。 b
$ b

  / ** 
*创建一个新文件并将其保存到云端硬盘。
* /
private void saveFileToDrive(){
//开始创建一个新内容并设置回调。
Log.i(标签,创建新内容);
最终位图图像= mBitmapToSave;
Drive.DriveApi.newDriveContents(mGoogleApiClient)
.setResultCallback(new ResultCallback< DriveContentsResult>(){
$ b $ @Override
public void onResult(DriveContentsResult result){
//如果操作不成功,我们不能做任何事情
//并且必须
//失败
if(!result.getStatus()。isSuccess()){
Log.i(TAG,无法创建新内容);
return;
}
//否则,我们可以将数据写入新内容。 b $ b Log.i(TAG,创建新内容);
//获取内容的输出流
OutputStream outputStream = result.getDriveContents()。getOutputStream();
//写入位图数据
ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
image.compress(Bitmap.Compres sFormat.PNG,100,bitmapStream);
尝试{
outputStream.write(bitmapStream.toByteArray());
} catch(IOException e1){
Log.i(TAG,Unable to write file contents。);
}
//创建初始元数据 - MIME类型和标题。
//请注意,用户稍后可以更改标题。
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType(image / jpeg)。setTitle(Android Photo.png)。build();
//为文件选择器创建一个意图,并启动它。
IntentSender intentSender = Drive.DriveApi
.newCreateFileActivityBuilder()
.setInitialMetadata(metadataChangeSet)
.setInitialDriveContents(result.getDriveContents())
.build(mGoogleApiClient);
尝试{
startIntentSenderForResult(
intentSender,REQUEST_CODE_CREATOR,null,0,0,0);
} catch(SendIntentException e){
Log.i(TAG,Failed to launch file chooser。);
}
}
});
}

它只是一个调用它的问题。看来演示程序正在调用Camera应用程序并返回 Image 。尝试删除 onConnected 方法中的条件,并且 saveFileToDrive 并显示一个File选取器。


I want to upload a database file to Google drive in my android app.

I can back up the database file fine it saves to /sdcard/schoolbinder/backups/notes

I used this website as a start: https://github.com/googledrive/android-quickstart/blob/master/app/src/main/java/com/google/android/gms/drive/sample/quickstart/MainActivity.java

this works as is in my app, but it does pictures not files. any idea on how to upload files

解决方案

The demo you cited already has the sample for choosing a file.

/**
 * Create a new file and save it to Drive.
 */
private void saveFileToDrive() {
    // Start by creating a new contents, and setting a callback.
    Log.i(TAG, "Creating new contents.");
    final Bitmap image = mBitmapToSave;
    Drive.DriveApi.newDriveContents(mGoogleApiClient)
            .setResultCallback(new ResultCallback<DriveContentsResult>() {

        @Override
        public void onResult(DriveContentsResult result) {
            // If the operation was not successful, we cannot do anything
            // and must
            // fail.
            if (!result.getStatus().isSuccess()) {
                Log.i(TAG, "Failed to create new contents.");
                return;
            }
            // Otherwise, we can write our data to the new contents.
            Log.i(TAG, "New contents created.");
            // Get an output stream for the contents.
            OutputStream outputStream = result.getDriveContents().getOutputStream();
            // Write the bitmap data from it.
            ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
            image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);
            try {
                outputStream.write(bitmapStream.toByteArray());
            } catch (IOException e1) {
                Log.i(TAG, "Unable to write file contents.");
            }
            // Create the initial metadata - MIME type and title.
            // Note that the user will be able to change the title later.
            MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
                    .setMimeType("image/jpeg").setTitle("Android Photo.png").build();
            // Create an intent for the file chooser, and start it.
            IntentSender intentSender = Drive.DriveApi
                    .newCreateFileActivityBuilder()
                    .setInitialMetadata(metadataChangeSet)
                    .setInitialDriveContents(result.getDriveContents())
                    .build(mGoogleApiClient);
            try {
                startIntentSenderForResult(
                        intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
            } catch (SendIntentException e) {
                Log.i(TAG, "Failed to launch file chooser.");
            }
        }
    });
}

Its just a matter of calling it. It seems that the demo is calling the Camera app and returning the Image. Try to remove the if condition in the onConnected method and the saveFileToDrive should be called and show a File picker.

这篇关于使用驱动器api将sql数据库上传到谷歌驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 00:55