Android 分享功能的实现

I : 利用隐式Intent实现分享

   1、应用实现分享的功能

      

 1 /* 实现分享功能 */
 2
 3         Intent intent = new Intent();
 4         intent.setAction(Intent.ACTION_SEND);
 5
 6         // 分享文本
 7         intent.setType("text/plain"); // text/html ...
 8         intent.putExtra(Intent.EXTRA_SUBJECT, "我要分享");
 9         intent.putExtra(Intent.EXTRA_TEXT, "分享的内容");
10
11         // 分享本地图片
12         intent.setType("image/*");
13         File file = new File(Environment.getExternalStorageDirectory()+"/imgCache/a0.jpg");
14         Uri uri = Uri.fromFile(file);
15         intent.putExtra(Intent.EXTRA_STREAM,uri);
16
17         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
18         startActivity(Intent.createChooser(intent, "分享列表"));

 2、应用加入系统的分享列表

 

 1  在AndroidManifest.xml文件中的<activity>标签下添加<Intent-filter>
 2
 3  <activity
 4    android:name="com.example.demo_share_01.Leading"
 5    android:label="@string/app_name" >
 6             <intent-filter>
 7                 <action android:name="android.intent.action.SEND" />
 9                 <category android:name="android.intent.category.DEFAULT" />
10                 <data android:mimeType="image/*"/>
11             </intent-filter>
12   </activity>

 

 II :  利用ShareSDK第三方库实现分享

    以一键分享(新浪微博和腾讯微博)为例

   第一步: 在src文件夹下添加叫cn.sharesdk.onekeyshare包

   第二步: 在libs文件夹下添加库文件 

                        

  第三步:在assets文件夹下添加ShareSDK.xml文件

        

  ShareSDK.xml文件代码如下:

<?xml version="1.0" encoding="utf-8"?>
<DevInfor>
    <!--
    	说明:

    	1、表格中的第一项
    		<ShareSDK
        		AppKey="api20" />
    	是必须的,其中的AppKey是您在ShareSDK上注册的开发者帐号的AppKey

    	2、所有集成到您项目的平台都应该为其在表格中填写相对应的开发者信息,以新浪微博为例:
    	    <SinaWeibo
                Id="1"
                SortId="1"
                AppKey="568898243"
                AppSecret="38a4f8204cc784f81f9f0daaf31e02e3"
                RedirectUrl="http://www.mob.com"
                Enable="true" />
    	其中的SortId是此平台在分享列表中的位置,由开发者自行定义,可以是任何整型数字,数值越大
    	越靠后AppKey、AppSecret和RedirectUrl是您在新浪微博上注册开发者信息和应用后得到的信息
    	Id是一个保留的识别符,整型,ShareSDK不使用此字段,供您在自己的项目中当作平台的识别符。
    	Enable字段表示此平台是否有效,布尔值,默认为true,如果Enable为false,即便平台的jar包
    	已经添加到应用中,平台实例依然不可获取。

    	各个平台注册应用信息的地址如下:
			新浪微博        http://open.weibo.com
			腾讯微博        http://dev.t.qq.com
			QQ空间          http://connect.qq.com/intro/login/
			微信好友        http://open.weixin.qq.com
			Facebook       https://developers.facebook.com
			Twitter        https://dev.twitter.com
			人人网          http://dev.renren.com
			开心网          http://open.kaixin001.com
			搜狐微博        http://open.t.sohu.com
			网易微博        http://open.t.163.com
			豆瓣           http://developers.douban.com

			有道云笔记      http://note.youdao.com/open/developguide.html#app
			印象笔记        https://dev.evernote.com/
			Linkedin       https://developer.linkedin.com
			FourSquare     https://developer.foursquare.com/
			搜狐随身看      https://open.sohu.com/
			Flickr         http://www.flickr.com/services/
			Pinterest      http://developers.pinterest.com/
			Tumblr         http://www.tumblr.com/developers
			Dropbox        https://www.dropbox.com/developers
			Instagram      http://instagram.com/developer#
			VKontakte      http://vk.com/dev
			易信好友        http://open.yixin.im/
			明道	           http://open.mingdao.com/
			Line           http://media.line.me/zh-hant/
			Pocket         http://getpocket.com/developer/apps/new
    -->

    <ShareSDK
        AppKey = "426e34bef3d7"/> <!-- 修改成你在sharesdk后台注册的应用的appkey"-->

    <!-- ShareByAppClient标识是否使用微博客户端分享,默认是false -->
    <SinaWeibo
        Id="1"
        SortId="1"
        AppKey="2073300154"
        AppSecret="a5f7b084ba7630688831f691e16d146b"
        RedirectUrl="https://api.weibo.com/oauth2/default.html"
        ShareByAppClient="false"
        Enable="true" />

    <TencentWeibo
        Id="2"
        SortId="2"
        AppKey="801550161"
        AppSecret="d2c82a847a577af120857feee42548ea"
        RedirectUri="http://www.baidu.com"
        Enable="true" />

</DevInfor>

 第四步:在AndroidManifest.xml文件中添加访问权限等配置信息

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.qf.sdemo_02_01_volley_news"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="18" />

  <!-- 添加需要的各种权限 -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <!-- 蓝牙分享所需的权限 -->
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

      <!-- 主Activity -->
        <activity
            android:name="com.qf.sdemo_02_01_volley_news.MainActivity"
            android:label="@string/app_name" >
<intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.qf.sdemo_02_01_volley_news.Detail" >
        </activity>

        <!-- 进行授权界面的注册 -->
        <activity
            android:name="cn.sharesdk.framework.ShareSDKUIShell"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:windowSoftInputMode="stateHidden|adjustResize" >

            <!--
            	Dropbox的SSO功能需要在此处添加一个对ACTION_VIEW事件的过滤器,其中的scheme是
            	“db-”前缀再开发者应用的加上appKey。如果此过滤器不设置,则不能完成SSO功能授权
            -->
            <intent-filter>
                <data android:scheme="db-7janx53ilz11gbs" />

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <!--
            	如果集成QQ分享,或者使用QQ客户端来进行QQ空间的分享,须要在此处添加一个对ACTION_VIEW
            	事件的过滤器,其中的scheme是“tencent”前缀再开发者应用的加上appId。如果此过滤器不设置,
            	则分享结束以后不能得到正确的回调
            -->
            <intent-filter>
                <data android:scheme="tencent100371282" />

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>

    </application>

</manifest>

  

第五步: 在mob.com 、新浪微博开发平台 和腾讯微博开发平台创建应用获得 appkey 和 appsecrect ,并添加到ShareSDK.xml文件中

第六步: 写代码实现分享

时间: 2024-07-29 21:22:18

Android 分享功能的实现的相关文章

Android -- 分享功能和打开指定程序

打开指定程序                                                                                Intent intent = new Intent(); ComponentName cmp = new ComponentName("com.sina.weibo","com.sina.weibo.EditActivity"); intent.setAction(Intent.ACTION_M

android 分享功能

上一篇讲了android第三方登录,这一篇大概说一下分享.需要注意几点: 1.登录和分享功能都必须是签名之后的apk,才能用 2.再吐槽一下,微信SDK做的真他妈的变态,和登录一样,必须是例如我的apk,包名(也就是AndroidManifest.xml中的包名)是com.kingdowin.gosu,你项目中必须有一个包名是com.kingdowin.gosu.wxapi,下面有一个类是WXEntryActivity.java,里面写登录或分享以及获得返回响应结果(public void on

Android分享功能,微博、QQ、QQ空间等社交平台分享之入门与进阶

前言 如何能迅速做一个分享功能,那主要就是根据第一个步骤来做就好了,因为友盟的sdk包已经集成很多的内容了,只要你有相应的app和平台账号就可以能马上分享.进阶的内容就是从第三部分开始,这些内容不难,目的就是为了更好的优化分享体验. 1.先做一个简单的分享效果. 1.1 创建一个Android项目 以下项目所需要的jar包,图片等资源可到该网站下载SDK即可. http://dev.umeng.com/social/android/quick-integration?spm=0.0.0.0.Lk

Android分享功能实现

通过系统分享组件实现分享功能 Intent.createChooser() 方法用来弹出系统分享列表. createChooser(Intent target, CharSequence title, IntentSender sender) 参数. 常规方法 public void share(Context context){ Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendInt

Android分享功能的一点总结

前段时间给以前的App加了分享功能,与大家分享一些心得. 实现分享功能有三种方式: 1.调用Android自带的分享接口,这种方式最简单,它是直接调用App的发信息功能,把我们的链接通过信息方式发出去,因此它的分享效果比较差.同时它只能发送给手机上已安装的社交App.最坑的是有些App对此功能是屏蔽的,比如微信朋友圈.代码很简单,网上一搜就有,我就不赘述了. 2.通过第三方SDK来分享,国内比较常用的有友盟和MO.首先要去申请开发,然后下载SDK再调用相应接口就行,缺点是支持部分APP(国内的大

分享一套完整的android 分享功能代码

微信分享代码: <pre name="code" class="html">public class WXEntryActivity extends Activity implements OnClickListener, IWXAPIEventHandler { private IWXAPI api; api = WXAPIFactory.createWXAPI(this, Constant.WEIXIN_APP_ID, false); api.han

在Android中如何实现分享功能

Android应用中能很方便的完成这些功能,很多的应用中都有"分享"功能?如何分享呢?下面给大家说说看.最近有人问到Android分享功能用那个比较好,使用Android开发自带的Intent来进行分享还是借助第三方呢,直接上代码: 一.使用Intent直接和第三方应用进行通信: /** * 分享功能 * * @param context *            上下文 * @param activityTitle *            Activity的名字 * @param

Android APP代码拨打电话、打开手机分享功能等隐式意图

Android APP拨打电话: Intent intent=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+110)); startActivity(intent); } Android APP打开电话薄: Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI); startActivity(intent); Android

在Android中使App高速、简单地支持新浪微博、微信、QQ、facebook等十几个主流社交平台的分享功能

前言 在如今的APP或者游戏中,分享功能差点儿已经成为标配.分享功能不但能够满足用户的需求.也能够为产品带来很多其它的用户,甚至能够对用户的行为.活跃度.年龄段等情况进行数据统计,使得软件公司能够对产品进行更精准的定位.今天我们就来简单剖析市场上一款优秀的分享SDK以及其集成过程.这款分享SDK就是友盟的社会化分享组件. 友盟社会化分享,帮助移动应用高速具备分享.登录.评论.喜欢等社交功能,提升用户粘度.助力产品推广,并提供实时.全面的社会化数据统计分析服务. 很多其它请訪问友盟社会化组件官网.