安卓:过滤意图特定URI模式 [英] Android: Filter intent for specific Uri pattern

查看:122
本文介绍了安卓:过滤意图特定URI模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的Andr​​oid应用程序在我的应用程序运行有一定的活动,从已发出的意图响应以下URI数据:

I need my Android application to run a certain Activity in my app, responding to the following Uri data from the Intent that was sent out:

<一个href="http://www.example.com/redirect.aspx?customurl=example%3a%2f%2f%3fop%3dexampledetail%26stuff%3d12345%26morestuff%3dI%2520Love%25Android" rel="nofollow">http://www.example.com/redirect.aspx?customurl=example%3a%2f%2f%3fop%3dexampledetail%26stuff%3d12345%26morestuff%3dI%2520Love%25Android

如果我用我的清单如下(为我想的意图做出反应的活动),我可以捕捉到这些,而是​​选择器弹出(这我不希望):

If I use the following in my manifest (for the Activity that I want to respond to the Intent), I can capture this, but the chooser pops up (which I don't want):

<intent-filter>
 <action android:name="android.intent.action.VIEW" />
 <data android:scheme="http" android:host="www.example.com" />
 <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

因为我不想选择器弹出,我试着使用android:pathPattern或Android:路径preFIX在标签来进一步过滤,以确保只有我的应用程序的响应,但它不是'牛逼为我工作。

Since I don't want the chooser to pop up, I tried to use the android:pathPattern, or android:pathPrefix in the tag to further filter to make sure that only my app responds but it isn't working for me.

谁能帮我做到这一点?

推荐答案

它看起来像您处理数据时,它来自于你自己的应用程序,所以不要用你的私人的网址为目的的目标,但创建部分特定意图,并给它的数据的URL作为一个额外的参数。

It looks like your dealing with data which comes from your own application, so don't use your "private" URL as the target of the intent but create a component specific Intent and give it the URL of your data as an EXTRA parameter.

是这样的:

Uri privateUri = Uri.parse("http://yourserver.com/path/to/data");
Intent i = new Intent(context, yourActivity.class);
i.putExtra("DATA_URI", privateUri);
startActivity(i);

在yourActivity.class,你只需要得到URI具有以下code:

In yourActivity.class, you would just have to get the Uri with the following code:

Uri privateUri = (Uri) getIntent().getParcelableExtra("DATA_URI");

这篇关于安卓:过滤意图特定URI模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