简体   繁体   English

如何链接URL以启动我的Android应用程序?

[英]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.

相关问题 从 email 中的链接启动我的应用程序,但链接已被 gmail 过滤,我该怎么办? 请求帮忙 ! - Launch my app from link in email, but link was filtered by gmail , How can I do ? ask for Help ! 如何从链接启动我的Android / IOS应用 - How to launch my Android / IOS app from a link 如何在启动 android 应用程序时启动特定片段 - How can I launch specific fragment at launch android app Android - 如何将我的免费应用程序链接到专业版 - Android - How can I link my free app to the Pro version 如何将Android上的Google帐户链接到我的应用程序? - How can I link the Google account on the android to my app? 如何使用自定义链接打开我的 Android 应用程序? - How can I open my Android app with a custom link? 我可以将Skype与我的Android应用程序链接吗? - Can I link Skype with my Android App? 如何通过电子邮件中的自定义URL启动我的应用 - How do I launch my app via a custom URL in an email 当我尝试从网站上的链接启动应用程序时,Android http URL方案不起作用 - Android http URL scheme is not working when I try to launch my application from a link on my website 我可以从我的应用程序中启动android应用程序吗? - Can I launch android apps from within my app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM