【问题标题】:Android: obtaining the all available intent extras of a Google Drive activityAndroid:获取 Google Drive 活动的所有可用 Intent Extra
【发布时间】:2012-10-29 20:40:40
【问题描述】:

我们想知道是否有可能在应用程序的活动中获取所有可用的 Intent Extra。 我们正在做一个 Android 应用程序,它对上传文件的 Google Drive 活动做出明确的意图,选择 gmail 帐户和 Google Drive 文件夹。

我们需要我们的应用程序选择文件夹和帐户,而不是用户(用户可以在可用的文件夹和帐户中轻松选择它,但我们不想要它)。

我们正在查看可以在 Intent 中添加哪些额外内容以执行此操作,但与 Google Drive 活动“交互”的唯一额外内容是额外的 EXTRA_STREAM,它提供了我们要上传的文件流: http://developer.android.com/reference/android/content/Intent.html#EXTRA_STREAM

我们还看到存在一个方法 intent.getExtras(),它返回一个包含意图的所有额外内容的地图(捆绑包),但是之前添加的所有额外内容,而不是可用的。

我们没有找到更多与 Google Drive 活动交互的标准附加功能,但可能应用程序的源代码已经定义了附加功能以实现这一点(不幸的是,Google Drive 应用程序不是开源的)。

这是我们现在拥有的代码:

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

  }
}

【问题讨论】:

    标签: android android-intent google-drive-api


    【解决方案1】:

    我们想知道是否有可能在应用程序的活动中获取所有可用的 Intent Extra。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多