private void InitializeShareSDK() { m_shareSDK = this.GetComponentDefault <ShareSDK>(); m_shareSDK.shareHandler = OnShareCallback; m_shareSDK.InitSDK(mobAppKey, mobAppSecret); Logger.LogDetail("SDKManager:: Initialize ShareSDK. key: [{0}], secret: [{1}]", mobAppKey, mobAppSecret); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); FindViewById(Resource.Id.button1).SetOnClickListener(this); FindViewById(Resource.Id.button2).SetOnClickListener(this); FindViewById(Resource.Id.button3).SetOnClickListener(this); FindViewById(Resource.Id.button4).SetOnClickListener(this); // 初始化ShareSDK ShareSDK.InitSDK(this); }
/* 获取平台列表,显示平台按钮*/ private void initPlatformList() { ShareSDK.InitSDK(this); Platform[] Platformlist = ShareSDK.GetPlatformList(); if (Platformlist != null) { LinearLayout linear = FindViewById <LinearLayout>(Resource.Id.linear); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); lp.Weight = 1; foreach (Platform platform in Platformlist) { if (!Tool.canGetUserInfo(platform)) { continue; } if (platform is CustomPlatform) { continue; } Button btn = new Button(this); btn.SetSingleLine(); String name = platform.Name; Console.WriteLine("名字" + name); if (platform.IsAuthValid) { btn.Text = GetString(Resource.String.remove_to_format, name); } else { btn.Text = GetString(Resource.String.login_to_format, name); } btn.TextSize = 16; btn.Tag = platform; btn.Visibility = ViewStates.Visible; btn.SetOnClickListener(this); linear.AddView(btn, lp); } } }
public void Login(Context context) { this.context = context.ApplicationContext; if (string.IsNullOrEmpty(CurrentPlatform)) { return; } // 初始化SDK ShareSDK.InitSDK(this.context); Platform plat = ShareSDK.GetPlatform(CurrentPlatform); if (plat == null) { return; } if (plat.IsAuthValid) { plat.RemoveAccount(true); return; } //使用SSO授权,通过客户单授权 plat.SSOSetting(false); plat.Complete += (sender, e) => { var platName = e.P0.Name; }; plat.Error += (sender, e) => { }; plat.Cancel += (sender, e) => { }; plat.ShowUser(null); }
/* * 演示执行第三方登录/注册的方法 * <p> * 这不是一个完整的示例代码,需要根据您项目的业务需求,改写登录/注册回调函数 * * @param platformName 执行登录/注册的平台名称,如:SinaWeibo.NAME */ private void login(string platformName) { LoginApi api = new LoginApi(); // 初始化SDK ShareSDK.InitSDK(ApplicationContext); Platform plat = ShareSDK.GetPlatform(platformName); if (plat == null) { return; } if (plat.IsAuthValid) { plat.RemoveAccount(true); return; } //使用SSO授权,通过客户单授权 plat.SSOSetting(false); plat.Complete += (sender, e) => { // 填写处理注册信息的代码,返回true表示数据合法,注册页面可以关闭 RunOnUiThread(() => { Toast.MakeText(this, "登录成功。", ToastLength.Short).Show(); }); }; plat.Error += (sender, e) => { }; plat.Cancel += (sender, e) => { }; plat.ShowUser(null); }
/** * 演示调用ShareSDK执行分享 * @param context * @param platformToShare 指定直接分享平台名称(一旦设置了平台名称,则九宫格将不会显示) * @param showContentEdit 是否显示编辑页 */ public static void InitalShare(Activity activity, string platformToShare, bool showContentEdit, string title, string shareContent, string imageUrl, string articleUrl) { ShareSDK.InitSDK(activity); // 初始化ShareSDK Button btnShare = activity.FindViewById <Button>(Resource.Id.footbar_share); btnShare.Click += delegate { OnekeyShare _oneKeyShare = new OnekeyShare(); _oneKeyShare.SetSilent(!showContentEdit); if (platformToShare != null) { _oneKeyShare.SetPlatform(platformToShare); } //ShareSDK快捷分享提供两个界面第一个是九宫格 CLASSIC 第二个是SKYBLUE _oneKeyShare.SetTheme(OnekeyShareTheme.Classic); // 令编辑页面显示为Dialog模式 _oneKeyShare.SetDialogMode(); // 在自动授权时可以禁用SSO方式 _oneKeyShare.DisableSSOWhenAuthorize(); //_oneKeyShare.setAddress("12345678901"); //分享短信的号码和邮件的地址 _oneKeyShare.SetTitle(title); _oneKeyShare.SetTitleUrl(articleUrl); //_oneKeyShare.SetText("ShareSDK--文本"); _oneKeyShare.Text = shareContent; //_oneKeyShare.setImagePath("/sdcard/test-pic.jpg"); //分享sdcard目录下的图片 _oneKeyShare.SetImageUrl(imageUrl); _oneKeyShare.SetUrl("http://www.cnblogs.com/CallMeUncle/"); //微信不绕过审核分享链接 //_oneKeyShare.setFilePath("/sdcard/test-pic.jpg"); //filePath是待分享应用程序的本地路劲,仅在微信(易信)好友和Dropbox中使用,否则可以不提供 _oneKeyShare.SetComment("分享"); //我对这条分享的评论,仅在人人网和QQ空间使用,否则可以不提供 _oneKeyShare.SetSite("博客园-IT胡小帅"); //QZone分享完之后返回应用时提示框上显示的名称 _oneKeyShare.SetSiteUrl(articleUrl); //QZone分享参数 _oneKeyShare.SetVenueName("博客园-IT胡小帅"); _oneKeyShare.SetVenueDescription("APP作者:胡帅。一个不出名的帅小伙,只想安安静静写个代码。"); // 将快捷分享的操作结果将通过OneKeyShareCallback回调 //_oneKeyShare.setCallback(new OneKeyShareCallback()); // 去自定义不同平台的字段内容 //_oneKeyShare.setShareContentCustomizeCallback(new ShareContentCustomizeDemo()); // 在九宫格设置自定义的图标 //Bitmap logo = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_launcher); //String label = "ShareSDK"; //var listener = new CustomOnClickListener(); //_oneKeyShare.SetCustomerLogo(logo, label, listener); // 为EditPage设置一个背景的View //_oneKeyShare.setEditPageBackground(getPage()); // 隐藏九宫格中的新浪微博,短信,邮件,微信收藏 _oneKeyShare.AddHiddenPlatform("SinaWeibo"); _oneKeyShare.AddHiddenPlatform("ShortMessage"); _oneKeyShare.AddHiddenPlatform("Email"); _oneKeyShare.AddHiddenPlatform("WechatFavorite"); // String[] AVATARS = { // "http://99touxiang.com/public/upload/nvsheng/125/27-011820_433.jpg", // "http://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg", // "http://diy.qqjay.com/u/files/2012/0523/f466c38e1c6c99ee2d6cd7746207a97a.jpg", // "http://diy.qqjay.com/u2/2013/0422/fadc08459b1ef5fc1ea6b5b8d22e44b4.jpg", // "http://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339510584349.jpg", // "http://diy.qqjay.com/u2/2013/0401/4355c29b30d295b26da6f242a65bcaad.jpg" }; // oks.setImageArray(AVATARS);//腾讯微博和twitter用此方法分享多张图片,其他平台不可以 // 启动分享 _oneKeyShare.Show(activity); }; }