需要在libs下面导入4个Jar包
SocialSDK_QQ_Simplify.jar QQJar包
main -- 核心库
需要在项目中导入 debug.keystore 文件
清单文件 需要导入{
<activity android:name="com.umeng.qq.tencent.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.umeng.qq.tencent.AssistActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar"/> application>
<meta-data android:name="UMENG_APPKEY" android:value="58c36c5de88bad39c6000f73"> meta-data>
}
继承类 配置 aoolication
@Override public void onCreate() { super.onCreate(); UMShareAPI.get(this); } { PlatformConfig.setQQZone("1106036236", "mjFCi0oxXZKZEWJs"); } 在activity 下 监听事件{
findViewById(R.id.texts).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { UMShareAPI mShareAPI = UMShareAPI.get(MainActivity.this); mShareAPI.getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, new UMAuthListener() { @Override public void onStart(SHARE_MEDIA platform) { //授权开始的回调 } @Override public void onComplete(SHARE_MEDIA platform, int action, Mapdata) { Toast.makeText(getApplicationContext(), "Authorize succeed", Toast.LENGTH_SHORT).show();
String profile_image_url = data.get("profile_image_url"); String name = data.get("name"); loginTrue(name, profile_image_url); if (platform.equals(SHARE_MEDIA.QQ)) { SharedPreferences.Editor edit = loginInfo.edit(); addUser(edit, name, profile_image_url); }
} @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); }
private void loginTrue(String name, String icon_image) { login_true.setVisibility(RelativeLayout.VISIBLE); login_flase.setVisibility(RelativeLayout.GONE); login_name.setText(name); ImageLoader.getInstance().displayImage(icon_image, login_icon); }
//传入Sp
private void addUser(SharedPreferences.Editor edit, String name, String imageUrl) { edit.putBoolean("flig", true); edit.putString("name", name); edit.putString("icon_image", imageUrl); edit.commit(); }
build.gradle配置
{
buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } signingConfigs { debug { storeFile file('debug.keystore') storePassword "android" keyAlias "androiddebugkey" keyPassword "android" } }
}