我想分享一个链接,以便当其他用户单击该链接,它打开我的应用程序与一些意图数据,我可以处理。
Intent i= new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject");
i.putExtra(android.content.Intent.EXTRA_TEXT, "xyz.com/blah");
i.putExtra("important stuff", "important stuff");
startActivity(Intent.createChooser(i, "Share via"));我还在清单中添加了以下内容:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="xyz.com" />
</intent-filter>所以点击共享文本,我的应用程序就打开了。现在,我想在我的应用程序工作,根据important stuff。但是,在单击它时(例如来自Whatsapp),我只在接收到的意图中得到以下信息。
字符串名称:com.android.browser.application_id
值(以键表示):com.whatsapp
我如何才能拿回我在意图上发送的important stuff?
发布于 2017-02-08 00:44:59
我怎么才能找回我在意图上发送的那些重要的东西?
你没有。
当然欢迎您在Intents上随意添加额外内容,但不要指望其他应用程序会对它们做任何事情。特别是,在 documentation中没有任何东西要求ACTION_SEND的实现者用随机的附加物来做任何事情,更不用说以某种方式将它们带回给您了。
同样,尽管欢迎您发明新的HTTP报头,但不需要Web服务器关注它们,更不用说在响应中将它们发送回您。
相反,将xyz.com/blah替换为xyz.com/important/stuff (或者可能是xyz.com/blah?important=stuff),并从用于启动活动的Uri中获取数据。您可以通过活动的Uri方法中的getIntent().getData() (或者可能是传递给onNewIntent()的Intent上的getData(),这取决于您的清单设置和该活动的现有实例是否已经存在)获得该活动。
https://stackoverflow.com/questions/42102650
复制相似问题