将intent filter manifest转换为intent filter java

时间:2014-09-05 04:44:38

标签: android android-intent intentfilter

我在Android清单中写了这个意图过滤器并且是正确的,但我想转换这个意图过滤器,以便在Android服务中,我从android清单中删除意图过滤器。

   <intent-filter>
       <action android:name="android.intent.action.VIEW" />
       <category android:name="android.intent.category.DEFAULT" />
       <category android:name="android.intent.category.BROWSABLE" />
       <data android:scheme="http" />
       <data android:scheme="https" />
       <data android:host="*" />
       <data android:pathPattern=".*\\.zip" />
       <data android:pathPattern=".*\\.zip.*" />
   <intent-filter>

我在java中编写了这些代码但是没有工作意图并从默认下载管理器开始:(

    MyReceiver mReceiver = new MyReceiver();//this is a BrodcastReciver class
    IntentFilter f = new IntentFilter();
    f.addAction("android.intent.action.VIEW");
    f.addCategory("android.intent.category.DEFAULT");
    f.addCategory("android.intent.category.BROWSABLE");
    f.addDataScheme("http");
    f.addDataScheme("https");
    f.addDataAuthority("*", null);
    f.addDataPath(".*\\.zip",PatternMatcher.PATTERN_SIMPLE_GLOB);
    f.addDataPath(".*\\.zip.*", PatternMatcher.PATTERN_SIMPLE_GLOB);
    Log.e("intent and brodcast", "seved");
    registerReceiver(mReceiver, f);

问题是什么? 请帮帮我

罐;)

1 个答案:

答案 0 :(得分:0)

在Java文件中使用Intent过滤器时,在其中添加 createchooser()属性。

在启动操作时,添加以下行:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
...

// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(sendIntent, title);

// Verify the original intent will resolve to at least one activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
    startActivity(chooser);
}

通过添加此代码,您将能够在要使用的任何浏览器中启动操作。