首先依赖
implementation 'com.github.bumptech.glide:glide:4.8.0' implementation 'com.squareup.picasso:picasso:2.3.2'
在app里面的 android下面加入
之后在清单文件中加入
这个包要是这个
App.java
import android.app.Application; import com.umeng.commonsdk.UMConfigure; import com.umeng.socialize.PlatformConfig; import com.umeng.socialize.UMShareAPI; /** * Created by lenovo on 2018/12/20. */ public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); UMConfigure.setLogEnabled(true); UMConfigure.init(this,"5a12384aa40fa3551f0001d1" ,"umeng", UMConfigure.DEVICE_TYPE_PHONE, "");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0 //打log UMConfigure.setLogEnabled(true); PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0"); PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba"); UMShareAPI.get(this); } }
主activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context="com.umeng.soexample.MainActivity"> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录" /> <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:src="@mipmap/ic_launcher" /> <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="XXXXXXXX" /> </LinearLayout>
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>
主MainActivity.java
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import com.squareup.picasso.Picasso; import com.umeng.socialize.UMAuthListener; import com.umeng.socialize.UMShareAPI; import com.umeng.socialize.UMShareConfig; import com.umeng.socialize.bean.SHARE_MEDIA; import java.util.Map; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Button btn; private ImageView image; private TextView text_view; private UMShareAPI umShareAPI; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn = findViewById(R.id.btn); btn.setOnClickListener(this); image = findViewById(R.id.image); text_view = findViewById(R.id.text_view); umShareAPI = UMShareAPI.get(this); } //------------------------------------------------------------------------------------------------------------------ //这个方法要放在Activity 中去 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.btn: UMShareConfig shareConfig = new UMShareConfig(); shareConfig.isNeedAuthOnGetUserInfo(true); UMShareAPI.get(MainActivity.this).setShareConfig(shareConfig); umShareAPI.getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, authListener); break; } } //给这个第三方一个监听-------------------------------------------------------------------------------------- public UMAuthListener authListener = new UMAuthListener() { @Override public void onStart(SHARE_MEDIA share_media) { } @Override public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) { text_view.setText(map.get("name").toString()); Picasso.with(MainActivity.this).load(map.get("profile_image_url")).into(image); // Glide.with(MainActivity.this).load(map.get("profile_image_url")).into(image); Log.i("quni ma de ", map.toString()); } @Override public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) { } @Override public void onCancel(SHARE_MEDIA share_media, int i) { } }; }