Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
02d095fd
提交
02d095fd
authored
7月 03, 2019
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:share large image on Android
上级
f9e5cc11
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
51 行增加
和
6 行删除
+51
-6
FluwxShareHandler.kt
...main/kotlin/com/jarvan/fluwx/handler/FluwxShareHandler.kt
+23
-1
ShareImageUtil.java
...rc/main/kotlin/com/jarvan/fluwx/utils/ShareImageUtil.java
+20
-3
WeChatThumbnailUtil.java
...in/kotlin/com/jarvan/fluwx/utils/WeChatThumbnailUtil.java
+5
-0
share_image_page.dart
example/lib/share_image_page.dart
+3
-2
没有找到文件。
android/src/main/kotlin/com/jarvan/fluwx/handler/FluwxShareHandler.kt
浏览文件 @
02d095fd
...
...
@@ -15,6 +15,7 @@
*/
package
com.jarvan.fluwx.handler
import
android.util.Log
import
com.jarvan.fluwx.constant.CallResult
import
com.jarvan.fluwx.constant.WeChatPluginMethods
import
com.jarvan.fluwx.constant.WechatPluginKeys
...
...
@@ -25,6 +26,7 @@ import io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.PluginRegistry
import
kotlinx.coroutines.*
import
java.io.ByteArrayInputStream
/***
...
...
@@ -170,11 +172,31 @@ internal class FluwxShareHandler {
val
byteArray
:
ByteArray
?
=
if
(
imagePath
.
isNullOrBlank
())
{
byteArrayOf
()
}
else
{
getImageByteArrayCommon
(
registrar
,
imagePath
!!
)
getImageByteArrayCommon
(
registrar
,
imagePath
)
}
val
imgObj
=
if
(
byteArray
!=
null
&&
byteArray
.
isNotEmpty
())
{
if
(
byteArray
.
size
>
512
*
1024
){
val
input
=
ByteArrayInputStream
(
byteArray
)
val
suffix
=
when
{
imagePath
.
isNullOrBlank
()
->
".jpeg"
imagePath
.
lastIndexOf
(
"."
)
==
-
1
->
".jpeg"
else
->
imagePath
.
substring
(
imagePath
.
lastIndexOf
(
"."
))
}
val
file
=
ShareImageUtil
.
inputStreamToFile
(
input
,
suffix
,
registrar
!!
.
context
())
WXImageObject
().
apply
{
setImagePath
(
file
.
absolutePath
)
}
}
else
{
WXImageObject
(
byteArray
)
}
}
else
{
null
}
...
...
android/src/main/kotlin/com/jarvan/fluwx/utils/ShareImageUtil.java
浏览文件 @
02d095fd
...
...
@@ -15,19 +15,24 @@
*/
package
com
.
jarvan
.
fluwx
.
utils
;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.content.res.AssetFileDescriptor
;
import
android.database.Cursor
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.provider.MediaStore
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.jarvan.fluwx.constant.WeChatPluginImageSchema
;
import
com.jarvan.fluwx.constant.WechatPluginKeys
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
@@ -50,7 +55,7 @@ public class ShareImageUtil {
public
static
byte
[]
getImageData
(
PluginRegistry
.
Registrar
registrar
,
String
path
)
{
byte
[]
result
=
null
;
if
(
path
.
startsWith
(
WeChatPluginImageSchema
.
SCHEMA_ASSETS
))
{
String
key
=
path
.
substring
(
WeChatPluginImageSchema
.
SCHEMA_ASSETS
.
length
()
,
path
.
length
()
);
String
key
=
path
.
substring
(
WeChatPluginImageSchema
.
SCHEMA_ASSETS
.
length
());
AssetFileDescriptor
fileDescriptor
=
AssetManagerUtil
.
openAsset
(
registrar
,
key
,
getPackage
(
key
));
try
{
InputStream
inputStream
=
fileDescriptor
.
createInputStream
();
...
...
@@ -118,14 +123,23 @@ public class ShareImageUtil {
return
packageStr
;
}
private
static
File
inputStreamToTmpFile
(
InputStream
inputStream
,
String
suffix
)
{
public
static
File
inputStreamToFile
(
InputStream
inputStream
,
String
suffix
,
Context
context
)
{
File
file
=
null
;
BufferedSink
sink
=
null
;
Source
source
=
null
;
OutputStream
outputStream
=
null
;
try
{
file
=
File
.
createTempFile
(
UUID
.
randomUUID
().
toString
(),
suffix
);
File
externalFile
=
context
.
getExternalCacheDir
();
if
(
externalFile
==
null
)
{
return
null
;
}
file
=
new
File
(
externalFile
.
getAbsolutePath
()+
File
.
separator
+
UUID
.
randomUUID
().
toString
()+
suffix
);
// file = File.createTempFile(UUID.randomUUID().toString(), suffix);
outputStream
=
new
FileOutputStream
(
file
);
sink
=
Okio
.
buffer
(
Okio
.
sink
(
outputStream
));
source
=
Okio
.
source
(
inputStream
);
...
...
@@ -162,6 +176,9 @@ public class ShareImageUtil {
return
file
;
}
private
static
InputStream
openStream
(
String
url
)
{
if
(!
url
.
startsWith
(
"https"
)
&&
!
url
.
startsWith
(
"http"
)){
url
=
"http://"
+
url
;
...
...
android/src/main/kotlin/com/jarvan/fluwx/utils/WeChatThumbnailUtil.java
浏览文件 @
02d095fd
...
...
@@ -224,6 +224,11 @@ public class WeChatThumbnailUtil {
}
private
static
File
downloadImage
(
String
url
)
{
if
(!
url
.
startsWith
(
"https"
)
&&
!
url
.
startsWith
(
"http"
)){
url
=
"http://"
+
url
;
}
File
result
=
null
;
OkHttpClient
okHttpClient
=
new
OkHttpClient
.
Builder
().
build
();
Request
request
=
new
Request
.
Builder
().
url
(
url
).
get
().
build
();
...
...
example/lib/share_image_page.dart
浏览文件 @
02d095fd
...
...
@@ -9,8 +9,9 @@ class ShareImagePage extends StatefulWidget {
class
_ShareImagePageState
extends
State
<
ShareImagePage
>
{
fluwx
.
WeChatScene
scene
=
fluwx
.
WeChatScene
.
SESSION
;
String
_imagePath
=
// "http://img-download.pchome.net/download/1k1/3a/3e/ofskcd-s1a.jpg"
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534614311230&di=b17a892b366b5d002f52abcce7c4eea0&imgtype=0&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170516%2F51296b2673704ae2992d0a28c244274c_th.png"
;
String
_thumbnail
=
"assets://logo.png"
;
String
_thumbnail
=
"assets://
images/
logo.png"
;
String
_response
=
""
;
...
...
@@ -54,7 +55,7 @@ class _ShareImagePageState extends State<ShareImagePage> {
),
TextField
(
decoration:
InputDecoration
(
labelText:
"缩略地址"
),
controller:
TextEditingController
(
text:
"assets://logo.png"
),
controller:
TextEditingController
(
text:
"assets://
images/
logo.png"
),
onChanged:
(
value
)
{
_thumbnail
=
value
;
},
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论