无法获取文件夹在谷歌驱动器FOM android应用列表 [英] Can't get the list of folders in Google Drive fom android application
问题描述
我想进去我的谷歌驱动器文件夹列表中,
我已经注册了我的申请成功地和code上,直到 onConnected()
的方法,
这是code我用:
I'm trying to get the list of folders inside my google drive,
I have registered my application succesfully, and the code is running till onConnected()
method,
This is the code I used:
public class MainActivity extends Activity implements
ConnectionCallbacks, OnConnectionFailedListener {
Button btn1,btn2,btn_index;
EditText etxt1;
private GoogleApiClient mGoogleApiClient;
public TextView tvHttp,etxt2;
private ListView mResultsListView;
private ResultsAdapter mResultsAdapter;
//https://drive.google.com/folderview?id=0B42Bn9gPjvDHd3dvVE1sZGRQWjg&usp=sharing
public static String EXISTING_FOLDER_ID = "0B42Bn9gPjvDHd3dvVE1sZGRQWjg";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
///==============================================
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Plus.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
//=================================================
btn1=(Button)findViewById(R.id.button1);
btn2=(Button)findViewById(R.id.button2);
btn_index=(Button)findViewById(R.id.button3);
etxt1=(EditText)findViewById(R.id.editText1);
etxt2=(TextView)findViewById(R.id.TextView01);
tvHttp = (TextView) findViewById(R.id.textView1);
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
public void onConnectionFailed(ConnectionResult arg0) {
// TODO Auto-generated method stub
etxt2.setText("connection failed !!!");
}
@Override
public void onConnected(Bundle arg0) {
super.onCreate(arg0);
// TODO Auto-generated method stub
etxt2.setText("connection success !!!");
setContentView(R.layout.activity_main);
mResultsListView = (ListView) findViewById(R.id.listViewResults);
mResultsAdapter = new ResultsAdapter(this);
mResultsListView.setAdapter(mResultsAdapter);
Drive.DriveApi.fetchDriveId(mGoogleApiClient, EXISTING_FOLDER_ID)
.setResultCallback(idCallback);
}
final private ResultCallback<DriveIdResult> idCallback = new ResultCallback<DriveIdResult>() {
@Override
public void onResult(DriveIdResult result) {
if (!result.getStatus().isSuccess()) {
//showMessage("Cannot find DriveId. Are you authorized to view this file?");
return;
}
DriveFolder folder = Drive.DriveApi.getFolder(mGoogleApiClient, result.getDriveId());
folder.listChildren(mGoogleApiClient)
.setResultCallback(metadataResult);
}
};
final private ResultCallback<MetadataBufferResult> metadataResult = new
ResultCallback<MetadataBufferResult>() {
@Override
public void onResult(MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
//showMessage("Problem while retrieving files");
return;
}
mResultsAdapter.clear();
mResultsAdapter.append(result.getMetadataBuffer());
//showMessage("Successfully listed files.");
}
};
}
如果我在执行 onConnected
方法仅第一行, etxt2.setText(连接成功!);
,我有消息:连接成功!,这意味着连接成功,但是当我尝试执行剩下来获取文件夹的名字,我得到这个错误:
If I execute just the first line in onConnected
Method, etxt2.setText("connection success !!!");
, I have the message : "connection success !!!", which means that the link is successful, but when I try to execute the rest to get the name of the folders I get this error:
05-16 11:49:24.553: E/AndroidRuntime(3782): FATAL EXCEPTION: main
05-16 11:49:24.553: E/AndroidRuntime(3782): Process: com.example.first_app, PID: 3782
05-16 11:49:24.553: E/AndroidRuntime(3782): java.lang.NullPointerException: Appropriate Api was not requested.
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.internal.er.b(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.common.api.b.a(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.common.api.b.a(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.common.api.b.b(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.common.api.b.a(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.drive.internal.l.fetchDriveId(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.example.first_app.MainActivity.onConnected(MainActivity.java:293)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.internal.ei.b(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.common.api.b.dy(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.common.api.b.d(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.common.api.b$2.onConnected(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.internal.ei.b(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.internal.ei.bo(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.internal.eh$h.b(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.internal.eh$h.a(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.internal.eh$b.ec(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.google.android.gms.internal.eh$a.handleMessage(Unknown Source)
05-16 11:49:24.553: E/AndroidRuntime(3782): at android.os.Handler.dispatchMessage(Handler.java:102)
05-16 11:49:24.553: E/AndroidRuntime(3782): at android.os.Looper.loop(Looper.java:136)
05-16 11:49:24.553: E/AndroidRuntime(3782): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-16 11:49:24.553: E/AndroidRuntime(3782): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 11:49:24.553: E/AndroidRuntime(3782): at java.lang.reflect.Method.invoke(Method.java:515)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-16 11:49:24.553: E/AndroidRuntime(3782): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-16 11:49:24.553: E/AndroidRuntime(3782): at dalvik.system.NativeStart.main(Native Method)
任何帮助将AP preciated,在此先感谢。
any help will be appreciated, thanks in advance.
推荐答案
随着错误消息表示不要求相应的API。你是不是要求你GoogleApiClient正确的API。您需要包括Drive.API
As the error message indicates "Appropriate Api was not requested". You are not requesting the correct API in your GoogleApiClient. You need to include Drive.API
这篇关于无法获取文件夹在谷歌驱动器FOM android应用列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!