在项目的build里添加红色部分
allprojects { repositories { jcenter() mavenCentral() } }
在APP里进行加依赖
compile 'com.umeng.sdk:common:latest.integration' compile 'com.umeng.sdk:analytics:latest.integration' compile files('libs/SocialSDK_QQ_Simplify.jar') compile files('libs/SocialSDK_Sina_Simplify.jar') compile files('libs/SocialSDK_WeChat_Simplify.jar') compile files('libs/umeng_shareboard_widget.jar') compile files('libs/umeng_social_api.jar') compile files('libs/umeng_social_net.jar') compile files('libs/umeng_social_shareboard.jar') compile files('libs/umeng_social_shareview.jar') compile files('libs/umeng_social_tool.jar')
创建一个APP 继承Application
public class Myapp extends Application { //三方的key { 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"); MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL); //初使 UMShareAPI.get(this); } }
在AndroidManifest.xml进行配置
先加权限
<!-- 必须的权限 --> <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.INTERNET" /> <!-- 推荐的权限 --> <!-- 添加如下权限,以便使用更多的第三方SDK和更精准的统计数据 --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
别忘了
android:name=".Myapp"然后在
<application>
里面加下面的代码
</application>
<!-- 新浪 的--> <activity android:name="com.umeng.socialize.media.WBShareCallBackActivity" android:configChanges="keyboardHidden|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="false" android:launchMode="singleTask" android:screenOrientation="portrait" > </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.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:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="orientation|keyboardHidden|screenSize"/> <!-- 分享编辑页--> <activity android:name="com.umeng.socialize.editorpage.ShareActivity" android:theme="@android:style/Theme.NoTitleBar" android:excludeFromRecents="true" /> <meta-data android:value="5aaf6a54f29d984ca4000148" android:name="UMENG_APPKEY"/> <meta-data android:value="Channel ID" android:name="UMENG_CHANNEL"/>
在layout写三个布局
1.socialize_share_menu_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical"> <com.umeng.socialize.shareboard.SocializeImageView android:id="@+id/socialize_image_view" android:layout_width="50dp" android:layout_height="50dp" android:padding="5dp" android:src="@drawable/umeng_socialize_menu_default" /> <TextView android:id="@+id/socialize_text_view" android:layout_width="63dp" android:layout_height="wrap_content" android:layout_marginTop="6dp" android:ellipsize="end" android:singleLine="true" android:text="未知" android:textSize="12sp" /> </LinearLayout>
2.umeng_socialize_oauth_dialog.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical"> <com.umeng.socialize.shareboard.SocializeImageView android:id="@+id/socialize_image_view" android:layout_width="50dp" android:layout_height="50dp" android:padding="5dp" android:src="@drawable/umeng_socialize_menu_default" /> <TextView android:id="@+id/socialize_text_view" android:layout_width="63dp" android:layout_height="wrap_content" android:layout_marginTop="6dp" android:ellipsize="end" android:singleLine="true" android:text="未知" android:textSize="12sp" /> </LinearLayout>3.umeng_socialize_share.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical"> <com.umeng.socialize.shareboard.SocializeImageView android:id="@+id/socialize_image_view" android:layout_width="50dp" android:layout_height="50dp" android:padding="5dp" android:src="@drawable/umeng_socialize_menu_default" /> <TextView android:id="@+id/socialize_text_view" android:layout_width="63dp" android:layout_height="wrap_content" android:layout_marginTop="6dp" android:ellipsize="end" android:singleLine="true" android:text="未知" android:textSize="12sp" /> </LinearLayout>4.activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.bw.myapplication.MainActivity"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@drawable/umeng_socialize_qq" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:id="@+id/qq" /> </RelativeLayout>
最后在Mainactivity写
public class MainActivity extends AppCompatActivity { private ImageView img; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img = (ImageView) findViewById(R.id.qq); img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { UMImage image=new UMImage(MainActivity.this,R.drawable.umeng_socialize_qq); new ShareAction(MainActivity.this).withMedia(image).setDisplayList(SHARE_MEDIA.SINA,SHARE_MEDIA.QQ,SHARE_MEDIA.WEIXIN) .setCallback(umShareListener).open(); } }); } private UMShareListener umShareListener = new UMShareListener() { /** * @descrption 分享开始的回调 * @param platform 平台类型 */ @Override public void onStart(SHARE_MEDIA platform) { } /** * @descrption 分享成功的回调 * @param platform 平台类型 */ @Override public void onResult(SHARE_MEDIA platform) { Toast.makeText(MainActivity.this,"成功 了",Toast.LENGTH_LONG).show(); } /** * @descrption 分享失败的回调 * @param platform 平台类型 * @param t 错误原因 */ @Override public void onError(SHARE_MEDIA platform, Throwable t) { Toast.makeText(MainActivity.this,"失 败"+t.getMessage(),Toast.LENGTH_LONG).show(); } /** * @descrption 分享取消的回调 * @param platform 平台类型 */ @Override public void onCancel(SHARE_MEDIA platform) { Toast.makeText(MainActivity.this,"取消 了",Toast.LENGTH_LONG).show(); } }; public void onResume() { super.onResume(); MobclickAgent.onResume(this); } public void onPause() { super.onPause(); MobclickAgent.onPause(this); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data); } }还有图片实在是没办法放 了 抱拳了老铁!