应用程序未显示在共享菜单中

时间:2013-06-22 02:30:06

标签: android android-intent share intentfilter

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

<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();
        }
    });
}

1 个答案:

答案 0 :(得分:0)

没有共享意图这样的东西。应用可以使用具有不同操作,类型,附加功能和数据的Intent来共享数据。大多数情况下,这些应用程序将使用ACTION_SEND,但根据应用程序的不同,其他参数会有很大差异。使用intent-filter,您只能使用http和https方案捕获Intents,而您的代码确实将类型限制为text / plain。这一切都取决于“共享菜单”在触发时的作用,无论您的代码是否有效。

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

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

相关问题