简体   繁体   English

使用 Intent ACTION_SEND 将数据从锚链接共享到特定应用

[英]Use intent ACTION_SEND to sharing data from anchor link to specific app

I want to share data from my website to Android app using a single link.我想使用单个链接将数据从我的网站共享到 Android 应用程序。 For example when user click on the below link: <a href="intent://SEND/#Intent;scheme=tg;package=org.telegram.messenger;S.EXTRA_TEXT='some text';end"> Share... </a> the browser launch Telegram app and ask user to select a contact to send EXTRA_TEXT to him/her.例如,当用户点击以下链接时: <a href="intent://SEND/#Intent;scheme=tg;package=org.telegram.messenger;S.EXTRA_TEXT='some text';end"> Share... </a>浏览器启动 Telegram 应用程序并要求用户选择一个联系人以向他/她发送 EXTRA_TEXT。 But the above code only open the telegram app and doesn't pass the EXTRA_TEXT to app.但是上面的代码只打开了电报应用程序,并没有将 EXTRA_TEXT 传递给应用程序。

I found this guide but this is JAVA and I don't know how to use this code in a link:我找到了本指南,但这是 JAVA,我不知道如何在链接中使用此代码:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

Put the data scheme and parameters in the anchor tag.将数据方案和参数放在锚标签中。
For eg:例如:

myappschema://?token=123 myappschema://?token=123

where it will send token to the myappschema.它将向 myappschema 发送令牌。

In the AndroidManifest of your app;在您的应用程序的 AndroidManifest 中; put this intent filter on your activity which you wish to open from web.将此意图过滤器放在您希望从网络打开的活动上。

<intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.APP_BROWSER" />
                <data android:scheme="myappschema" />
</intent-filter>

Inside your activity;在您的活动中; you can fetch data from Intent.你可以从 Intent 中获取数据。 eg: Uri data =getIntent().getData();例如: Uri data =getIntent().getData();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM