activity
package lqy.bwie.com.hhd;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
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 android.widget.Toast;
import com.squareup.picasso.Picasso;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareConfig;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import java.util.Map;
import java.util.Set;
public class MainActivity extends AppCompatActivity {
private Button mBtnQQ, mBtnQQShare;
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBtnQQ = findViewById(R.id.btn_qq);
mBtnQQShare = findViewById(R.id.btn_qq_share);
tv = findViewById(R.id.tv);
// checkPermission();
mBtnQQ.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
UMShareConfig umShareConfig = new UMShareConfig();
umShareConfig.isNeedAuthOnGetUserInfo(true);
UMShareAPI.get(MainActivity.this).setShareConfig(umShareConfig);
UMShareAPI.get(MainActivity.this).getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA share_media) {
// Intent intent = new Intent(MainActivity.this, Main2Activity.class);
// startActivity(intent);
}
@Override
public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
//获取用户信息
Set<String> set= map.keySet();
String str = map.get("name");
tv.setText(str);
}
@Override
public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
Log.i("dj", "UMAuthListener onError" + throwable.getLocalizedMessage());
}
@Override
public void onCancel(SHARE_MEDIA share_media, int i) {
Log.i("dj", "UMAuthListener onCancel");
}
});
}
});
mBtnQQShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
UMImage umImage = new UMImage(MainActivity.this, R.drawable.ic_launcher_background);
new ShareAction(MainActivity.this)
.withText("hh")
.withMedia(umImage)
.setDisplayList(SHARE_MEDIA.QQ)
.setCallback(new UMShareListener() {
@Override
public void onStart(SHARE_MEDIA share_media) {
}
@Override
public void onResult(SHARE_MEDIA share_media) {
}
@Override
public void onError(SHARE_MEDIA share_media, Throwable throwable) {
}
@Override
public void onCancel(SHARE_MEDIA share_media) {
}
})
.open();
}
});
}
// private void checkPermission() {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// String[] mPermissionList = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
// Manifest.permission.ACCESS_FINE_LOCATION,
// Manifest.permission.CALL_PHONE,
// Manifest.permission.READ_LOGS,
// Manifest.permission.READ_PHONE_STATE,
// Manifest.permission.READ_EXTERNAL_STORAGE,
// Manifest.permission.SET_DEBUG_APP,
// Manifest.permission.SYSTEM_ALERT_WINDOW,
// Manifest.permission.GET_ACCOUNTS,
// Manifest.permission.WRITE_APN_SETTINGS};
// ActivityCompat.requestPermissions(this, mPermissionList, 123);
// }
// }
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}