友盟分享

配置清单





在build。gradel添加依赖

defaultConfig{

添加    manifestPlaceholders= [qqappid:"101921073"]

}


添加依赖包
implementation files('libs/umeng-asms-v1.1.4.aar'// asms包依赖(必选)

implementation'com.umeng.umsdk:common:9.3.3'

implementation'com.umeng.umsdk:share-core:7.1.3'

implementation'com.umeng.umsdk:share-board:7.1.3'

implementation'com.umeng.umsdk:share-qq:7.1.3'

implementation'com.umeng.umsdk:share-sina:7.1.3'

implementation'com.sina.weibo.sdk:core:4.4.3:openDefaultRelease@aar'

在另外一个build.gradle中添加依赖

repositories{

maven{ url'https://dl.bintray.com/umsdk/release' }

    maven{ url"https://dl.bintray.com/thelasterstar/maven/" }

}

allprojects{

        maven{ url'https://dl.bintray.com/umsdk/release' }

        maven{ url"https://dl.bintray.com/thelasterstar/maven/" }

}

}

在proguard--rules中添加混淆文件


-dontshrink

-dontoptimize

-dontwarncom.google.android.maps.**

-dontwarnandroid.webkit.WebView

-dontwarncom.umeng.**

-dontwarncom.tencent.weibo.sdk.**

-dontwarncom.facebook.**

-keep public classjavax.**

-keep public classandroid.webkit.**

-dontwarnandroid.support.v4.**

-keep enumcom.facebook.**

-keepattributesExceptions,InnerClasses,Signature

-keepattributes*Annotation*

-keepattributesSourceFile,LineNumberTable

-keep public interfacecom.facebook.**

-keep public interfacecom.tencent.**

-keep public interfacecom.umeng.socialize.**

-keep public interfacecom.umeng.socialize.sensor.**

-keep public interfacecom.umeng.scrshot.**

-keep public classcom.umeng.socialize.* {*;}

-keep classcom.umeng.** {*;}

-keep classcom.facebook.**

-keep classcom.facebook.** {*;}

-keep classcom.umeng.scrshot.**

-keep public classcom.tencent.** {*;}

-keep classcom.umeng.socialize.sensor.**

-keep classcom.umeng.socialize.handler.**

-keep classcom.umeng.socialize.handler.*

-keep classcom.umeng.weixin.handler.**

-keep classcom.umeng.weixin.handler.*

-keep classcom.umeng.qq.handler.**

-keep classcom.umeng.qq.handler.*

-keep classUMMoreHandler{*;}

-keep classcom.tencent.mm.sdk.modelmsg.WXMediaMessage {*;}

-keep classcom.tencent.mm.sdk.modelmsg.** implementscom.tencent.mm.sdk.modelmsg.WXMediaMessage$IMediaObject {*;}

-keep classim.yixin.sdk.api.YXMessage {*;}

-keep classim.yixin.sdk.api.** implementsim.yixin.sdk.api.YXMessage$YXMessageData{*;}

-keep classcom.tencent.mm.sdk.** {

*;

}

-keep classcom.tencent.mm.opensdk.** {

*;

}

-keep classcom.tencent.wxop.** {

*;

}

-keep classcom.tencent.mm.sdk.** {

*;

}

-keep classcom.twitter.** { *; }

-keep classcom.tencent.** {*;}

-dontwarncom.tencent.**

-keep classcom.kakao.** {*;}

-dontwarncom.kakao.**

-keep public classcom.umeng.com.umeng.soexample.R$*{

public static final int *;

}

-keep public classcom.linkedin.android.mobilesdk.R$*{

public static final int *;

}

-keepclassmembers enum * {

public static **[]values();

public static **valueOf(java.lang.String);

}

-keep classcom.tencent.open.TDialog$*

-keep classcom.tencent.open.TDialog$* {*;}

-keep classcom.tencent.open.PKDialog

-keep classcom.tencent.open.PKDialog {*;}

-keep classcom.tencent.open.PKDialog$*

-keep classcom.tencent.open.PKDialog$* {*;}

-keep classcom.umeng.socialize.impl.ImageImpl {*;}

-keep classcom.sina.** {*;}

-dontwarncom.sina.**

-keep classcom.alipay.share.sdk.** {

*;

}

-keepnames class * implementsandroid.os.Parcelable {

public static final **CREATOR;

}

-keep classcom.linkedin.** { *; }

-keep classcom.android.dingtalk.share.ddsharemodule.** { *; }

-keepattributesSignature


MainActivity主页面点击按钮弹出分享

