Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Launch a Google Drive application from another application not uploaded file

I tried to upload a file from my android application by manually launching Google drive (installed on the device). I tried this to send using Intent.createChooser and its working fine for uploading file attachment. But I need to upload file for specific intent (like Dropbox, Google drive only). So I changed the code and tried to upload a file to Google drive as following ways, but no success, only Google drive app is open on device, no file uploaded:

PackageManager pm = this.getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.google.android.apps.docs");
intent.setType("application/pdf");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/sdcard0/test.pdf"));
intent.putExtra(Intent.EXTRA_SUBJECT, "attach a file test");
intent.addCategory(Intent.ACTION_ATTACH_DATA);
startActivity(intent);

Can we upload a PDF file by opening the intent manually as above?

like image 640
user2459928 Avatar asked Jun 06 '13 14:06

user2459928


People also ask

Can an Android app launch another app?

In android, we can lunch other applications using packing name. This example demonstrate about How to Launch an application from another application on Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

Can an APK be uploaded to Google Drive?

You can upload your apk to Google Drive, right click file on Google Drive -> share this file to your client. Then after your client download successfully, you can delete this file from your Google Drive for safe.


1 Answers

I got the solution for executing following code after research:

import android.support.v4.app.ShareCompat;

Uri pdfUri = Uri.parse("file://sdcard/sdcard0/test.pdf");                
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
                                     .setText("Share PDF doc")
                                         .setType("application/pdf")
                                         .setStream(pdfUri )
                                         .getIntent()
                                 .setPackage("com.google.android.apps.docs");
startActivity(shareIntent);

Similarly we can use for other share intent and the corresponding package name of few intents are as below:

  • com.dropbox.android = Dropbox
  • com.android.bluetooth = Bluetooth
  • com.android.email = Email
  • com.google.android.gm = Gmail
  • com.microsoft.skydrive = Skydrive
  • com.google.android.apps.docs = Googledrive

For gmail sharing we need to use following type of code:

Uri zipUri = Uri.parse("file://sdcard/sdcard0/test.zip");  
String[] emailArr = {"[email protected]"};              
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
                                  .setText("Share ZIP doc")
                                  .setType("application/zip")
                                  .setEmailTo(emailArr)
                                  .setStream(zipUri)
                                  .setSubject("Share zip doc")
                                  .setText("Sent with email app.")
                                  .getIntent()
                           .setPackage("com.google.android.gm");
startActivity(shareIntent);
like image 188
user2459928 Avatar answered Oct 08 '22 15:10

user2459928