第一
ivDialogbg.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
showSelectAlerts(Contants.EXCHANGE_BANNER_ICON_URL +lbb.getMsg());
return false;
}
});
第二
private void showSelectAlerts(final String url) {//专属二维码
AlertDialog.Builder builder =new AlertDialog.Builder(getActivity());
String str[] = {"发送给朋友", "保存到手机", "识别图中二维码"};
builder.setItems(str, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterfacem, int i) {
switch (i) {
case 0:
showShare(url);
// Toast.makeText(getActivity(),"发送给朋友",Toast.LENGTH_LONG).show();
break;
case 1:
// Toast.makeText(getActivity(),"保存图片",Toast.LENGTH_LONG).show();
Glide.with(getActivity()).load(url).asBitmap().toBytes().into(new SimpleTarget() {
@Override
public void onResourceReady(byte[] bytes, GlideAnimation glideAnimation) {
try {
savaBitmap(bytes);
}catch (Exception e) {
e.printStackTrace();
}
}
});
break;
case 2:
SharedPreferences sp = getActivity().getSharedPreferences("loginNum", MODE_PRIVATE);
int userid = sp.getInt("userId",-1);
String mobile = sp.getString("mobile","-1");
Intent intents =new Intent(getActivity(), RegisterActivity.class);
intents.putExtra("userid", userid);
intents.putExtra("mobile", mobile);
startActivity(intents);
break;
}
}
});
builder.show();
}
第三部分 单独转分享
集成mobSDK 也是ShareSDK
1,在项目外部build.gradle 中 设置如下
dependencies {
classpath'com.android.tools.build:gradle:3.1.2'
classpath'com.mob.sdk:MobSDK:+' //重点
}
2,在项目APP中的build.gradle 中 配置需要分享的SDK
applyplugin:'com.mob.sdk'
android{
......
MobSDK {
appKey"27ed99e83d379"
appSecret"7b2519037aa8e66f26c5f1d82dc5adae"
ShareSDK {
//平台配置信息
devInfo {
SinaWeibo {
appKey"568898243"
appSecret"38a4f8204cc784f81f9f0daaf31e02e3"
callbackUri"http://www.sharesdk.cn"
shareByAppClientfalse
}
Wechat {
id4
sortId4
appId"wx4868b35061f87885"
appSecret"64020361b8ec4c99936c0e3999a9f249"
userName"gh_afb25ac019c9"
path "pages/index/index.html?id=1"
bypassApprovaltrue
enabletrue
}
WechatMoments{
Id="5"
SortId="5"
AppId="wxf8b14da3087d67b2"
AppSecret="wxf8b14da3087d67b2"
BypassApproval="true"
Enable="true"
}
QQ {
appId"100371282"
appKey"aed9b0303e3ed1e27bae87c33761161d"
shareByAppClienttrue
}
// Facebook {
// appKey "1412473428822331"
// appSecret "a42f4f3f867dc947b9ed6020c2e93558"
// callbackUri "https://mob.com"
// }
}
}
}
}
3,使用如下
private void showShare(String url) {
OnekeyShare oks =new OnekeyShare();
//关闭sso授权
oks.disableSSOWhenAuthorize();
// oks.setTitle("123");
// oks.setText("12");
// oks.setTitleUrl("http://www.sina.com/");
// oks.setUrl("http://www.sina.com/");
oks.setImageUrl(url);
oks.setTheme(OnekeyShareTheme.CLASSIC);
// title标题,微信、QQ和QQ空间等平台使用
// oks.setTitle(getString(R.string.share));
// titleUrl QQ和QQ空间跳转链接
// oks.setTitleUrl("http://sharesdk.cn");
// text是分享文本,所有平台都需要这个字段
// oks.setText("我是分享文本");
// imagePath是图片的本地路径,Linked-In以外的平台都支持此参数
// oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
// url在微信、微博,Facebook等平台中使用
// oks.setUrl(url);
// comment是我对这条分享的评论,仅在人人网使用
// oks.setComment("我是测试评论文本");
oks.setCallback(new PlatformActionListener() {
@Override
public void onComplete(final Platform platform, int i, final HashMap hashMap) {
Message msg =new Message();
msg.what =0;
msg.obj = platform;
new Handler(Looper.getMainLooper(), new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
platform.getName().equals(Wechat.NAME);
Toast.makeText(getContext(), "分享成功", Toast.LENGTH_SHORT).show();
ewmDialog.setVisibility(View.GONE);
return false;
}
}).sendMessage(msg);
platform.removeAccount(true);
}
@Override
public void onError(Platform platform, int i, final Throwable throwable) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), "分享失败" +throwable.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onCancel(Platform platform, int i) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), "分享取消", Toast.LENGTH_SHORT).show();
}
});
}
});
// 启动分享GUI
oks.show(getActivity());
}