如何创建可以在Android中“共享”网址的应用?

时间:2022-02-10 07:10:31

Please can someone explain in Plain English how I create an app that Android can then offer as a target if I "Share" a URL from within the device's browser?

如果我在设备的浏览器中“共享”一个URL,那么有人可以用普通英语解释我如何创建一个Android可以作为目标提供的应用程序吗?

I'm finding Google's official SDK documentation near-impenetrable, and (so far) lacking in any real world examples relevant to passing a URL from the browser into another application. :-(

我发现谷歌的官方SDK文档几乎无法穿透,并且(到目前为止)缺少与将浏览器中的URL传递到另一个应用程序相关的任何现实示例。 :-(

I would be really grateful for any advice people might be able to offer; feels like I'm slamming my head against a big, green, brick wall right about now.

对于人们可能提出的任何建议,我将非常感激;感觉就像我现在正撞在一个绿色的大砖墙上。

Thanks in advance!

提前致谢!

2 个解决方案

#1


1  

You want to create an application that can handle ACTION_SEND intents and then register an intent filter in your AndroidManifest.xml file. I copied the following example from Android's default Mms application's manifest:

您想要创建一个可以处理ACTION_SEND意图的应用程序,然后在AndroidManifest.xml文件中注册一个意图过滤器。我从Android的默认Mms应用程序清单中复制了以下示例:

<activity android:name=".ui.ComposeMessageActivity"
    android:configChanges="orientation|keyboardHidden"
    android:windowSoftInputMode="stateHidden"
    android:launchMode="singleTop" >
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
    </intent-filter>
    <!-- ... -->
</activity>

#2


-1  

Needed to implement it in a simple way in my application and decided as follows:

需要在我的应用程序中以简单的方式实现它并决定如下:

String strUrl = "http://example.com";
Intent shareUrl = new Intent(Intent.ACTION_SEND);
shareUrl.setType("text/plain");
shareUrl.putExtra(android.content.Intent.EXTRA_TEXT, strUrl);
startActivity(Intent.createChooser(shareURL,"Share with..."));

This is the simplest way that you can do to share some content of your app with other apps on your device. Practical and functional.

这是您与设备上的其他应用分享应用内容的最简单方法。实用和功能。

#1


1  

You want to create an application that can handle ACTION_SEND intents and then register an intent filter in your AndroidManifest.xml file. I copied the following example from Android's default Mms application's manifest:

您想要创建一个可以处理ACTION_SEND意图的应用程序,然后在AndroidManifest.xml文件中注册一个意图过滤器。我从Android的默认Mms应用程序清单中复制了以下示例:

<activity android:name=".ui.ComposeMessageActivity"
    android:configChanges="orientation|keyboardHidden"
    android:windowSoftInputMode="stateHidden"
    android:launchMode="singleTop" >
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
    </intent-filter>
    <!-- ... -->
</activity>

#2


-1  

Needed to implement it in a simple way in my application and decided as follows:

需要在我的应用程序中以简单的方式实现它并决定如下:

String strUrl = "http://example.com";
Intent shareUrl = new Intent(Intent.ACTION_SEND);
shareUrl.setType("text/plain");
shareUrl.putExtra(android.content.Intent.EXTRA_TEXT, strUrl);
startActivity(Intent.createChooser(shareURL,"Share with..."));

This is the simplest way that you can do to share some content of your app with other apps on your device. Practical and functional.

这是您与设备上的其他应用分享应用内容的最简单方法。实用和功能。