我們想知道是否可以在應用程序的活動中獲取所有可用的附加內容。 我們正在製作一個Android應用程序,用於顯示上傳文件的Google雲端硬盤活動的明確意圖,選擇Gmail帳戶和Google雲端硬盤文件夾。Android:獲取Google雲端硬盤活動的所有可用附加內容
我們需要我們的應用程序選擇文件夾和帳戶,而不是用戶(用戶可以選擇它容易地挑選可用的文件夾和帳戶,但我們不需要它)。
我們看到哪些附加組件可以添加到意圖中,但唯一額外的與Google雲端硬盤活動「互動」的是額外的EXTRA_STREAM,它提供了我們想要上傳的文件流: http://developer.android.com/reference/android/content/Intent.html#EXTRA_STREAM
我們也看到存在梅託德intent.getExtras(),它返回一個地圖(束)絲毫的意圖所有的臨時演員,但也有之前添加的所有演員,而不是可獲取的。
我們沒有發現更多可與Google雲端硬盤活動交互的標準附加功能,但爲了使此功能(不幸的是,Google雲端硬盤應用程序不是開源的)可能是應用程序的源代碼已定義了額外功能。
這是我們的代碼現在:
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "MESSAGE";
private void error(String message){
Intent intent = new Intent(this, DisplayMessageActivity.class);
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
public void sendMessage(View view){
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String rootPath = Environment.getExternalStorageDirectory().getPath();
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(rootPath.concat("/rev.txt")));
intent.putExtra(Intent.EXTRA_SUBJECT, "asunto");
intent.putExtra(Intent.EXTRA_TEXT, "text");
String[] emails = new String[4];
emails[0] = "[email protected]";
intent.putExtra(Intent.EXTRA_EMAIL, emails);
List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);
System.out.println(apps.size());
if (apps.size()>0) {
ResolveInfo ri;
for (Iterator<ResolveInfo> it = apps.iterator(); it.hasNext();) {
ri = it.next();
System.out.println(ri.toString());
}
ComponentName component = new ComponentName("com.google.android.apps.docs",
"com.google.android.apps.docs.shareitem.UploadSharedItemActivity");
intent.setComponent(component);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
System.out.println("NON ATOPO O DRIVE");
error("NON ATOPO O DRIVE");
}
}
else {
System.out.println("non hai aplicacions");
error("non hai aplicacions");
}
}
}
好的,謝謝你的信息。 – Santiago