微信分享图片改用FileProvider方式分享
This commit is contained in:
@ -23,11 +23,13 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.gh.common.Base64ImageHolder;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.gamecenter.BuildConfig;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.WeiBoShareActivity;
|
||||
import com.lightgame.utils.Utils;
|
||||
@ -354,7 +356,7 @@ public class MessageShareUtils {
|
||||
|
||||
//官方分享
|
||||
WXImageObject imgObj = new WXImageObject();
|
||||
imgObj.setImagePath(mWriteBitmapPath + picName);
|
||||
imgObj.setImagePath(getWechatImagePath());
|
||||
WXMediaMessage msg = new WXMediaMessage();
|
||||
msg.mediaObject = imgObj;
|
||||
|
||||
@ -389,7 +391,7 @@ public class MessageShareUtils {
|
||||
}
|
||||
|
||||
WXImageObject imgObj = new WXImageObject();
|
||||
imgObj.setImagePath(mWriteBitmapPath + picName);
|
||||
imgObj.setImagePath(getWechatImagePath());
|
||||
WXMediaMessage msg = new WXMediaMessage();
|
||||
msg.mediaObject = imgObj;
|
||||
|
||||
@ -494,6 +496,22 @@ public class MessageShareUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Android11需要使用FileProvider方式分享,所以要判断是否能用FileProvider
|
||||
* OpenSDK版本必须大于或等于 5.4.3 版本,微信版本为7.0.13及以上,Android版本7.0及以上
|
||||
* 微信版本的判断方式:当且仅当通过 IWXAPI.getWXAppSupportAPI() 接口获取到的值 >= 0x27000D00,才能支持FileProvider的方式进行分享
|
||||
*/
|
||||
private String getWechatImagePath() {
|
||||
String path = mWriteBitmapPath + picName;
|
||||
if (mIWXAPI.getWXAppSupportAPI() >= 0x27000D00 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
Uri uri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID, new File(mWriteBitmapPath + picName));
|
||||
// 授权给微信访问路径
|
||||
mContext.grantUriPermission("com.tencent.mm", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
path = uri.toString();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注意,第二个入参需要是 file 本身而不是 folder
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user