Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ApiException:10:必须请求驱动器#作用域_文件_Android_Google Api_Google Drive Api - Fatal编程技术网

Android ApiException:10:必须请求驱动器#作用域_文件

Android ApiException:10:必须请求驱动器#作用域_文件,android,google-api,google-drive-api,Android,Google Api,Google Drive Api,我变得异常了:10。我试着在网上找这个,但什么也没找到。奇怪的是,我在一些设备上得到了这个错误,而在其他设备上没有,也就是说,在一些设备上,比如emulator或my S7,文件是创建的,但在一些较旧的设备上,它给出了这个错误 我检查过的是:Google play服务在所有运行同一版本的设备上都是最新的,所以我想这是不可能的 代码: private void createNewFile(){ final File file = getApplicationContext().ge

我变得异常了:10。我试着在网上找这个,但什么也没找到。奇怪的是,我在一些设备上得到了这个错误,而在其他设备上没有,也就是说,在一些设备上,比如emulator或my S7,文件是创建的,但在一些较旧的设备上,它给出了这个错误

我检查过的是:Google play服务在所有运行同一版本的设备上都是最新的,所以我想这是不可能的

代码

    private void createNewFile(){
    final File file = getApplicationContext().getDatabasePath("eventManager");
    if(mDriveResourceClient!=null){
        Log.i(TAG,"Beginning Writing");
        final Task<DriveFolder> rootFolderTask = mDriveResourceClient.getRootFolder();
        final Task<DriveContents> createContentsTask = mDriveResourceClient.createContents();
        Tasks.whenAll(rootFolderTask, createContentsTask)
                .continueWithTask(new Continuation<Void, Task< DriveFile>>(){
                    @Override
                    public Task<DriveFile> then(Task<Void> task) throws Exception{
                        Log.i(TAG,"Writing task started");
                        DriveFolder parent = rootFolderTask.getResult();
                        DriveContents contents = createContentsTask.getResult();
                        OutputStream outputStream = contents.getOutputStream();
                        try{
                            InputStream inputStream = new FileInputStream(file);
                            byte[] buf = new byte[4096];
                            int c;
                            while((c = inputStream.read(buf, 0, buf.length))>0){
                                outputStream.write(buf, 0, c);
                            }
                        }catch (Exception e) {
                            Log.i(TAG,"Writing task failed");

                        }finally {
                            outputStream.close();
                        }
                        MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                                .setTitle("My_File")
                                .setMimeType("application/x-sqlite3")
                                .setStarred(true)
                                .build();
                        Log.i(TAG,"Writing task started");
                        return mDriveResourceClient.createFile(parent, changeSet, contents);

                    }
                })
                .addOnSuccessListener(this,
                        new OnSuccessListener<DriveFile>() {
                            @Override
                            public void onSuccess(DriveFile driveFile) {
                                Toast.makeText(getApplicationContext(), "File Saved", Toast.LENGTH_SHORT).show();
                            }
                        })
                .addOnFailureListener(this, new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Log.e(TAG, "Unable to create file", e);
                        Toast.makeText(getApplicationContext(), "Error!", Toast.LENGTH_SHORT).show();
                    }
                });
    }
}
private void createNewFile(){
最终文件File=getApplicationContext().getDatabasePath(“eventManager”);
如果(mDriveResourceClient!=null){
Log.i(标签“开始写入”);
最终任务rootFolderTask=mDriveResourceClient.getRootFolder();
最终任务createContentsTask=mDriveResourceClient.createContents();
Tasks.whenAll(rootFolderTask、createContentsTask)
.continueWithTask(新的continueWithTask>(){
@凌驾
然后公共任务(任务任务)引发异常{
Log.i(标记“写入任务已启动”);
DriveFolder parent=rootFolderTask.getResult();
DriveContents=createContentsTask.getResult();
OutputStream OutputStream=contents.getOutputStream();
试一试{
InputStream InputStream=新文件InputStream(文件);
字节[]buf=新字节[4096];
INTC;
而((c=inputStream.read(buf,0,buf.length))>0){
outputStream.write(buf,0,c);
}
}捕获(例外e){
Log.i(标记“写入任务失败”);
}最后{
outputStream.close();
}
MetadataChangeSet changeSet=新建MetadataChangeSet.Builder()
.setTitle(“我的文件”)
.setMimeType(“应用程序/x-sqlite3”)
.setStarred(真)
.build();
Log.i(标记“写入任务已启动”);
返回mDriveResourceClient.createFile(父级、变更集、内容);
}
})
.addOnSuccessListener(此,
新OnSuccessListener(){
@凌驾
成功时公共无效(驱动文件驱动文件){
Toast.makeText(getApplicationContext(),“文件已保存”,Toast.LENGTH\u SHORT.show();
}
})
.addOnFailureListener(此,新的OnFailureListener(){
@凌驾
public void onFailure(@NonNull异常e){
Log.e(标记“无法创建文件”,e);
Toast.makeText(getApplicationContext(),“Error!”,Toast.LENGTH\u SHORT.show();
}
});
}
}
错误:12-27 14:57:26.723 30393-30393/?E/main活动:无法创建文件 com.google.android.gms.common.api.ApiException:10:必须请求驱动器#范围(SCOPE)文件 位于com.google.android.gms.internal.zzbna.zza(未知来源) 位于com.google.android.gms.common.api.internal.zze.zza(未知来源) 位于com.google.android.gms.common.api.internal.zzbr.zzb(未知来源) 位于com.google.android.gms.common.api.internal.zzbr.zza(未知来源) 位于com.google.android.gms.common.api.internal.zzbp.handleMessage(未知来源) 位于android.os.Handler.dispatchMessage(Handler.java:98) 位于android.os.Looper.loop(Looper.java:148) 运行(HandlerThread.java:61)


你解决这个问题了吗