1

我将我的应用程序设置为使用这些意图过滤器和此处理程序接收共享意图。我在共享菜单中没有看到它。

<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http"/>
</intent-filter>
<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:scheme="https"/>
</intent-filter>


Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type.equals("text/plain")) {
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setTitle(R.string.pick_profile);
    builder.setItems(getConnProfNames(connectionProfiles), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            selectedItem = connectionProfiles.get(which);
            DownloadTask.execute();
        }
    });
}
4

1 回答 1

0

没有共享意图之类的东西。应用程序可以使用具有不同操作、类型、附加功能和数据的 Intent 共享数据。大多数这些应用程序将使用 ACTION_SEND,但根据应用程序的不同,其他参数会有很大差异。使用您的意图过滤器,您只能使用 http 和 https 方案捕获意图,并且您的代码确实将类型另外限制为 text/plain。这一切都取决于触发时“共享菜单”的作用,您的上述代码是否有效。

Dolphin 浏览器用于共享其数据的意图是 AFAIK 未公开记录。我设法使用以下过滤器“捕捉”了它的一个意图:

<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <data android:mimeType="*/*" />
   <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

我还设法从附加内容中获取 URL,如下所示:

    CharSequence text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);

这实际上取决于您要尝试实现所需的过滤器。如果您尝试获取 URL 并加载 HTML 页面,那么我使用的过滤器将完成这项工作。它允许获取 URL,然后您可以在 WebView 中显示页面。

于 2013-06-22T04:20:02.290 回答