修改微信分享为Intent分享,不依赖sdk
This commit is contained in:
@@ -2,18 +2,18 @@ apply plugin: 'com.android.application'
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
signingConfigs { release {
|
signingConfigs { release {
|
||||||
storeFile file('./keystore/gamehall.keystore')
|
storeFile file('G:\\Works\\YouleApp\\harmonyos\\tsgame_ohos\\keystore\\daoqi_game_1.keystore')
|
||||||
storePassword 'tswl2015'
|
storePassword 'tswl0791'
|
||||||
keyPassword 'tswl2015'
|
keyPassword 'tswl0791'
|
||||||
keyAlias = 'gamehall'
|
keyAlias = 'gamehall'
|
||||||
v1SigningEnabled true
|
v1SigningEnabled true
|
||||||
v2SigningEnabled true
|
v2SigningEnabled true
|
||||||
}
|
}
|
||||||
|
|
||||||
debug {
|
debug {
|
||||||
storeFile file('./keystore/gamehall.keystore')
|
storeFile file('G:\\Works\\YouleApp\\harmonyos\\tsgame_ohos\\keystore\\daoqi_game_1.keystore')
|
||||||
storePassword 'tswl2015'
|
storePassword 'tswl0791'
|
||||||
keyPassword 'tswl2015'
|
keyPassword 'tswl0791'
|
||||||
keyAlias = 'gamehall'
|
keyAlias = 'gamehall'
|
||||||
v1SigningEnabled true
|
v1SigningEnabled true
|
||||||
v2SigningEnabled true
|
v2SigningEnabled true
|
||||||
|
|||||||
@@ -2,51 +2,26 @@ package com.jx.jyhd.simcpux.util;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.jx.jyhd.simcpux.Constants;
|
|
||||||
import com.jx.jyhd.simcpux.Util;
|
|
||||||
import com.jx.jyhd.wxapi.WXEntryActivity;
|
|
||||||
import com.tagmae.tsgame_erwang.utils.Base64ImageUtil;
|
import com.tagmae.tsgame_erwang.utils.Base64ImageUtil;
|
||||||
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
|
import com.tsgame.tsgame_niuniu.util.WeChatIntentShareUtil;
|
||||||
import com.tencent.mm.opensdk.modelmsg.WXImageObject;
|
|
||||||
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
|
|
||||||
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
|
|
||||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
|
||||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信分享工具类
|
* 微信分享工具类(已代理至无SDK版 WeChatIntentShareUtil)
|
||||||
*/
|
*/
|
||||||
public class WeChatShareUtil {
|
public class WeChatShareUtil {
|
||||||
|
|
||||||
private static final int THUMB_SIZE = 150;
|
|
||||||
private static WeChatShareUtil instance;
|
private static WeChatShareUtil instance;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final IWXAPI mWxApi;
|
|
||||||
private WeChatShareCallback mCallback;
|
private WeChatShareCallback mCallback;
|
||||||
|
|
||||||
private WeChatShareUtil(Context context) {
|
private WeChatShareUtil(Context context) {
|
||||||
this.mContext = context.getApplicationContext();
|
this.mContext = context.getApplicationContext();
|
||||||
// 初始化微信API
|
|
||||||
mWxApi = WXAPIFactory.createWXAPI(mContext, Constants.APP_ID, true);
|
|
||||||
mWxApi.registerApp(Constants.APP_ID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取实例
|
|
||||||
* @param context 上下文
|
|
||||||
* @return WeChatShareUtil实例
|
|
||||||
*/
|
|
||||||
public static WeChatShareUtil getInstance(Context context) {
|
public static WeChatShareUtil getInstance(Context context) {
|
||||||
if (instance == null && context != null) {
|
if (instance == null && context != null) {
|
||||||
instance = new WeChatShareUtil(context);
|
instance = new WeChatShareUtil(context);
|
||||||
@@ -54,130 +29,44 @@ public class WeChatShareUtil {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查微信是否已安装
|
|
||||||
* @return 是否安装
|
|
||||||
*/
|
|
||||||
public boolean isWeChatInstalled() {
|
public boolean isWeChatInstalled() {
|
||||||
try {
|
return WeChatIntentShareUtil.getInstance(mContext).isWeChatInstalled();
|
||||||
return mWxApi.isWXAppInstalled();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置分享回调
|
|
||||||
* @param callback 分享回调
|
|
||||||
*/
|
|
||||||
public void setShareCallback(WeChatShareCallback callback) {
|
public void setShareCallback(WeChatShareCallback callback) {
|
||||||
this.mCallback = callback;
|
this.mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分享回调
|
|
||||||
* @return 分享回调
|
|
||||||
*/
|
|
||||||
public WeChatShareCallback getShareCallback() {
|
public WeChatShareCallback getShareCallback() {
|
||||||
return mCallback;
|
return mCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void bindCallback() {
|
||||||
* 分享网页到微信
|
if (mCallback != null) {
|
||||||
* @param activity 活动
|
WeChatIntentShareUtil.getInstance(mContext).setShareCallback(new WeChatIntentShareUtil.WeChatShareCallback() {
|
||||||
* @param webpageUrl 网页链接
|
|
||||||
* @param title 标题
|
|
||||||
* @param description 描述
|
|
||||||
* @param scene 分享场景(0:好友, 1:朋友圈)
|
|
||||||
*/
|
|
||||||
public void shareWebPage(Activity activity, String webpageUrl, String title, String description, int scene) {
|
|
||||||
if (!isWeChatInstalled()) {
|
|
||||||
Toast.makeText(activity, "请先安装微信客户端", Toast.LENGTH_SHORT).show();
|
|
||||||
if (mCallback != null) {
|
|
||||||
mCallback.onError(-1, "未安装微信客户端");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 设置分享回调处理
|
|
||||||
// 创建Handler来接收微信分享结果
|
|
||||||
final Handler shareHandler = new Handler(Looper.getMainLooper()) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void onSuccess() {
|
||||||
// 处理微信分享回调
|
if (mCallback != null) mCallback.onSuccess();
|
||||||
if (mCallback != null) {
|
|
||||||
if (msg.what == 0) { // 成功
|
|
||||||
mCallback.onSuccess();
|
|
||||||
} else if (msg.what == -2) { // 取消
|
|
||||||
mCallback.onCancel();
|
|
||||||
} else { // 错误
|
|
||||||
mCallback.onError(msg.what, "微信分享失败,错误码:" + msg.what);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// 设置分享回调
|
@Override
|
||||||
WXEntryActivity.setshareHandler(shareHandler);
|
public void onError(int code, String message) {
|
||||||
|
if (mCallback != null) mCallback.onError(code, message);
|
||||||
// 创建网页消息对象
|
|
||||||
WXWebpageObject webpage = new WXWebpageObject();
|
|
||||||
webpage.webpageUrl = webpageUrl;
|
|
||||||
|
|
||||||
// 创建多媒体消息
|
|
||||||
WXMediaMessage msg = new WXMediaMessage(webpage);
|
|
||||||
msg.title = title;
|
|
||||||
msg.description = description;
|
|
||||||
|
|
||||||
// 设置缩略图 - 使用应用的启动图标 logo6 而不是 ic_launcher
|
|
||||||
Bitmap thumbBmp = BitmapFactory.decodeResource(mContext.getResources(),
|
|
||||||
mContext.getResources().getIdentifier("logo6", "drawable", mContext.getPackageName()));
|
|
||||||
|
|
||||||
// 如果找不到logo6,则退回到使用ic_launcher
|
|
||||||
if (thumbBmp == null) {
|
|
||||||
thumbBmp = BitmapFactory.decodeResource(mContext.getResources(),
|
|
||||||
com.jx.jyhd.R.mipmap.ic_launcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (thumbBmp != null) {
|
|
||||||
Bitmap thumbBitmap = Bitmap.createScaledBitmap(thumbBmp, THUMB_SIZE, THUMB_SIZE, true);
|
|
||||||
thumbBmp.recycle();
|
|
||||||
msg.thumbData = Util.bmpToByteArray(thumbBitmap, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建发送请求
|
|
||||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
|
||||||
req.transaction = buildTransaction("webpage");
|
|
||||||
req.message = msg;
|
|
||||||
req.scene = scene == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
|
|
||||||
|
|
||||||
// 发送请求
|
|
||||||
boolean result = mWxApi.sendReq(req);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
Toast.makeText(activity, "微信分享请求发送失败", Toast.LENGTH_SHORT).show();
|
|
||||||
if (mCallback != null) {
|
|
||||||
mCallback.onError(-2, "微信分享请求发送失败");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
@Override
|
||||||
e.printStackTrace();
|
public void onCancel() {
|
||||||
Toast.makeText(activity, "微信分享失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
if (mCallback != null) mCallback.onCancel();
|
||||||
if (mCallback != null) {
|
}
|
||||||
mCallback.onError(-3, "微信分享失败: " + e.getMessage());
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void shareWebPage(Activity activity, String webpageUrl, String title, String description, int scene) {
|
||||||
* 分享图片到微信
|
bindCallback();
|
||||||
* @param activity 活动
|
WeChatIntentShareUtil.getInstance(activity).shareWebPage(activity, webpageUrl, title, description, scene);
|
||||||
* @param imagePath 图片路径
|
}
|
||||||
* @param scene 分享场景(0:好友, 1:朋友圈)
|
|
||||||
*/
|
|
||||||
public void shareImage(Activity activity, String imagePath, int scene) {
|
public void shareImage(Activity activity, String imagePath, int scene) {
|
||||||
if (!isWeChatInstalled()) {
|
if (!isWeChatInstalled()) {
|
||||||
Toast.makeText(activity, "请先安装微信客户端", Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, "请先安装微信客户端", Toast.LENGTH_SHORT).show();
|
||||||
@@ -187,23 +76,16 @@ public class WeChatShareUtil {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用新的图片处理工具类检查图片是否存在,不存在时可以尝试使用其他备用方案
|
Uri imageFile = Base64ImageUtil.base64ToImageFile(activity, imagePath, null);
|
||||||
Uri imageFile = Base64ImageUtil.base64ToImageFile(activity,imagePath,null);
|
|
||||||
//Uri imageFile = Uri.parse(imagePath);
|
|
||||||
|
|
||||||
if (imageFile == null) {
|
if (imageFile == null) {
|
||||||
//Toast.makeText(activity, "分享图片不存在,尝试创建临时图片", Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
// 如果是Bitmap对象,可以使用ImageProcessUtils保存
|
|
||||||
if (imagePath.startsWith("data:image/") || imagePath.startsWith("base64,")) {
|
if (imagePath.startsWith("data:image/") || imagePath.startsWith("base64,")) {
|
||||||
// 对于Base64编码的图片,使用ImageProcessUtils保存
|
|
||||||
com.tagmae.tsgame_erwang.utils.ImageProcessUtils.saveBase64ImageToCache(
|
com.tagmae.tsgame_erwang.utils.ImageProcessUtils.saveBase64ImageToCache(
|
||||||
activity,
|
activity,
|
||||||
imagePath,
|
imagePath,
|
||||||
new com.tagmae.tsgame_erwang.utils.ImageProcessUtils.ImageSaveCallback() {
|
new com.tagmae.tsgame_erwang.utils.ImageProcessUtils.ImageSaveCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(String savedImagePath) {
|
public void onSuccess(String savedImagePath) {
|
||||||
// 保存成功,使用新路径进行分享
|
|
||||||
shareImageInternal(activity, savedImagePath, scene);
|
shareImageInternal(activity, savedImagePath, scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +100,6 @@ public class WeChatShareUtil {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// 图片不存在且不能处理
|
|
||||||
if (mCallback != null) {
|
if (mCallback != null) {
|
||||||
mCallback.onError(-2, "图片文件不存在");
|
mCallback.onError(-2, "图片文件不存在");
|
||||||
}
|
}
|
||||||
@@ -226,89 +107,14 @@ public class WeChatShareUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 直接使用现有图片路径分享
|
|
||||||
shareImageInternal(activity, imageFile.getPath(), scene);
|
shareImageInternal(activity, imageFile.getPath(), scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 内部图片分享实现
|
|
||||||
*/
|
|
||||||
private void shareImageInternal(Activity activity, String imagePath, int scene) {
|
private void shareImageInternal(Activity activity, String imagePath, int scene) {
|
||||||
try {
|
bindCallback();
|
||||||
// 设置分享回调处理
|
WeChatIntentShareUtil.getInstance(activity).shareImage(activity, imagePath, scene);
|
||||||
// 创建Handler来接收微信分享结果
|
|
||||||
final Handler shareHandler = new Handler(Looper.getMainLooper()) {
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
// 处理微信分享回调
|
|
||||||
if (mCallback != null) {
|
|
||||||
if (msg.what == 0) { // 成功
|
|
||||||
mCallback.onSuccess();
|
|
||||||
} else if (msg.what == -2) { // 取消
|
|
||||||
mCallback.onCancel();
|
|
||||||
} else { // 错误
|
|
||||||
mCallback.onError(msg.what, "微信分享失败,错误码:" + msg.what);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 设置分享回调
|
|
||||||
WXEntryActivity.setshareHandler(shareHandler);
|
|
||||||
|
|
||||||
// 加载要分享的图片
|
|
||||||
Bitmap bmp = BitmapFactory.decodeFile(imagePath);
|
|
||||||
if (bmp == null) {
|
|
||||||
Toast.makeText(activity, "图片加载失败", Toast.LENGTH_SHORT).show();
|
|
||||||
if (mCallback != null) {
|
|
||||||
mCallback.onError(-3, "图片加载失败");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建图片对象
|
|
||||||
WXImageObject imgObj = new WXImageObject(bmp);
|
|
||||||
|
|
||||||
// 创建多媒体消息
|
|
||||||
WXMediaMessage msg = new WXMediaMessage();
|
|
||||||
msg.mediaObject = imgObj;
|
|
||||||
|
|
||||||
// 设置缩略图
|
|
||||||
Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
|
|
||||||
bmp.recycle();
|
|
||||||
msg.thumbData = Util.bmpToByteArray(thumbBmp, true);
|
|
||||||
|
|
||||||
// 构建发送请求
|
|
||||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
|
||||||
req.transaction = buildTransaction("img");
|
|
||||||
req.message = msg;
|
|
||||||
req.scene = scene == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
|
|
||||||
|
|
||||||
// 发送请求
|
|
||||||
boolean result = mWxApi.sendReq(req);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
Toast.makeText(activity, "微信分享请求发送失败", Toast.LENGTH_SHORT).show();
|
|
||||||
if (mCallback != null) {
|
|
||||||
mCallback.onError(-4, "微信分享请求发送失败");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Toast.makeText(activity, "微信分享失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
|
||||||
if (mCallback != null) {
|
|
||||||
mCallback.onError(-5, "微信分享失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 分享Bitmap到微信
|
|
||||||
* @param activity 活动
|
|
||||||
* @param bitmap 位图对象
|
|
||||||
* @param scene 分享场景(0:好友, 1:朋友圈)
|
|
||||||
*/
|
|
||||||
public void shareBitmap(Activity activity, Bitmap bitmap, int scene) {
|
public void shareBitmap(Activity activity, Bitmap bitmap, int scene) {
|
||||||
if (bitmap == null) {
|
if (bitmap == null) {
|
||||||
Toast.makeText(activity, "分享图片为空", Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, "分享图片为空", Toast.LENGTH_SHORT).show();
|
||||||
@@ -318,14 +124,12 @@ public class WeChatShareUtil {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用ImageProcessUtils保存Bitmap
|
|
||||||
com.tagmae.tsgame_erwang.utils.ImageProcessUtils.saveBitmapToCache(
|
com.tagmae.tsgame_erwang.utils.ImageProcessUtils.saveBitmapToCache(
|
||||||
activity,
|
activity,
|
||||||
bitmap,
|
bitmap,
|
||||||
new com.tagmae.tsgame_erwang.utils.ImageProcessUtils.ImageSaveCallback() {
|
new com.tagmae.tsgame_erwang.utils.ImageProcessUtils.ImageSaveCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(String imagePath) {
|
public void onSuccess(String imagePath) {
|
||||||
// 保存成功,使用生成的图片路径分享
|
|
||||||
shareImageInternal(activity, imagePath, scene);
|
shareImageInternal(activity, imagePath, scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,16 +144,6 @@ public class WeChatShareUtil {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建交易ID
|
|
||||||
*/
|
|
||||||
private String buildTransaction(String type) {
|
|
||||||
return type + System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微信分享回调接口
|
|
||||||
*/
|
|
||||||
public interface WeChatShareCallback {
|
public interface WeChatShareCallback {
|
||||||
void onSuccess();
|
void onSuccess();
|
||||||
void onError(int code, String message);
|
void onError(int code, String message);
|
||||||
|
|||||||
@@ -3474,49 +3474,14 @@ public class NewwebviewActivity extends AppCompatActivity implements
|
|||||||
|
|
||||||
if (bean.getType().equals("1")) {
|
if (bean.getType().equals("1")) {
|
||||||
|
|
||||||
WXWebpageObject webpage = new WXWebpageObject();
|
com.tsgame.tsgame_niuniu.util.WeChatIntentShareUtil.getInstance(this).shareWebPage(
|
||||||
webpage.webpageUrl = bean.getWebpageUrl();
|
this,
|
||||||
WXMediaMessage msg = new WXMediaMessage(webpage);
|
bean.getWebpageUrl(),
|
||||||
msg.title = bean.getTitle();
|
bean.getTitle(),
|
||||||
msg.description = bean.getDescription();
|
bean.getDescription(),
|
||||||
// Toast.makeText(this, bean.getDescription(), 1).show();
|
com.tsgame.tsgame_niuniu.util.WeChatIntentShareUtil.SCENE_FRIENDS
|
||||||
Bitmap bt = BitmapFactory.decodeResource(getResources(),
|
);
|
||||||
R.drawable.sharelogo3);
|
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
bt.compress(Bitmap.CompressFormat.PNG, 100, out);
|
|
||||||
|
|
||||||
// Toast.makeText(webviewActivity.this, "" +
|
|
||||||
// out.toByteArray().length,
|
|
||||||
// 1).show();
|
|
||||||
|
|
||||||
if (out.toByteArray().length > 32000) {
|
|
||||||
// int a=out.toByteArray().length/30000;
|
|
||||||
BitmapFactory.Options newOpts = new BitmapFactory.Options();
|
|
||||||
newOpts.inJustDecodeBounds = true;
|
|
||||||
|
|
||||||
// Toast.makeText(webviewActivity.this, "压缩", 1).show();
|
|
||||||
|
|
||||||
BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.sharelogo3, newOpts);
|
|
||||||
|
|
||||||
newOpts.inJustDecodeBounds = false;
|
|
||||||
int inSampleSize = 2;// 大小缩小一半
|
|
||||||
|
|
||||||
newOpts.inSampleSize = inSampleSize;
|
|
||||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.sharelogo3, newOpts);
|
|
||||||
|
|
||||||
msg.thumbData = Util.bmpToByteArray(bitmap, true);
|
|
||||||
} else {
|
|
||||||
msg.thumbData = Util.bmpToByteArray(bt, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
|
||||||
req.transaction = buildTransaction("webpage");
|
|
||||||
req.message = msg;
|
|
||||||
req.scene = SendMessageToWX.Req.WXSceneSession;
|
|
||||||
api.sendReq(req);
|
|
||||||
} else if (bean.getType().equals("2")) {
|
} else if (bean.getType().equals("2")) {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@@ -3704,46 +3669,13 @@ public class NewwebviewActivity extends AppCompatActivity implements
|
|||||||
|
|
||||||
if (bean.getType().equals("1")) {
|
if (bean.getType().equals("1")) {
|
||||||
System.out.println("hhhhhhh");
|
System.out.println("hhhhhhh");
|
||||||
WXWebpageObject webpage = new WXWebpageObject();
|
com.tsgame.tsgame_niuniu.util.WeChatIntentShareUtil.getInstance(this).shareWebPage(
|
||||||
webpage.webpageUrl = bean.getWebpageUrl();
|
this,
|
||||||
WXMediaMessage msg = new WXMediaMessage(webpage);
|
bean.getWebpageUrl(),
|
||||||
msg.title = bean.getTitle();
|
bean.getTitle(),
|
||||||
msg.description = bean.getDescription();
|
bean.getDescription(),
|
||||||
// Toast.makeText(this, bean.getDescription(), 1).show();
|
com.tsgame.tsgame_niuniu.util.WeChatIntentShareUtil.SCENE_MOMENTS
|
||||||
|
);
|
||||||
Bitmap bt = BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.sharelogo3);
|
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
bt.compress(Bitmap.CompressFormat.PNG, 100, out);
|
|
||||||
|
|
||||||
// Toast.makeText(webviewActivity.this, "" +
|
|
||||||
// out.toByteArray().length,
|
|
||||||
// 1).show();
|
|
||||||
|
|
||||||
if (out.toByteArray().length > 32000) {
|
|
||||||
// int a=out.toByteArray().length/30000;
|
|
||||||
BitmapFactory.Options newOpts = new BitmapFactory.Options();
|
|
||||||
newOpts.inJustDecodeBounds = true;
|
|
||||||
BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.sharelogo3, newOpts);
|
|
||||||
newOpts.inJustDecodeBounds = false;
|
|
||||||
int inSampleSize = 2;// 大小缩小一半
|
|
||||||
newOpts.inSampleSize = inSampleSize;
|
|
||||||
|
|
||||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.sharelogo3, newOpts);
|
|
||||||
|
|
||||||
msg.thumbData = Util.bmpToByteArray(bitmap, true);
|
|
||||||
} else {
|
|
||||||
msg.thumbData = Util.bmpToByteArray(bt, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
|
||||||
req.transaction = buildTransaction("webpage");
|
|
||||||
req.message = msg;
|
|
||||||
req.scene = SendMessageToWX.Req.WXSceneTimeline;
|
|
||||||
api.sendReq(req);
|
|
||||||
|
|
||||||
} else if (bean.getType().equals("2")) {
|
} else if (bean.getType().equals("2")) {
|
||||||
photosharefriends();
|
photosharefriends();
|
||||||
|
|||||||
@@ -3347,52 +3347,14 @@ public class webviewActivity extends AppCompatActivity implements
|
|||||||
|
|
||||||
if (bean.getType().equals("1")) {
|
if (bean.getType().equals("1")) {
|
||||||
|
|
||||||
WXWebpageObject webpage = new WXWebpageObject();
|
com.tsgame.tsgame_niuniu.util.WeChatIntentShareUtil.getInstance(this).shareWebPage(
|
||||||
webpage.webpageUrl = bean.getWebpageUrl();
|
this,
|
||||||
WXMediaMessage msg = new WXMediaMessage(webpage);
|
bean.getWebpageUrl(),
|
||||||
msg.title = bean.getTitle();
|
bean.getTitle(),
|
||||||
msg.description = bean.getDescription();
|
bean.getDescription(),
|
||||||
// Toast.makeText(this, bean.getDescription(), 1).show();
|
com.tsgame.tsgame_niuniu.util.WeChatIntentShareUtil.SCENE_FRIENDS
|
||||||
Bitmap bt = BitmapFactory.decodeResource(getResources(),
|
);
|
||||||
R.drawable.sharelogo3);
|
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
bt.compress(Bitmap.CompressFormat.PNG, 100, out);
|
|
||||||
|
|
||||||
// Toast.makeText(webviewActivity.this, "" +
|
|
||||||
// out.toByteArray().length,
|
|
||||||
// 1).show();
|
|
||||||
|
|
||||||
if (out.toByteArray().length > 32000) {
|
|
||||||
// int a=out.toByteArray().length/30000;
|
|
||||||
BitmapFactory.Options newOpts = new BitmapFactory.Options();
|
|
||||||
newOpts.inJustDecodeBounds = true;
|
|
||||||
|
|
||||||
// Toast.makeText(webviewActivity.this, "压缩", 1).show();
|
|
||||||
|
|
||||||
BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.sharelogo3, newOpts);
|
|
||||||
|
|
||||||
newOpts.inJustDecodeBounds = false;
|
|
||||||
int inSampleSize = (out.toByteArray().length / 32768 + 1) / 2 + 2;
|
|
||||||
if (inSampleSize < 2) {
|
|
||||||
inSampleSize = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
newOpts.inSampleSize = inSampleSize;
|
|
||||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.sharelogo3, newOpts);
|
|
||||||
|
|
||||||
msg.thumbData = Util.bmpToByteArray(bitmap, true);
|
|
||||||
} else {
|
|
||||||
msg.thumbData = Util.bmpToByteArray(bt, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
|
||||||
req.transaction = buildTransaction("webpage");
|
|
||||||
req.message = msg;
|
|
||||||
req.scene = SendMessageToWX.Req.WXSceneSession;
|
|
||||||
api.sendReq(req);
|
|
||||||
} else if (bean.getType().equals("2")) {
|
} else if (bean.getType().equals("2")) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -3538,49 +3500,13 @@ public class webviewActivity extends AppCompatActivity implements
|
|||||||
Wxistrue.sharetype = 2;
|
Wxistrue.sharetype = 2;
|
||||||
|
|
||||||
if (bean.getType().equals("1")) {
|
if (bean.getType().equals("1")) {
|
||||||
WXWebpageObject webpage = new WXWebpageObject();
|
com.tsgame.tsgame_niuniu.util.WeChatIntentShareUtil.getInstance(this).shareWebPage(
|
||||||
webpage.webpageUrl = bean.getWebpageUrl();
|
this,
|
||||||
WXMediaMessage msg = new WXMediaMessage(webpage);
|
bean.getWebpageUrl(),
|
||||||
msg.title = bean.getTitle();
|
bean.getTitle(),
|
||||||
msg.description = bean.getDescription();
|
bean.getDescription(),
|
||||||
// Toast.makeText(this, bean.getDescription(), 1).show();
|
com.tsgame.tsgame_niuniu.util.WeChatIntentShareUtil.SCENE_MOMENTS
|
||||||
|
);
|
||||||
Bitmap bt = BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.sharelogo3);
|
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
bt.compress(Bitmap.CompressFormat.PNG, 100, out);
|
|
||||||
|
|
||||||
// Toast.makeText(webviewActivity.this, "" +
|
|
||||||
// out.toByteArray().length,
|
|
||||||
// 1).show();
|
|
||||||
|
|
||||||
if (out.toByteArray().length > 32000) {
|
|
||||||
// int a=out.toByteArray().length/30000;
|
|
||||||
BitmapFactory.Options newOpts = new BitmapFactory.Options();
|
|
||||||
newOpts.inJustDecodeBounds = true;
|
|
||||||
BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.sharelogo3, newOpts);
|
|
||||||
newOpts.inJustDecodeBounds = false;
|
|
||||||
int inSampleSize = (out.toByteArray().length / 32000 + 1) / 2 + 2;
|
|
||||||
if (inSampleSize < 2) {
|
|
||||||
inSampleSize = 2;
|
|
||||||
}
|
|
||||||
newOpts.inSampleSize = inSampleSize;
|
|
||||||
|
|
||||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
|
|
||||||
R.drawable.sharelogo3, newOpts);
|
|
||||||
|
|
||||||
msg.thumbData = Util.bmpToByteArray(bitmap, true);
|
|
||||||
} else {
|
|
||||||
msg.thumbData = Util.bmpToByteArray(bt, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
|
||||||
req.transaction = buildTransaction("webpage");
|
|
||||||
req.message = msg;
|
|
||||||
req.scene = SendMessageToWX.Req.WXSceneTimeline;
|
|
||||||
api.sendReq(req);
|
|
||||||
|
|
||||||
} else if (bean.getType().equals("2")) {
|
} else if (bean.getType().equals("2")) {
|
||||||
// photosharefriends();
|
// photosharefriends();
|
||||||
|
|||||||
@@ -340,11 +340,12 @@ public class WeChatIntentShareUtil {
|
|||||||
sb.append(title).append("\n\n");
|
sb.append(title).append("\n\n");
|
||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(description)) {
|
if (!TextUtils.isEmpty(description)) {
|
||||||
sb.append(description).append("\n\n");
|
sb.append(description);
|
||||||
}
|
|
||||||
if (!TextUtils.isEmpty(webUrl)) {
|
|
||||||
sb.append(webUrl);
|
|
||||||
}
|
}
|
||||||
|
// 根据需求限制:分享的链接(webUrl)不需要分享出去
|
||||||
|
// if (!TextUtils.isEmpty(webUrl)) {
|
||||||
|
// sb.append("\n\n").append(webUrl);
|
||||||
|
// }
|
||||||
|
|
||||||
// 朋友圈不支持纯文本分享,需要准备一个默认图片
|
// 朋友圈不支持纯文本分享,需要准备一个默认图片
|
||||||
if (scene == SCENE_MOMENTS) {
|
if (scene == SCENE_MOMENTS) {
|
||||||
|
|||||||
BIN
keystore/daoqi_game_1.keystore
Normal file
BIN
keystore/daoqi_game_1.keystore
Normal file
Binary file not shown.
Reference in New Issue
Block a user