将Intent连接到intent-filters

时间:2013-09-26 16:47:58

标签: android android-intent

我在Oracle的VirtualBox中使用VM =“WSVGA 7.0 Tablet - 4.2.2 - API17”进行测试

我无法使用此代码使用Intent连接到应用程序:

  Intent intent = new Intent("com.estrongs.action.PICK_FILE");
  Intent intent = new Intent("com.example.filechooser.PICK_DIRECTORY");
    //      intent.setDataAndTypeAndNormalize(Uri.parse("file://"), "*/*"); 
            //No Activity found to handle Intent { act=com.estrongs.action.PICK_FILE  dat=file:// typ=*/* }
            //No Activity found to handle Intent { act=com.estrongs.action.PICK_FILE  }
    //      intent.setType("*/*");
            //No Activity found to handle Intent { act=com.estrongs.action.PICK_FILE  typ=file/* }
            //No Activity found to handle Intent { act=com.estrongs.action.PICK_FILE  typ=*/* }  
            //  NOTE:  Extra space at end of action  above.  removed below
            //No Activity found to handle Intent { act=com.estrongs.action.PICK_FILE typ=*/* }
            //No Activity found to handle Intent { act=com.example.filechooser.PICK_DIRECTORY typ=*/* }
            //No Activity found to handle Intent { act=com.example.filechooser.PICK_DIRECTORY }
    //      startActivityForResult(intent, FolderChosen);
>

来自我的AndroidManifest.xml:

  

   <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <action android:name="android.intent.action.SEND" />
      <action android:name="android.intent.action.GET_CONTENT" />
      <category android:name="android.intent.category.OPENABLE" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:mimeType="*/*" />
  </intent-filter>

  <intent-filter>
       <action android:name="com.example.filechooser.PICK_DIRECTORY" />
  </intent-filter>
     

&GT; 我确实让这个工作:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setDataAndTypeAndNormalize(Uri.parse(“file://”),“ / ”); // file:// WORKED

// onCreate intent=Intent { act=android.intent.action.GET_CONTENT dat=file:// typ=*/* 
//      flg=0x3000000 cmp=com.example.filechooser/.FileChooser }  <<<<<<<<<<<<<NOTE:  WORKED 

我应该如何编写可以由以下意图选择的intent-filter:

  

Intent intent = new Intent(“com.estrongs.action.PICK_FILE”);      Intent intent = new Intent(“com.example.filechooser.PICK_DIRECTORY”);

1 个答案:

答案 0 :(得分:2)

<intent-filter>
    <action android:name="com.estrongs.action.PICK_FILE" />
    <action android:name="com.example.filechooser.PICK_DIRECTORY" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.OPENABLE" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

我假设您接受所有MIME类型,因为您的元素包含“ / ”,所以我建议您省略该元素。默认情况下,如果不存在过滤器元素(即),Android将匹配任何值。