在drawable里还要加上图片 这里没有图片自己努力吧
自己创建的App别忘了在清单文件里配置
首先导依赖
compile 'com.umeng.sdk:common:latest.integration' compile 'com.umeng.sdk:analytics:latest.integration'
这个是加在最外边那个build里的
allprojects { repositories { jcenter() //在大的build加上这句话 mavenCentral() } }
导jar包 加在libs里的 现在的是最后生成好的在build里
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')
清单文件加权限
<!-- 必须的权限 --> <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" />
在清单文件<application></application>里配置
<meta-data android:value="YOUR_APP_KEY" android:name="UMENG_APPKEY"/> <meta-data android:value="Channel ID" android:name="UMENG_CHANNEL"/> <!-- 新浪 的--> <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" />
在layout里写上这三个绿色xml
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>
umeng_socialize_oauth_dialog.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#D4E0E5"> <RelativeLayout android:id="@+id/umeng_socialize_titlebar" android:layout_width="match_parent" android:layout_height="54dp" android:background="#0086DC"> <TextView android:id="@+id/umeng_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="" android:textColor="#ffffff" android:textSize="18sp" /> <RelativeLayout android:id="@+id/umeng_back" android:layout_width="60dp" android:layout_height="match_parent" android:onClick="onCancel" android:visibility="visible"> <ImageButton android:layout_width="12dp" android:layout_height="20dp" android:layout_centerVertical="true" android:background="@drawable/umeng_socialize_back_icon" android:layout_marginLeft="15dp" android:scaleType="center" /> </RelativeLayout> <TextView android:id="@+id/umeng_share_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerInParent="true" android:layout_marginRight="10dp" android:background="@drawable/umeng_socialize_btn_bg" android:padding="4dp" android:text="分享" android:textColor="#ffffff" /> </RelativeLayout> <RelativeLayout android:id="@+id/umeng_socialize_follow" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_alignParentBottom="true" android:background="#AAAAAA" android:visibility="visible"> <CheckBox android:id="@+id/umeng_socialize_follow_check" android:layout_width="20dp" android:layout_height="20dp" android:layout_centerVertical="true" android:layout_marginLeft="20dp" android:checked="true" android:visibility="gone" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@id/umeng_socialize_follow_check" android:text="关注官方微博" android:textColor="#f8f8f8" android:textSize="16sp" android:visibility="gone" /> </RelativeLayout> <!--<LinearLayout--> <!--android:id="@+id/webView_container"--> <!--android:layout_width="match_parent"--> <!--android:layout_height="match_parent"--> <!--android:layout_above="@id/umeng_socialize_follow"--> <!--android:layout_below="@id/umeng_socialize_titlebar"--> <!--android:orientation="horizontal"--> <!--android:visibility="visible" />--> <WebView android:id="@+id/webView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#F2F5F6" android:layout_above="@id/umeng_socialize_follow" android:layout_below="@id/umeng_socialize_titlebar" android:visibility="visible" /> <RelativeLayout android:id="@+id/progress_bar_parent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/umeng_socialize_titlebar" android:background="#F2F5F6" > <LinearLayout android:layout_width="80dp" android:layout_height="80dp" android:layout_centerInParent="true" android:orientation="horizontal"> <ProgressBar android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="10dp" /> </LinearLayout> </RelativeLayout> </RelativeLayout>
umeng_socialize_share.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#D4E0E5" android:id="@+id/root" android:orientation="vertical"> <RelativeLayout android:id="@+id/umeng_socialize_share_titlebar" android:layout_width="match_parent" android:layout_height="54dp" android:background="#0086DC"> <TextView android:id="@+id/umeng_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="" android:textColor="#ffffff" android:textSize="18sp" /> <RelativeLayout android:id="@+id/umeng_back" android:layout_width="50dp" android:layout_height="match_parent" android:onClick="onCancel" android:visibility="visible"> <ImageButton android:layout_width="12dp" android:layout_height="20dp" android:layout_centerVertical="true" android:layout_marginLeft="15dp" android:background="@drawable/umeng_socialize_back_icon" android:clickable="false" android:scaleType="center" /> </RelativeLayout> <TextView android:id="@+id/umeng_share_btn" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_centerInParent="true" android:gravity="center_vertical" android:paddingLeft="15dp" android:paddingRight="15dp" android:text="分享" android:textColor="#ffffff" android:textSize="15sp" /> </RelativeLayout> <EditText android:id="@+id/umeng_socialize_share_edittext" android:layout_width="fill_parent" android:layout_height="180dp" android:layout_below="@id/umeng_socialize_share_titlebar" android:paddingLeft="15dp" android:paddingRight="15dp" android:paddingTop="8dp" android:background="#ffffff" android:bufferType="spannable" android:gravity="top" android:hint="编辑分享内容" android:lineSpacingExtra="3dp" android:paddingBottom="10dp" android:textColor="#000000" android:textSize="15sp" /> <TextView android:id="@+id/umeng_socialize_share_word_num" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignRight="@id/umeng_socialize_share_edittext" android:background="#ffffff" android:layout_below="@id/umeng_socialize_share_edittext" android:paddingBottom="10dp" android:paddingRight="15dp" android:gravity="right" android:singleLine="true" android:textColor="#98999B" android:textSize="14sp" /> <RelativeLayout android:id="@+id/umeng_socialize_share_bottom_area" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/umeng_socialize_share_word_num" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:background="#F2F5F6" android:visibility="gone"> <RelativeLayout android:layout_width="62dp" android:layout_height="62dp" android:layout_centerVertical="true" android:layout_marginBottom="15dp" android:layout_marginLeft="15dp" android:id="@+id/umeng_image_edge" android:layout_marginTop="15dp" android:background="@drawable/umeng_socialize_edit_bg" > <ImageView android:id="@+id/umeng_share_icon" android:layout_width="60dp" android:layout_height="60dp" android:layout_centerInParent="true" android:src="#2c3035" /> </RelativeLayout> <TextView android:layout_width="280dp" android:id="@+id/umeng_web_title" android:layout_toRightOf="@id/umeng_image_edge" android:layout_marginLeft="40dp" android:layout_marginTop="20dp" android:textColor="#575A5C" android:singleLine="true" android:textSize="14sp" android:visibility="gone" android:layout_height="wrap_content" /> <ImageView android:id="@+id/umeng_del" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignRight="@id/umeng_image_edge" android:layout_alignTop="@id/umeng_image_edge" android:layout_marginRight="-10dp" android:layout_marginTop="-10dp" android:background="@drawable/umeng_socialize_delete" /> </RelativeLayout> </RelativeLayout>
在values里写上这四个红色xml
umeng_socialize_colors.xml
<?xml version="1.0" encoding="utf-8"?><resources> <!--<color name="umeng_socialize_list_item_bgcolor">#FFFFFF</color>--> <!--<color name="umeng_socialize_divider">#E6E6E6</color>--> <!--<color name="umeng_socialize_text_time">#999999</color>--> <!--<color name="umeng_socialize_text_title">#464f61</color>--> <!--<color name="umeng_socialize_text_friends_list">#959696</color>--> <!--<color name="umeng_socialize_text_share_content">#666666</color>--> <!--<color name="umeng_socialize_ucenter_bg">#EEEEEE</color>--> <!--<color name="umeng_socialize_text_ucenter">#595959</color>--> <!--<color name="umeng_socialize_edit_bg">#C4C4C4</color>--> <!--<color name="umeng_socialize_grid_divider_line">#F8F8F8</color>--> <!--<color name="umeng_socialize_web_bg">#F4F4F4</color>--> <!--<color name="umeng_socialize_shareactivity">#D4E0E5</color>--> <!--<color name="umeng_socialize_shareactivitydefault">#ffffff</color>--> </resources>
umeng_socialize_shareview_strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="umeng_socialize_sharetosina">分享到新浪微博</string> <string name="umeng_socialize_sharetodouban">分享到豆瓣</string> <string name="umeng_socialize_sharetorenren">分享到人人网</string> <string name="umeng_socialize_sharetotencent">分享到腾讯微博</string> <string name="umeng_socialize_sharetotwitter">分享到twitter</string> <string name="umeng_socialize_sharetolinkin">分享到领英</string> </resources>
umeng_socialize_strings.xml 这里面啥也没有加上就行
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- 平台名称 --> </resources>
umeng_socialize_style.xml
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <!--<style name="ACPLDialog">--> <!--<item name="android:windowFrame">@null</item>--> <!--<item name="android:windowNoTitle">true</item>--> <!--<item name="android:windowIsFloating">true</item>--> <!--<item name="android:windowContentOverlay">@null</item>--> <!--</style>--> <!--<style name="umeng_socialize_action_bar_itemlayout">--> <!--<item name="android:layout_height">fill_parent</item>--> <!--<item name="android:layout_width">fill_parent</item>--> <!--<item name="android:layout_weight">1</item>--> <!--<item name="android:paddingLeft">4dp</item>--> <!--<item name="android:paddingTop">4dp</item>--> <!--<item name="android:paddingRight">4dp</item>--> <!--<item name="android:gravity">center_vertical</item>--> <!--</style>--> <!--<style name="umeng_socialize_action_bar_item_im">--> <!--<item name="android:layout_width">25dp</item>--> <!--<item name="android:layout_height">25dp</item>--> <!--<item name="android:scaleType">fitCenter</item>--> <!--<item name="android:layout_centerVertical">true</item>--> <!--</style>--> <!--<style name="umeng_socialize_action_bar_item_tv">--> <!--<item name="android:layout_width">wrap_content</item>--> <!--<item name="android:layout_height">fill_parent</item>--> <!--<item name="android:layout_marginLeft">5dp</item>--> <!--<item name="android:text">999</item>--> <!--<item name="android:gravity">center</item>--> <!--<item name="android:textColor">#ffffff</item>--> <!--<item name="android:textSize">12sp</item>--> <!--<item name="android:textStyle">bold</item>--> <!--</style>--> <!--网页授权的布局--> <style name="umeng_socialize_popup_dialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> <item name="android:background">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:backgroundDimEnabled">true</item> <item name="android:backgroundDimAmount">0.6</item> </style> <!--<style name="Theme.UMDialog" parent="android:style/Theme.Dialog">--> <!--<item name="android:windowNoTitle">true</item>--> <!--<item name="android:windowBackground">@android:color/transparent</item>--> <!--</style>--> <style name="Theme.UMDefault" parent="android:style/Theme.NoTitleBar"></style> <!--<style name="umeng_socialize_divider">--> <!--<item name="android:layout_width">fill_parent</item>--> <!--<item name="android:layout_height">1dp</item>--> <!--<item name="android:background">@color/umeng_socialize_divider</item>--> <!--</style>--> <!--<style name="umeng_socialize_list_item">--> <!--<item name="android:layout_width">fill_parent</item>--> <!--<item name="android:layout_height">55dp</item>--> <!--<item name="android:background">@color/umeng_socialize_list_item_bgcolor</item>--> <!--<item name="android:paddingBottom">5dp</item>--> <!--<item name="android:paddingTop">5dp</item>--> <!--</style>--> <!--<style name="umeng_socialize_edit_padding">--> <!--<item name="android:layout_width">fill_parent</item>--> <!--<item name="android:layout_height">fill_parent</item>--> <!--<item name="android:background">@color/umeng_socialize_list_item_bgcolor</item>--> <!--<item name="android:layout_marginLeft">6dp</item>--> <!--<item name="android:layout_marginRight">6dp</item>--> <!--<item name="android:layout_marginTop">6dp</item>--> <!--<item name="android:layout_marginBottom">6dp</item>--> <!--</style>--> </resources>
写一个类继承Application
package com.bw.ym.app; import android.app.Application; import com.umeng.analytics.MobclickAgent; import com.umeng.commonsdk.UMConfigure; import com.umeng.socialize.PlatformConfig; import com.umeng.socialize.UMShareAPI; /** * Created by lenovo on 2018/3/21. */ public class App 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); } }
在MainActivity按钮点击分享
package com.bw.ym; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.Toast; import com.umeng.analytics.MobclickAgent; import com.umeng.socialize.ShareAction; import com.umeng.socialize.UMShareAPI; import com.umeng.socialize.UMShareListener; import com.umeng.socialize.bean.SHARE_MEDIA; import com.umeng.socialize.media.UMImage; public class MainActivity extends AppCompatActivity implements View.OnClickListener { /** * Hello World! */ private Button mBtn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } 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); } private void initView() { mBtn = (Button) findViewById(R.id.btn); mBtn.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { default: break; case R.id.btn: 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(); break; } } }
但是我有图片 哈哈哈嗝儿