droid的启动从另一个应用程序没有上传文件中的谷歌应用程序驱动

droid的启动从另一个应用程序没有上传文件中的谷歌应用程序驱动

本文介绍了Android的启动从另一个应用程序没有上传文件中的谷歌应用程序驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过手工启动谷歌驱动器(安装在设备上)上载从我的Andr​​oid应用程序的文件。我试图用这个 Intent.createChooser 及其工作正常上传文件附件来发送。但我需要上传特定意图的文件(如Dropbox的,谷歌只驱动器)。所以我改变了code,并试图文件到谷歌驱动器上传为以下几个方面,但没有成功,只有谷歌驱动程序是在设备上打开的,没有文件上传:

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);

我们可以通过手动打开的意图如上上传PDF文件?

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

推荐答案

我的研究后,执行以下code解决方案:

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 =蓝牙

  • com.android.email =电子邮件

  • com.google.android.gm =的Gmail

  • com.microsoft.skydrive = SkyDrive中

  • com.google.android.apps.docs = Google云端硬盘

有关Gmail的共享,我们需要使用以下类型code的:

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);

这篇关于Android的启动从另一个应用程序没有上传文件中的谷歌应用程序驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 00:45