[英]How can I link a URL to launch my Android app?
In my app, I want to code a share feature to allow the user to share his/her post. 在我的应用中,我想对共享功能进行编码,以允许用户共享他/她的帖子。
Now let's say my friend shared his post and I got the link. 现在,假设我的朋友分享了他的帖子,我得到了链接。 How can I get that link to launch in my app? 如何获得该链接以在我的应用中启动? And how do I choose which activity it goes to? 以及我该如何选择参加哪个活动? And how do I get the link so I know which post it's linking to? 而且我如何获得链接,以便知道链接到哪个帖子?
I think this is done with intents, but I have no idea how to do it. 我认为这是出于意图完成的,但是我不知道该怎么做。
Try this, hope it will work for you 试试这个,希望它对你有用
String url = "http://www.xample.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Add an intent-filter for your Activity (in the Manifest of your app): 为您的活动添加一个意图过滤器(在您的应用清单中):
<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>
In this example, your app will handle all links which starts with http://example.com/ 在此示例中,您的应用将处理所有以http://example.com/开头的链接
Then, in your Activity, this way you can read the URL which was used to call your app: 然后,在“活动”中,您可以通过这种方式阅读用于调用应用程序的URL:
Uri uri = getIntent().getData(); Uri uri = getIntent()。getData();
This will return something like this: http://example.com/link.php?post=1 这将返回如下内容: http : //example.com/link.php?post=1
Use the different methods of uri to get the required information. 使用uri的不同方法来获取所需的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.