@Overridepublic void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); PermissionMgr.getInstance().onRequestPermissionsResult(this, requestCode, permissions, grantResults);}

public void share() { UMImage image = new UMImage(MainActivity.this, "http://ww4.sinaimg.cn/large/610dc034jw1f2uyg3nvq7j20gy0p6myx.jpg");//网络图片 image.setThumb(new UMImage(MainActivity.this, R.mipmap.ic_launcher_round)); new ShareAction(MainActivity.this).withText("这是分享奥斯卡奖地方").withMedia(image).setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ) .setCallback(umShareListener).open();}public UMShareListener umShareListener = new UMShareListener() { @Override public void onStart(SHARE_MEDIA share_media) { Toast.makeText(MainActivity.this, "开始分享", Toast.LENGTH_SHORT).show(); } @Override public void onResult(SHARE_MEDIA share_media) { Toast.makeText(MainActivity.this, "分享结果", Toast.LENGTH_SHORT).show(); } @Override public void onError(SHARE_MEDIA share_media, Throwable throwable) { Toast.makeText(MainActivity.this, "开始失败" + throwable.getMessage(), Toast.LENGTH_SHORT).show(); } @Override public void onCancel(SHARE_MEDIA share_media) { Toast.makeText(MainActivity.this, "分享取消", Toast.LENGTH_SHORT).show(); }};@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);}




PermissionMgr 这个权限类

private static final PermissionMgr sInstance =new PermissionMgr();

private static final int PERMISSION_REQUEST_CODE =1;

private static final String[]PERMISSIONS =new String[] {

android.Manifest.permission.INTERNET,

android.Manifest.permission.ACCESS_NETWORK_STATE,

Manifest.permission.READ_EXTERNAL_STORAGE,

android.Manifest.permission.ACCESS_WIFI_STATE,

android.Manifest.permission.WRITE_EXTERNAL_STORAGE};

private ListmPermissionList =new ArrayList();

private PermissionMgr() {}

public static PermissionMgr getInstance() {

return sInstance;

}

public void requestPermissions(Activity context) {

if (Build.VERSION.SDK_INT

return;

}

mPermissionList.clear();

for (String permission :PERMISSIONS) {

if (ActivityCompat.checkSelfPermission(context,permission) !=PERMISSION_GRANTED) {

mPermissionList.add(permission);

}

}

if (mPermissionList.size() >0) {

ActivityCompat.requestPermissions(context,mPermissionList.toArray(new String[]{}),PERMISSION_REQUEST_CODE);

}

}

public void onRequestPermissionsResult(Activity activity,int requestCode,String[] permissions,int[] grantResults) {

if (Build.VERSION.SDK_INT

return;

}

if (PERMISSION_REQUEST_CODE != requestCode) {

return;

}

for (int i =0; i < grantResults.length; i++) {

if (grantResults[i] ==PERMISSION_GRANTED) {

mPermissionList.remove(permissions[i]);

}

}

if (mPermissionList.isEmpty()) {

return;

}

if (showConfirmDialog(activity)) {

requestPermissions(activity);

return;

}

askForPermission(activity);

}

private boolean showConfirmDialog(Activity activity) {

if (Build.VERSION.SDK_INT

return false;

}

for (String permission :mPermissionList) {

// 还可以弹框确认

        if (activity.shouldShowRequestPermissionRationale(permission)) {

return true;

}

}

return false;

}

private void askForPermission(final Activity activity) {

AlertDialog.Builder builder =new AlertDialog.Builder(activity);

builder.setTitle("Need Permission!");

builder.setPositiveButton("Settings",new DialogInterface.OnClickListener() {

@Override

        public void onClick(DialogInterface dialog,int which) {

Intent intent =new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);

intent.setData(Uri.parse("package:" +activity.getPackageName()));// 根据包名打开对应的设置界面

            activity.startActivity(intent);

}

});

builder.setCancelable(false);

builder.create().show();

}

MyApplication配置类 

@Override

public void onCreate() {

super.onCreate();

UMConfigure.init(this,"5fe15d17345b8b53f575e1e5"

            ,"umeng",UMConfigure.DEVICE_TYPE_PHONE,"");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0

    // QQ设置

    PlatformConfig.setQQZone("101921073","38a314d9c8acadf3d3fe056cf908a2ad");

PlatformConfig.setQQFileProvider("com.gy.myapplication.fileprovider");

// 其他平台设置

    PlatformConfig.setSinaWeibo("2779483073","3fcbcd9df63e095b8168202bae259465","http://www.sina.com");

}

在这有我们需要的arr包 D:\AndroidStudioProjects\20031A\share\app\libs

你可能感兴趣的:(友盟分享)