友盟第三方带面板分享+不带面板分享+登录

扎依赖:

清单:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<!-- //新浪-->
<activity
    android:name="com.umeng.socialize.media.WBShareCallBackActivity"
    android:configChanges="keyboardHidden|orientation"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:exported="false"
    android:screenOrientation="portrait" >
</activity>
<activity android:name="com.sina.weibo.sdk.web.WeiboSdkWebActivity"
    android:configChanges="keyboardHidden|orientation"
    android:exported="false"
    android:windowSoftInputMode="adjustResize"
    >
</activity>
<activity
    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
    android:launchMode="singleTask"
    android:name="com.sina.weibo.sdk.share.WbShareTransActivity">
    <intent-filter>
        <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>


<!--qq-->
<activity
    android:name="com.tencent.tauth.AuthActivity"
    android:launchMode="singleTask"
    android:noHistory="true" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="tencent100424468" />
    </intent-filter>
</activity>
<activity
    android:name="com.tencent.connect.common.AssistActivity"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:configChanges="orientation|keyboardHidden|screenSize"/>
 
MyApplication类:
public class MyApplication extends Application {
    {
            PlatformConfig.setWeixin("wx967daebe835fbeac","5bb696d9ccd75a38c8a0bfe0675559b3");
        PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
        PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad","http://sns.whalecloud.com");
}
    @Override
    public void onCreate() {
        super.onCreate();
        // UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE, "1fe6a20054bcef865eeb0991ee84525b");
        UMConfigure.init(this,"5a12384aa40fa3551f0001d1"
                ,"umeng",UMConfigure.DEVICE_TYPE_PHONE,"");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0

        // UMShareAPI.get(this);
    }
}
MainActivity主类:
public class MainActivity extends AppCompatActivity {

    @BindView(R.id.Dai_Btn)
    Button DaiBtn;
    @BindView(R.id.No_Dai_Btn)
    Button NoDaiBtn;
    @BindView(R.id.Login_Btn)
    Button LoginBtn;
    private UMAuthListener umAuthListener;
    private UMShareListener umShareListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        if (Build.VERSION.SDK_INT >= 23) {
            String[] mPermissionList = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CALL_PHONE, Manifest.permission.READ_LOGS, Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.SET_DEBUG_APP, Manifest.permission.SYSTEM_ALERT_WINDOW, Manifest.permission.GET_ACCOUNTS, Manifest.permission.WRITE_APN_SETTINGS};
            ActivityCompat.requestPermissions(this, mPermissionList, 123);
        }


        //⑧分享的监听
        umShareListener = new UMShareListener() {
            @Override
            public void onStart(SHARE_MEDIA share_media) {
                Log.e("onStart", "onStart");
            }

            @Override
            public void onResult(SHARE_MEDIA share_media) {
                Log.e("onResult", "onResult");
            }

            @Override
            public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                Log.e("onError", "onError");
            }

            @Override
            public void onCancel(SHARE_MEDIA share_media) {
                Log.e("onCancel", "onCancel");
            }
        };

//⑦授权登陆的监听
        //授权成功了。map里面就封装了一些qq信息
/* tv.setText(map.get("name"));
 Picasso.with(MainActivity.this).load(map.get("iconurl")).into(iv);*/
        umAuthListener = new UMAuthListener() {
            @Override
            public void onStart(SHARE_MEDIA share_media) {
                Log.e("onStart", "onStart");
            }

            //授权成功了。map里面就封装了一些qq信息
            @Override
            public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
           /* tv.setText(map.get("name"));
            Picasso.with(MainActivity.this).load(map.get("iconurl")).into(iv);*/
            }

            @Override
            public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
                Log.e("onError", "onError");
            }

            @Override
            public void onCancel(SHARE_MEDIA share_media, int i) {
                Log.e("onCancel", "onCancel");
            }
        };
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }




    private void getDaiMianBan() {
        new ShareAction(MainActivity.this)
                .withText("hello")
                .setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN)
                .setCallback(umShareListener)
                .withMedia(new UMImage(MainActivity.this, R.mipmap.ic_launcher))
                .open();
    }

    private void getNoDaiMianBan() {
        UMImage umImage = new UMImage(MainActivity.this, R.mipmap.ic_launcher);
        new ShareAction(MainActivity.this)
                .setPlatform(SHARE_MEDIA.QZONE)//传入平台
                .withText("hello")//分享内容
                .withMedia(umImage)
                .setCallback(umShareListener)//回调监听器
                .share();
    }

    // ⑥授权分享
    private void getLogin() {
        UMShareAPI mShareAPI = UMShareAPI.get(MainActivity.this);
        mShareAPI.getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, umAuthListener);
    }


    @OnClick({R.id.Dai_Btn, R.id.No_Dai_Btn, R.id.Login_Btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.Dai_Btn:
                getDaiMianBan();
                break;
            case R.id.No_Dai_Btn:
                getNoDaiMianBan();
                break;
            case R.id.Login_Btn:
                getLogin();
                break;
        }
    }
}

布局:

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:text="带面板"
        android:id="@+id/Dai_Btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button
        android:text="不带面板"
        android:id="@+id/No_Dai_Btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button
        android:text="登录"
        android:id="@+id/Login_Btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值