我可以通过浏览器的HTML页面链接广播自定义意图吗? [英] can i Broadcast custom intent through my HTML page link from browser?
问题描述
当我点击浏览器中的HTML页面链接时,我想广播自定义的意图。我知道android系统会为此播放android.intent.action.VIEW,我可以在我的应用程序中收到这个,但这样做会列出我的应用程序的每个可点击的链接,所以我想广播我的自定义意图操作。
我已经通过以下方式解决了这个问题:
line
< a href =intent://example.com/test?id = 12345#Intent; scheme = myapp ; package = com.mypackage; end>直接打开您的应用程序< / a>
这里example.com/test?id=12345
可以是任何你想要的东西,这将在我们的 onCreate()
方法中以我们的意图数据的形式传递,所以我给出了例如id。
scheme
可以是我们需要在我们的menifest.xml中为intent-filter编写相同方案的任何字符串
软件包
是您的应用软件包名称,以便将其与其他应用程序区分开来b $ b
注意:如果app没有安装在设备上,它会从AndroidMenifest中给定的有效包名称
打开google playstore .xml文件
< intent-filter>
< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< intent-filter>
< category android:name =android.intent.category.DEFAULT/>
< category android:name =android.intent.category.BROWSABLE/>
< data android:scheme =myapp/>
< / intent-filter>
您可以添加意图过滤器来执行任何我给予启动器活动的活动
注意< data android:scheme =myapp/>
方案名称必须与之前在HTML文件中给出的相同。
完成!在设备的任何浏览器中打开html文件您可以在您的活动的 onCreate()
方法中获取意图数据。
Intent intent = getIntent();
if(intent!= null&& amp; intent.getData()!= null){
Uri data = intent.getData();
String path = data.getPath();
String id = data.getQueryParameter(id);
Log.d(ID,:+ id);
}
I want to broadcast my custom intent when i click a link of my html page from browser. I know android system will broadcast "android.intent.action.VIEW" for this and i can receive this in my application but doing this will list my application for every clickable link so i want to broadcast my custom intent action.
I have solved this by following
create test.html file with this single line
<a href="intent://example.com/test?id=12345#Intent;scheme=myapp;package=com.mypackage;end">Open Your Application Directly</a>
Here "example.com/test?id=12345"
can be any thing you want this will be passed as intent data in our in our onCreate()
method so i have given id for example.
"scheme"
can be any string we need to write same scheme in our menifest.xml for intent-filter
"package"
is your app package name to differentiate it from other app with same scheme
Note : If app is not installed in device then it will open google playstore from given valid package name
in AndroidMenifest.xml file
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="myapp" />
</intent-filter>
you can add intent filter for any activity i have given to launcher activity
note the <data android:scheme="myapp" />
scheme name must be same as given in HTML file before.
Done! open html file in any browser of your device & click on link it will directly open your app.
You can get intent data in your activity's onCreate()
method like
Intent intent = getIntent();
if (intent != null && intent.getData() != null) {
Uri data = intent.getData();
String path = data.getPath();
String id = data.getQueryParameter("id");
Log.d("ID", ": " + id);
}
这篇关于我可以通过浏览器的HTML页面链接广播自定义意图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!