![](/img/trans.png)
[英]Launch my app from link in email, but link was filtered by gmail , How can I do ? ask for Help !
[英]How can I link a URL to launch my Android app?
在我的应用中,我想对共享功能进行编码,以允许用户共享他/她的帖子。
现在,假设我的朋友分享了他的帖子,我得到了链接。 如何获得该链接以在我的应用中启动? 以及我该如何选择参加哪个活动? 而且我如何获得链接,以便知道链接到哪个帖子?
我认为这是出于意图完成的,但是我不知道该怎么做。
试试这个,希望它对你有用
String url = "http://www.xample.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
为您的活动添加一个意图过滤器(在您的应用清单中):
<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:host="example.com"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
在此示例中,您的应用将处理所有以http://example.com/开头的链接
然后,在“活动”中,您可以通过这种方式阅读用于调用应用程序的URL:
Uri uri = getIntent()。getData();
这将返回如下内容: http : //example.com/link.php?post=1
使用uri的不同方法来获取所需的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.