欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android第三方登录之QQ登录

程序员文章站 2023-12-02 17:37:04
本文实例为大家分享了android第三方登录之qq的具体代码,供大家参考,具体内容如下 第三方登录之qq 代码区 public class mainact...

本文实例为大家分享了android第三方登录之qq的具体代码,供大家参考,具体内容如下

第三方登录之qq

代码区

public class mainactivity extends appcompatactivity {

 private button btn;
 private textview tv;
 private imageview image;

 @override
 protected void oncreate(bundle savedinstancestate) {
  super.oncreate(savedinstancestate);
  setcontentview(r.layout.activity_main);
  btn = (button) findviewbyid(r.id.btn);
  tv = (textview) findviewbyid(r.id.tv);
  image = (imageview) findviewbyid(r.id.image);
  btn.setonclicklistener(new view.onclicklistener() {
   @override
   public void onclick(view view) {
    umshareapi.get(mainactivity.this).getplatforminfo(mainactivity.this, share_media.qq, umauthlistener);
   }
  });
 }
 private umauthlistener umauthlistener = new umauthlistener() {
  @override
  public void onstart(share_media platform) {
   //授权开始的回调
  }
  @override
  public void oncomplete(share_media platform, int action, map<string, string> data) {
   toast.maketext(getapplicationcontext(), "authorize succeed", toast.length_short).show();
   string name = data.get("name");
   string gender = data.get("gender");
   string photourl = data.get("iconurl");
   tv.settext(name + " " +gender);
   imageloader.getinstance().displayimage(photourl,image);
  }

  @override
  public void onerror(share_media platform, int action, throwable t) {
   toast.maketext( getapplicationcontext(), "authorize fail", toast.length_short).show();
  }

  @override
  public void oncancel(share_media platform, int action) {
   toast.maketext( getapplicationcontext(), "authorize cancel", toast.length_short).show();
  }
 };
 @override
 protected void onactivityresult(int requestcode, int resultcode, intent data) {
  super.onactivityresult(requestcode, resultcode, data);
  umshareapi.get(this).onactivityresult(requestcode, resultcode, data);
 }
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.qqqqq">
 <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" />
 <application android:allowbackup="true" android:icon="@mipmap/ic_launcher"
  android:label="@string/app_name" android:roundicon="@mipmap/ic_launcher_round"
  android:supportsrtl="true" android:theme="@style/apptheme"
  android:name=".appliction">
  <activity android:name=".mainactivity">
   <intent-filter>
    <action android:name="android.intent.action.main" />

    <category android:name="android.intent.category.launcher" />
   </intent-filter>
  </activity>
  <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:screenorientation="portrait"
   android:theme="@android:style/theme.translucent.notitlebar"
   android:configchanges="orientation|keyboardhidden|screensize"/>


 </application>
 <meta-data
  android:name="umeng_appkey"
  android:value="59af450107fe652856001419" >
 </meta-data>
</manifest>
buildtypes {
 release {
  minifyenabled false
  signingconfig signingconfigs.debug
  proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'
 }
 debug {
  minifyenabled false
  signingconfig signingconfigs.debug
  proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'
 }
}
signingconfigs {
 debug {
  storefile file('debug.keystore')
  storepassword "android"
  keyalias "androiddebugkey"
  keypassword "android"
 }
}

附带一张照片

Android第三方登录之QQ登录

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。