安卓:过滤意图特定URI模式意图、模式、URI

2023-09-12 04:40:21 作者:单身快乐i

我需要我的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:

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