java– 在Android上捕获和拦截ACTION_SEND意图

java– 在Android上捕获和拦截ACTION_SEND意图,第1张

概述目前,我有一个非常标准的ACTION_SEND意图来从我的应用程序内部共享信息.代码类似于以下内容:Intentintent=newIntent(Intent.ACTION_SEND);intent.setType("text/plain");intent.putExtra(Intent.EXTRA_SUBJECT,subject);intent.putExtra(Intent.EXTRA_TE

目前,我有一个非常标准的ACTION_SEND意图来从我的应用程序内部共享信息.代码类似于以下内容:

    Intent intent = new Intent(Intent.ACTION_SEND);    intent.setType("text/plain");    intent.putExtra(Intent.EXTRA_SUBJECT, subject);    intent.putExtra(Intent.EXTRA_TEXT, text);    context.startActivity(Intent.createChooser(intent, Title));

现在,如果用户在他们的手机上安装了Facebook应用程序,则Facebook会显示为意图选择器的选项.但是,我想拦截用户点击“Facebook”并使用Facebook SDK执行任务,而不是用户手机上已有的Facebook应用程序.有没有办法拦截onClick的Facebook选项?谢谢!

解决方法:

这是我的博客文章的链接,其中包含详细的解决方案,包括代码和屏幕截图.

http://clickclickclack.wordpress.com/2012/01/03/intercepting-androids-action_send-intents/

正如该文引述:

[W]e first create a new action_send intent and set the type to
text/plain. Next, we create a List. We make the call to the package
manager to query for all ActivitIEs with the action_send intent
registered. This call returs a List of ResolveInfo objects, each
corresponding to an Activity on the device that claims to handle send
actions.

[Then, r]ather than launching the action_send intent and letting it
create its own dialog (one that we would have no control over), we
will build our own with the AlertDialog.Builder. First we give it a
Title, then set its adapter to the List adapter we just created with
the activitIEs List as our data set[.]

The next important pIEce we need to look at is the OnClick Listener we
gave the Builder. To find which item the user clicked, we use the
adapter.getItem(int which) method. This will return the object in that
position of our original List, in this case, a ResolveInfo object
corresponding to the selected Activity. For my case in particular, I
only care about separating things into two groups: Facebook and not
Facebook. To do this, I simply check if the selected Activity’s
package name contains ‘facebook’. If it does not, I create a new
action_send intent, set the class name to the selected activity, and
launch it. However, if the package name DOES contain ‘facebook’, I
instantiated my personal PostToFacebookDialog object which will create
a basic AndroID dialog with post and cancel buttons, and will post to
Facebook directly using the Graph API, thus circumventing the user’s
installed Facebook app.

总结

以上是内存溢出为你收集整理的java – 在Android上捕获和拦截ACTION_SEND意图全部内容,希望文章能够帮你解决java – 在Android上捕获和拦截ACTION_SEND意图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1114241.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存