I’m trying to create an Android application so that the user can browse and select files from their Google Drive.
I am completely new to Android, and I tried to use samples. When I launch the APK on my phone, authentication seems to work fine, but I'm not sure how to retrieve and display Drive folders.
- How can they be found?
- What should they appear in (
ListView?) So that users can navigate through files?
My onConnected code is working fine, but I think the problem is with DriveId not populating correctly.
@Override
public void onConnected(Bundle connectionHint) {
Log.i(TAG, "API client connected.");
super.onCreate(connectionHint);
setContentView(R.layout.activity_listfiles);
mResultsListView = (ListView) findViewById(R.id.listViewResults);
mResultsAdapter = new ResultsAdapter(this);
mResultsListView.setAdapter(mResultsAdapter);
Drive.DriveApi.fetchDriveId(getGoogleApiClient(), EXISTING_FOLDER_ID)
.setResultCallback(idCallback);
}
I have a layout called "activity_listfiles.xml". On this layout, it's just a ListView called: @ id / listViewResults
, DriveID: DriveId. ?
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(getGoogleApiClient(), result.getDriveId());
folder.listChildren(getGoogleApiClient())
.setResultCallback(metadataResult);
}
};
- ? :
https://github.com/googledrive/android-demos/tree/master/src/com/google/android/gms/drive/sample/demo
java ResultsAdapter, , :
public class ResultsAdapter extends DataBufferAdapter<Metadata> {
public ResultsAdapter(Context context) {
super(context, android.R.layout.simple_list_item_1);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = View.inflate(getContext(),
android.R.layout.simple_list_item_1, null);
}
Metadata metadata = getItem(position);
TextView titleTextView =
(TextView) convertView.findViewById(android.R.id.text1);
titleTextView.setText(metadata.getTitle());
return convertView;
}
}
, String EXISTING_FOLDER_ID BaseActivity.java, :
public static final String EXISTING_FOLDER_ID = "0B2EEtIjPUdX6MERsWlYxN3J6RU0";
, - ?
:
EXISTING_FOLDER_ID = Drive.DriveApi.getRootFolder(getGoogleApiClient()).getDriveId().toString();
showMessage(EXISTING_FOLDER_ID);
Drive.DriveApi.fetchDriveId(getGoogleApiClient(),EXISTING_FOLDER_ID)
.setResultCallback(idCallback);
showMessage DOES , , - - "Can not find DriveID".
, fetchDriveID ?