友盟官网
将集成的包里面的东西都复制进项目里面libs,res分别复制进去
libs里面的jar包 add to module
新建App继承application
public class App extends Application{
@Override
public void onCreate() {
super.onCreate();
UMShareAPI.get(this);
}
{
PlatformConfig.setWeixin("wx967daebe835fbeac", "5bb696d9ccd75a38c8a0bfe0675559b3");
PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad", "http://sns.whalecloud.com");
}
}
清单文件中引入
<application
android:name=".App"
</application>
清单文件中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lianxiday07_um_denglu">
<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:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="UMENG_APPKEY"
android:value="561cae6ae0f55abd990035bf" >
</meta-data>
<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>
</manifest>
activity_main
MainActivity<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:onClick="dianji" android:text="点击QQ登录" android:layout_width="match_parent" android:layout_height="wrap_content" /> </RelativeLayout>
public class MainActivity extends AppCompatActivity { private UMShareAPI mShareAPI; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mShareAPI = UMShareAPI.get(this); } public void dianji(View view){ new ShareAction(MainActivity.this); mShareAPI.getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, authListener); //其中umAuthListener为授权回调,构建如下: } UMAuthListener authListener = new UMAuthListener() { /** * @desc 授权开始的回调 * @param platform 平台名称 */ public void onStart(SHARE_MEDIA platform) { } /** * @desc 授权成功的回调 * @param platform 平台名称 * @param action 行为序号,开发者用不上 * @param data 用户资料返回 */ public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) { } /** * @desc 授权失败的回调 * @param platform 平台名称 * @param action 行为序号,开发者用不上 * @param t 错误原因 */ public void onError(SHARE_MEDIA platform, int action, Throwable t) { } /** * @desc 授权取消的回调 * @param platform 平台名称 * @param action 行为序号,开发者用不上 */ public void onCancel(SHARE_MEDIA platform, int action) { } }; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data); } }