美文网首页
如何实现友盟第三方登录与分享

如何实现友盟第三方登录与分享

作者: Sink_Into | 来源:发表于2017-12-05 16:42 被阅读132次

    //友盟配置

    package="com.example.tadaynews"

    android:versionCode="1"

    android:versionName="1.0" >

    android:minSdkVersion="14"

    android:targetSdkVersion="14" />

    android:name="com.example.utils.App"

    android:icon="@drawable/icon"

    android:allowBackup="true"

    android:label="@string/app_name"

    android:theme="@style/AppTheme" >

    android:name="com.example.view.WelcomeActivity"

    android:label="@string/app_name" >

    android:name="com.example.tadaynews.MainActivity"

    android:label="@string/app_name" >

    android:name="com.example.login.MoreLoginActivity"

    android:label="@string/app_name" >

    android:name="com.example.login.LoginActivity"

    android:label="@string/app_name" >

    android:name="com.example.login.RegisterActivity"

    android:label="@string/app_name" >

    android:name="com.example.login.RegisterInfo"

    android:label="@string/app_name" >

    android:name="com.example.view.Left_MenuSetActivity"

    android:label="@string/app_name" >

    android:name="com.example.login.FindPasswordActivity"

    android:label="@string/app_name" >

    android:name="com.example.fragment.FragInfoActivity"

    android:label="@string/app_name" >

    android:name="com.example.view.DownLoadActivity"

    android:label="@string/app_name" >

    android:name="com.example.tadaynews.SearchActvity"

    android:label="@string/app_name" >

    android:name="com.example.tadaynews.SourchInfoActivity"

    android:label="@string/app_name" >

    android:name="com.umeng.socialize.editorpage.ShareActivity"

    android:excludeFromRecents="true"

    android:theme="@style/Theme.UMDefault" />

    android:name="com.umeng.soexample.wxapi.WXEntryActivity"

    android:configChanges="keyboardHidden|orientation|screenSize"

    android:exported="true"

    android:screenOrientation="portrait"

    android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    android:name=".WBShareActivity"

    android:configChanges="keyboardHidden|orientation"

    android:screenOrientation="portrait" >

    android:name="com.sina.weibo.sdk.component.WeiboSdkBrowser"

    android:configChanges="keyboardHidden|orientation"

    android:exported="false"

    android:windowSoftInputMode="adjustResize" >

    android:name="com.sina.weibo.sdk.net.DownloadService"

    android:exported="false" >

    android:name="com.tencent.tauth.AuthActivity"

    android:launchMode="singleTask"

    android:noHistory="true" >

    android:name="com.tencent.connect.common.AssistActivity"

    android:screenOrientation="portrait"

    android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    android:name="com.example.umeng.WXEntryActivity"

    android:configChanges="keyboardHidden|orientation|screenSize"

    android:exported="true"

    android:screenOrientation="portrait"

    android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    android:name="UMENG_APPKEY"

    android:value="56e7626ee0f55a8a3f0017c9" >

    android:name="com.baidu.android.pushservice.PushKeepAlive"

    android:theme="@android:style/Theme.Translucent.NoTitleBar"/>

    android:process=":bdservice_v1" >

    android:process=":bdservice_v1" >

    android:process=":bdservice_v1" >

    android:exported="true" />

    //友盟第三方登录

    package com.example.utils;

    import java.util.Map;

    import com.umeng.socialize.UMAuthListener;

    import com.umeng.socialize.UMShareAPI;

    import com.umeng.socialize.bean.SHARE_MEDIA;

    import android.app.Activity;

    import android.content.Context;

    import android.widget.Toast;

    /**

    * 工具类

    * 定有友盟,,,第三方登录 类,实现整个项目的第三方登录

    * @author 浅议爱

    *

    */

    public class UmengUtils {

    public static void uMengLogin(final Context context,SHARE_MEDIA share){

    UMShareAPI mUMAPI = UMShareAPI.get(context);

    UMAuthListener uMengShare = new UMAuthListener() {

    @Override

    // 鎴愬姛

    public void onComplete(SHARE_MEDIA platform, int action,

    Map data) {

    Toast.makeText(context.getApplicationContext(), "Authorize succeed",

    Toast.LENGTH_SHORT).show();

    }

    @Override

    // 澶辫触

    public void onError(SHARE_MEDIA platform, int action, Throwable t) {

    Toast.makeText(context.getApplicationContext(), "Authorize fail",

    Toast.LENGTH_SHORT).show();

    }

    @Override

    // 鍙栨秷

    public void onCancel(SHARE_MEDIA platform, int action) {

    Toast.makeText(context.getApplicationContext(), "Authorize cancel",

    Toast.LENGTH_SHORT).show();

    }

    };

    mUMAPI.doOauthVerify((Activity) context, share, uMengShare);

    }

    }

    //工具类

    /**

    *

    */

    package com.example.utils;

    import com.umeng.socialize.PlatformConfig;

    import android.app.Application;

    /**

    * @author WJL

    *

    */

    public class App extends Application {

    @Override

    public void onCreate() {

    // TODO Auto-generated method stub

    super.onCreate();

    // 寰俊 appid appsecret

    PlatformConfig.setWeixin("wx967daebe835fbeac",

    "5bb696d9ccd75a38c8a0bfe0675559b3");

    // 鏂版氮寰崥 appkey appsecret

    PlatformConfig.setSinaWeibo("3921700954",

    "04b48b094faeb16683c32669824ebdad");

    // QQ鍜孮zone appid appkey

    PlatformConfig.setQQZone("1105181363",

    "  nOSNQJcIQSRw3a03");

    }

    }

    //友盟分享

    package com.example.fragment;

    import java.util.List;

    import com.example.bean.ObjectData;

    import com.example.tadaynews.R;

    import com.umeng.socialize.Config;

    import com.umeng.socialize.PlatformConfig;

    import com.umeng.socialize.ShareAction;

    import com.umeng.socialize.UMShareListener;

    import com.umeng.socialize.bean.SHARE_MEDIA;

    import com.umeng.socialize.shareboard.SnsPlatform;

    import com.umeng.socialize.utils.ShareBoardlistener;

    import android.app.Activity;

    import android.content.Intent;

    import android.os.Bundle;

    import android.view.View;

    import android.view.View.OnClickListener;

    import android.webkit.WebView;

    import android.widget.ImageView;

    /**

    *

    * 该页面,显示详情页面,点击分享按钮,进行分享

    * @author 浅议爱

    *

    */

    public class FragInfoActivity extends Activity {

    private UMShareListener umShareListener;

    private ShareBoardlistener shareBoardlistener;

    private WebView mWebView;

    private ImageView shareImageView;//分享按钮

    private List list_data;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    // TODO Auto-generated method stub

    super.onCreate(savedInstanceState);

    setContentView(R.layout.frag_info);

    PlatformConfig.setQQZone("100424468",

    "c7394704798a158208a74ab60104f0ba");

    PlatformConfig.setWeixin("wx967daebe835fbeac",

    "5bb696d9ccd75a38c8a0bfe0675559b3");

    // 微信 appid appsecret

    PlatformConfig.setSinaWeibo("3921700954",

    "04b48b094faeb16683c32669824ebdad");

    // 新浪微博 appkey appsecret

    PlatformConfig.setQQZone("100424468",

    "c7394704798a158208a74ab60104f0ba");

    // QQ和Qzone appid appkey

    PlatformConfig.setAlipay("2015111700822536");

    // 支付宝 appid

    PlatformConfig.setYixin("yxc0614e80c9304c11b0391514d09f13bf");

    // 易信 appkey

    PlatformConfig.setTwitter("3aIN7fuF685MuZ7jtXkQxalyi",

    "MK6FEYG63eWcpDFgRYw4w9puJhzDl0tyuqWjZ3M7XJuuG7mMbO");

    // Twitter appid appkey

    PlatformConfig.setPinterest("1439206");

    // Pinterest appid

    PlatformConfig.setLaiwang("laiwangd497e70d4",

    "d497e70d4c3e4efeab1381476bac4c5e");

    share();

    mWebView=(WebView) findViewById(R.id.mywebview);

    shareImageView=(ImageView) findViewById(R.id.share_image);

    Intent it=getIntent();

    String url=(String) it.getSerializableExtra("web_url");

    list_data=(List) it.getSerializableExtra("data");

    mWebView.loadUrl(url);

    //设置监听,点击,进行分享,分享数据

    shareImageView.setOnClickListener(new OnClickListener() {

    @Override

    public void onClick(View v) {

    // TODO Auto-generated method stub

    Config.OpenEditor = false;

    final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[] {

    SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,

    SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE,

    SHARE_MEDIA.DOUBAN };

    new ShareAction(FragInfoActivity.this).setDisplayList(displaylist)

    .setShareboardclickCallback(shareBoardlistener).open();

    }

    });

    }

    /**

    *

    * 分享调用的方法

    */

    private void share() {

    // TODO Auto-generated method stub

    umShareListener=new UMShareListener() {

    //分享成功

    @Override

    public void onResult(SHARE_MEDIA arg0) {

    // TODO Auto-generated method stub

    }

    //分享失败

    @Override

    public void onError(SHARE_MEDIA arg0, Throwable arg1) {

    // TODO Auto-generated method stub

    }

    //取消分享

    @Override

    public void onCancel(SHARE_MEDIA arg0) {

    // TODO Auto-generated method stub

    }

    };

    //shareBoardlistener=new ShareBoardlistener() {

    ////选择要分享的数据

    //@Override

    //public void onclick(SnsPlatform arg0, SHARE_MEDIA arg1) {

    //// TODO Auto-generated method stub

    //if (arg1 == null) {

    //if (arg0.mKeyword.equals("11")) {

    //}

    //} else {

    //// 设置分享的内容

    //new ShareAction(FragInfoActivity.this)

    //.setPlatform(arg1)

    //.setCallback(umShareListener)

    //.withText(list_data.getContent())

    //.withTitle(list_data.getTitle())

    //.withTargetUrl(list_data.getDisplay_url())

    //.setListenerList(umShareListener).share();

    //}

    //}

    //};

    }

    }

    相关文章

      网友评论

          本文标题:如何实现友盟第三方登录与分享

          本文链接:https://www.haomeiwen.com/subject/wwpcixtx.html