热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android将应用加入到分享列表跳转的市场选择列表

今天老大出了个需求,要将我们的应用加入到分享列表里面。做Iphone的小果果说实现不了,在Android上能做。哎,不说什么了。找资料吧。首先凭多次的经验,应该是以下步骤。1,找lo

今天老大出了个需求,要将我们的应用加入到分享列表里面。做Iphone的小果果说实现不了,在Android上能做。哎,不说什么了。找资料吧。

 

首先凭多次的经验,应该是以下步骤。

1,找log,logcat是个好东西,能帮你迅速定位到程序的走向,不光是能找bug哦,有些提示信息能帮你找到一些解决问题的入口点,比如说上次要调用2.2设备的前置摄像头。

2,看官方文档,对这个东西的描述,不要急于找网上的案例。要知道,我们的需求千变万化,网上的案例不见得是符合你的需求的,所以不要乱试一通哈。

3,通过官方的描述,找对应的方法或者在网上搜特定的语句,相信很快就能解决了。

下面说下我实际的解决步骤:

1.这是我在logcat里面翻出来的log,很神奇额。

//  07-27 15:53:08.061: INFO/ActivityManager(2460): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) }
//  07-27 15:53:08.846: INFO/ActivityManager(2460): Displayed activity android/com.android.internal.app.ChooserActivity: 771 ms (total 771 ms)
//  07-27 15:53:21.592: INFO/ActivityManager(2460): Starting activity: Intent { act=android.intent.action.SEND typ=image/jpeg flg=0x3000000 cmp=com.sina.weibo/.EditActivity (has extras) }

2.现在就去搜这个intent吧(android.intent.action.CHOOSER)慢慢看不翻译了

Activity Action: Display an activity chooser, allowing the user to pick what they want to before proceeding. This can be used as an alternative to the standard activity picker that is displayed by the system when you try to start an activity with multiple possible matches, with these differences in behavior:
You can specify the title that will appear in the activity chooser.
The user does not have the option to make one of the matching activities a preferred activity, and all possible activities will always be shown even if one of them is currently marked as the preferred activity.
This action should be used when the user will naturally expect to select an activity in order to proceed. An example if when not to use it is when the user clicks on a "mailto:" link. They would naturally expect to go directly to their mail app, so startActivity() should be called directly: it will either launch the current preferred app, or put up a dialog allowing the user to pick an app to use and optionally marking that as preferred.
In contrast, if the user is selecting a menu item to send a picture they are viewing to someone else, there are many different things they may want to do at this point: send it through e-mail, upload it to a web service, etc. In this case the CHOOSER action should be used, to always present to the user a list of the things they can do, with a nice title given by the caller such as "Send this photo with:".
As a convenience, an Intent of this form can be created with the createChooser(Intent, CharSequence) function.

3.好吧,现在搜索吧,关键字:  Android 分享

Intent intent=new Intent(Intent.ACTION_SEND);  基本上都有这个语句,好,再搜这个吧。找个几次基本上就能找到了

贴代码吧。







//这里是要接收send的类型



这是我自己的微博应用。label是要弹出来的分享列表的文字。 这个就是Intent.ACTION_SEND了。

 

                          Intent it = getIntent();
if (it != null &&  it.getAction() != null && it.getAction().equals(Intent.ACTION_SEND)) {
Bundle extras = it.getExtras();
if (extras.containsKey("android.intent.extra.STREAM")) {
Log.i(TAG, "uri++=" + extras.get("android.intent.extra.STREAM"));
uri = (Uri) extras.get("android.intent.extra.STREAM");
set_image(uri);//这里是将我们所选的分享图片加载出来
}
// 07-27 17:39:44.073: INFO/Writer_Blog(3289): android.intent.extra.STREAM=content://media/external/images/media/1211
}

网上找到的代码,能获取所有manifest文件里面加了 apps

public List getShareTargets(){
List mApps = new ArrayList();
Intent intent=new Intent(Intent.ACTION_SEND,null);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("text/plain");
PackageManager pm=this.getPackageManager();
mApps=pm.queryIntentActivities(intent,PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
return mApps;
}

 

还有一个跳转进市场的代码


 

Intent intent = new Intent(Intent.ACTION_VIEW);
2 intent.setData(Uri.parse("market://details?id=" + getPackageName()));
3 startActivity(intent);

跳转进市场搜索的代码

Intent intent = new Intent(Intent.ACTION_VIEW);
2 intent.setData(Uri.parse("market://search?q=pub:Your Publisher Name"));
3 startActivity(intent);

推荐阅读
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • 本文讨论了如何使用IF函数从基于有限输入列表的有限输出列表中获取输出,并提出了是否有更快/更有效的执行代码的方法。作者希望了解是否有办法缩短代码,并从自我开发的角度来看是否有更好的方法。提供的代码可以按原样工作,但作者想知道是否有更好的方法来执行这样的任务。 ... [详细]
  • 使用圣杯布局模式实现网站首页的内容布局
    本文介绍了使用圣杯布局模式实现网站首页的内容布局的方法,包括HTML部分代码和实例。同时还提供了公司新闻、最新产品、关于我们、联系我们等页面的布局示例。商品展示区包括了车里子和农家生态土鸡蛋等产品的价格信息。 ... [详细]
  • node.jsurlsearchparamsAPI哎哎哎 ... [详细]
  • 本文介绍了iOS开发中检测和解决内存泄漏的方法,包括静态分析、使用instruments检查内存泄漏以及代码测试等。同时还介绍了最能挣钱的行业,包括互联网行业、娱乐行业、教育行业、智能行业和老年服务行业,并提供了选行业的技巧。 ... [详细]
  • 正则表达式及其范例
    为什么80%的码农都做不了架构师?一、前言部分控制台输入的字符串,编译成java字符串之后才送进内存,比如控制台打\, ... [详细]
  • [转载]从零开始学习OpenGL ES之四 – 光效
    继续我们的iPhoneOpenGLES之旅,我们将讨论光效。目前,我们没有加入任何光效。幸运的是,OpenGL在没有设置光效的情况下仍然可 ... [详细]
  • 1.webkit内核中的一些私有的meta标签,这些meta标签在开发webapp时起到非常重要的作用(1) ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • Python爬虫中使用正则表达式的方法和注意事项
    本文介绍了在Python爬虫中使用正则表达式的方法和注意事项。首先解释了爬虫的四个主要步骤,并强调了正则表达式在数据处理中的重要性。然后详细介绍了正则表达式的概念和用法,包括检索、替换和过滤文本的功能。同时提到了re模块是Python内置的用于处理正则表达式的模块,并给出了使用正则表达式时需要注意的特殊字符转义和原始字符串的用法。通过本文的学习,读者可以掌握在Python爬虫中使用正则表达式的技巧和方法。 ... [详细]
  • 本文介绍了Oracle存储过程的基本语法和写法示例,同时还介绍了已命名的系统异常的产生原因。 ... [详细]
  • Ihaveaworkfolderdirectory.我有一个工作文件夹目录。holderDir.glob(*)>holder[ProjectOne, ... [详细]
author-avatar
手机用户2602913291
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有