我正尝试使用https://developers.google.com/drive/android/files#making_modifications中提供的程序将数据附加到Google云端硬盘上的现有文件中
虽然控制正常但没有变化反映在文件中.
public void addHistoryEntry(final String location) {
final DriveFile file = Drive.DriveApi.getFile(getClient(), historyFileId);
file.open(getClient(), DriveFile.MODE_READ_WRITE, null)
.setResultCallback(new ResultCallback<DriveContentsResult>() {
@Override
public void onResult(DriveContentsResult driveContentsResult) {
if (!driveContentsResult.getStatus().isSuccess()) {
L.c("Problem in Writing to file");
return;
}
DriveContents contents = driveContentsResult.getDriveContents();
try {
ParcelFileDescriptor parcelFileDescriptor = contents.getParcelFileDescriptor();
FileInputStream fileInputStream = new FileInputStream(parcelFileDescriptor.getFileDescriptor());
// Read to the end of the file.
fileInputStream.read(new byte[fileInputStream.available()]);
// Append to the file.
FileOutputStream fileOutputStream = new FileOutputStream(parcelFileDescriptor
.getFileDescriptor());
Writer writer = new OutputStreamWriter(fileOutputStream);
writer.write(location+"\n"); …Run Code Online (Sandbox Code Playgroud) 我正在使用以下链接中提供的适用于 Google Drive Rest APi 的Android 快速入门。安卓快速入门
示例代码按原样运行良好。但是,当我尝试从文件中获取其他详细信息时,例如getCreatedTime()或GetWevViewLink()'null' 被返回。只有 getName() 和 getId() 返回值。
android google-api google-drive-api google-drive-android-api
在我的应用程序中,用户可以从相机和图库中选择图像以加载到ImageView中。
我正在使用以下代码打开相关的应用程序以选择图像:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
Run Code Online (Sandbox Code Playgroud)
问题出在Google硬盘上。如果用户从Google云端硬盘中选择图片,则我将获得这样的URI:content://com.google.android.apps.docs.storage.legacy/enc%3DHxtpLaMr66OMOzDOKTRZ-5ed7q7Szj7F7nC0IlxBnV8hx2P1%0A
我能够生成位图,但无法获取文件名。
InputStream input = context.getContentResolver().openInputStream(uri);
Bitmap bitmap = BitmapFactory
.decodeStream(input);
Run Code Online (Sandbox Code Playgroud)
我需要显示用户选择的文件名。
请帮我从Google驱动器URI中提取图片名称。
android android-imageview google-drive-api android-bitmap google-drive-android-api
我试图以编程方式获取我的谷歌驱动器中的文件夹名称,并在文件夹内创建一个文件夹,但没有办法。
\n\n我已经查看了这个文档:
\n\n\n\n但如何获取特定文件夹并在其中创建另一个文件夹?以编程方式,而不是通过助手。
\n\n好的。我需要将位图更新到谷歌驱动器。我尝试使用这段代码但不起作用
\n\n String IdFolder = (String) objects[0];\n Bitmap bitmapUpload = (Bitmap) objects[1];\n\n File fileMetadata = new File();\n fileMetadata.setTitle("photo.jpg");\n fileMetadata.setParents(Collections.singletonList(new ParentReference().setId(IdFolder)));\n\n File file = mService.files().insert(fileMetadata, bitmapUpload)\n .setFields("id, parents")\n .execute();\n System.out.println("File ID: " + file.getId());\nRun Code Online (Sandbox Code Playgroud)\n\n我已经尝试过这个:
\n\n String IdFolder = (String) objects[0];\n Bitmap bitmapUpload = (Bitmap) objects[1];\n\n int byteSize = bitmapUpload.getRowBytes() * bitmapUpload.getHeight();\n ByteBuffer byteBuffer = ByteBuffer.allocate(byteSize);\n bitmap.copyPixelsToBuffer(byteBuffer);\n\n\n byte[] byteArray = byteBuffer.array();\n\n\n ByteArrayInputStream bs = new ByteArrayInputStream(byteArray);\n\n File fileMetadata …Run Code Online (Sandbox Code Playgroud) public class Helpers extends Activity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
SharedPreferences preferences;
private static final String TAG = "BaseDriveActivity";
public static String EXISTING_FOLDER_ID;
protected static final int REQUEST_CODE_RESOLUTION = 1;
protected static final int NEXT_AVAILABLE_REQUEST_CODE = 2;
public static final String folderId = "FOLDER_ID";
public static final String fileName = "folderId";
private GoogleApiClient mGoogleApiClient;
@Override
protected void onResume() {
super.onResume();
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build(); …Run Code Online (Sandbox Code Playgroud) android google-drive-api google-play-services google-drive-android-api
我试图将谷歌驱动器图像链接设置为图像视图,但它显示为空白.我尝试了很多方法,我也使用了Glide库.如果我使用示例在线网址它正在工作.这是我的链接. https://drive.google.com/file/d/18F2oNjVUmyX7Kez5r7A6tOlrN0u5oZOr/edit
如何解决这个请帮助我.