1

We want to know if is possible obtain all the available intent extras in an activity of an application. We are doing an Android application that make an explicit intent to the Google Drive activity that upload a file, selecting the gmail account and a Google Drive folder.

We need the our application select the folder and the account, not the user (the user would can select it easyly picking in the available folders and accounts, but we not want it).

We were seeing which extras can add in the intent in order to do that, but the unique extra that "interact" whit the Google Drive activity is the extra EXTRA_STREAM, which provides the stream of the file that we want to upload: http://developer.android.com/reference/android/content/Intent.html#EXTRA_STREAM

We see also that exists a metod intent.getExtras(), which return a map (Bundle) whit all the extras of an intent, but there are all the extras previously added, not the availables.

We not find more standard extras that interact whit the Google Drive activity, but probably the source code of the application have defined extras in order to make this (unfortunately the Google Drive application is not open source).

This is the code we have for now:

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] = "aa@gmail.com";
   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");
    }

  }
}
4

1 回答 1

0

我们想知道是否有可能在应用程序的活动中获得所有可用的意图附加信息。

阅读相关活动作者提供的文档。如果没有此类文档,请不要开始活动。

如果您希望能够以编程方式收集有关支持的附加功能的信息,那是不可能的。

于 2012-10-29T20:50:07.033 回答