在app开发的时候需要用到分享功能,利用友盟的第三方分享,可以大大的简化,分享难度
首先,应该去由友盟的官网注册成为开发者:http://dev.umeng.com/
添加应用,下载官网的社会化分享的sdk(sdk下有详细的文档说明以及demo),在sdk的根目录下,双击SDKIntegration.jar文件,选择需要快速集成的功能,选择工程的根目录,同时需要填写注册应用的appid
刷新工程,查看是否集成成功。
先看看效果图
MainActivity的代码如下:
package com.photo.test; import com.umeng.socialize.bean.SHARE_MEDIA; import com.umeng.socialize.bean.SocializeEntity; import com.umeng.socialize.controller.UMEvernoteHandler; import com.umeng.socialize.controller.UMServiceFactory; import com.umeng.socialize.controller.UMSocialService; import com.umeng.socialize.controller.listener.SocializeListeners.SnsPostListener; import com.umeng.socialize.instagram.controller.UMInstagramHandler; import com.umeng.socialize.instagram.media.InstagramShareContent; import com.umeng.socialize.media.UMImage; import com.umeng.socialize.pinterest.controller.UMPinterestHandler; import com.umeng.socialize.pocket.controller.UMPocketHandler; import com.umeng.socialize.sso.EmailHandler; import com.umeng.socialize.sso.QZoneSsoHandler; import com.umeng.socialize.sso.SmsHandler; import com.umeng.socialize.sso.UMQQSsoHandler; import com.umeng.socialize.weixin.controller.UMWXHandler; import com.umeng.socialize.weixin.media.WeiXinShareContent; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { final UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //设置分享的内容 mController.setShareContent("友盟社会化组件(SDK)让移动应用快速整合社交分享功能,http://www.umeng.com/social"); //mController.setShareMedia(new UMImage(this, //"http://dev.umeng.com/images/social.png")); //设置分享的图标 mController.setShareMedia(new UMImage(this, R.drawable.ic_launcher)); mController.setAppWebSite(SHARE_MEDIA.RENREN, "http://www.umeng.com/social"); //添加qq空间分享 QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(this,"com.photo.test","5443208ffd98c5c227000e4e"); qZoneSsoHandler.addToSocialSDK(); UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(this,"com.photo.test","5443208ffd98c5c227000e4e"); qqSsoHandler.addToSocialSDK(); //添加微信平台 UMWXHandler wxHandler = new UMWXHandler(this,"com.photo.test","5443208ffd98c5c227000e4e"); wxHandler.addToSocialSDK(); // 添加微信朋友圈 UMWXHandler wxCircleHandler = new UMWXHandler(this,"com.photo.test","5443208ffd98c5c227000e4e"); wxCircleHandler.setToCircle(true); wxCircleHandler.addToSocialSDK(); //设置微信好友分享内容 WeiXinShareContent weixinContent = new WeiXinShareContent(); //设置分享文字 weixinContent.setShareContent("来自友盟社会化组件(SDK)让移动应用快速整合社交分享功能,微信"); //设置title weixinContent.setTitle("友盟社会化分享组件-微信"); //设置分享内容跳转URL weixinContent.setTargetUrl("http://www.baidu.com"); //设置分享图片 weixinContent.setShareImage(new UMImage(this,R.drawable.ic_launcher)); mController.setShareMedia(weixinContent); // 添加短信 SmsHandler smsHandler = new SmsHandler(); smsHandler.addToSocialSDK(); // 添加email EmailHandler emailHandler = new EmailHandler(); emailHandler.addToSocialSDK(); //添加推特分享 mController.getConfig().supportAppPlatform(this, SHARE_MEDIA.TWITTER, "这里你构造mController填写的字符串参数", true) ; // 构建Instagram的Handler UMInstagramHandler instagramHandler = new UMInstagramHandler(this); // 将instagram添加到sdk中 instagramHandler.addToSocialSDK(); // 本地图片 UMImage localImage = new UMImage(this, R.drawable.ic_launcher); // 设置分享到Instagram的内容, 注意由于instagram客户端的限制,目前该平台只支持纯图片分享,文字、音乐、url图片等都无法分享。 InstagramShareContent instagramShareContent = new InstagramShareContent(localImage); // 设置Instagram的分享内容 // 添加evernote平台,添加印象笔记 UMEvernoteHandler evernoteHandler = new UMEvernoteHandler(this); evernoteHandler.addToSocialSDK(); // 添加pinterest平台 UMPinterestHandler pinterestHandler = new UMPinterestHandler(this,"你的app id"); pinterestHandler.addToSocialSDK(); // 添加Pocket平台 UMPocketHandler pocketHandler = new UMPocketHandler(this); pocketHandler.addToSocialSDK(); mController.setShareMedia(instagramShareContent); mController.openShare(this, true); Button share = (Button) findViewById(R.id.share); share.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub // 是否只有已登录用户才能打开分享选择页 mController.openShare(MainActivity.this, false); } }); } }
添加用户反馈的模块:
首先去友盟官网下载反馈模块的sdk:http://dev.umeng.com/feedback/android/sdk-download
需要将一下代码添加到清单文件里:
<manifest……> <application ……> <activity android:name="com.umeng.fb.ConversationActivity" android:theme="@android:style/Theme.NoTitleBar"/> <activity android:name="com.umeng.fb.ContactActivity" android:theme="@android:style/Theme.NoTitleBar"/> <meta-data android:value="YOUR_APP_KEY" android:name="UMENG_APPKEY"></meta-data> <meta-data android:value="Channel ID" android:name="UMENG_CHANNEL"/> </application> <uses-sdk android:minSdkVersion="4"></uses-sdk> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </manifest>
Feedback
模块,调用下面函数进入反馈界面:
FeedbackAgent agent = new FeedbackAgent(context); agent.startFeedbackActivity();
开发者需要自己去友盟的开发者后台管理反馈给用户信息:http://www.umeng.com/apps/e4e000722c5c89dff8023445/reports/feedbacks,注意这里首先需要登录
效果如图所示:源码连接:http://download.csdn.net/detail/mockingbirds/8055497