如何在安卓中创建可在 Android 中"Share" URL 的应用?



请有人用简单的英语解释我如何创建一个应用程序,Android可以然后提供作为目标,如果我从设备的浏览器内"共享"一个URL ?

我发现Google的官方SDK文档几乎难以理解,并且(到目前为止)缺乏任何与将URL从浏览器传递到另一个应用程序相关的实际示例。: -

我将非常感激任何人可能提供的任何建议;感觉就像我的头撞上了一堵巨大的绿色砖墙。

提前感谢!

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

<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>

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

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..."));

这是与设备上的其他应用程序共享应用程序内容的最简单方法。

最新更新