提交 a0ec7fc2 authored 作者: JarvanMo's avatar JarvanMo

fix:can't find assets

上级 ad83a78f
......@@ -4,9 +4,8 @@
## 写在前面
使用Fluwx之前,强烈建议先阅读[微信SDK官方文档](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1)
这有助于你使用Fluwx。Fluwx的api字段名称基本和官方的字段名称是一致的。
这有助于你使用```Fluwx``````Fluwx```的api字段名称基本和官方的字段名称是一致的。
## 引入
## 初始化
```dart
......@@ -41,7 +40,8 @@ Fluwx.unregisterApp(RegisterModel(doOnAndroid: true, doOnIOS: true));
title: "Fluwx",
thumbnail: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534532387799&di=12701cc3f20c1a78a5c7524ec33b4c59&imgtype=0&src=http%3A%2F%2Fwww.cssxt.com%2Fuploadfile%2F2017%2F1208%2F20171208110834538.jpg',
)).then((result){
},onError: (msg){
},
onError: (msg){
});
```
```fluwx.share(WeChatShareModel)```目前仅支持系统内```WeChatShareModel```的子类,不支持自定义。
......
......@@ -2,6 +2,7 @@ package com.jarvan.fluwx.utils;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.text.TextUtils;
import java.io.IOException;
......@@ -15,7 +16,12 @@ public final class AssetManagerUtil {
public static AssetFileDescriptor openAsset(PluginRegistry.Registrar registrar, String assetKey, String assetPackage) {
AssetFileDescriptor fd = null;
AssetManager assetManager = registrar.context().getAssets();
String key = registrar.lookupKeyForAsset(assetKey, assetPackage);
String key;
if (TextUtils.isEmpty(assetPackage)) {
key = registrar.lookupKeyForAsset(assetKey);
} else {
key = registrar.lookupKeyForAsset(assetKey, assetPackage);
}
try {
fd = assetManager.openFd(key);
} catch (IOException e) {
......
......@@ -3,6 +3,7 @@ package com.jarvan.fluwx.utils;
import android.content.res.AssetFileDescriptor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import com.jarvan.fluwx.constant.WeChatPluginImageSchema;
......@@ -170,8 +171,14 @@ public class WeChatThumbnailUtil {
private static File getAssetFile(String thumbnail, PluginRegistry.Registrar registrar) {
File result = null;
String key = thumbnail.substring(WeChatPluginImageSchema.SCHEMA_ASSETS.length(), thumbnail.length());
AssetFileDescriptor fileDescriptor = AssetManagerUtil.openAsset(registrar, key, getPackage(key));
int endIndex = thumbnail.length();
int indexOfPackage = thumbnail.indexOf(WechatPluginKeys.PACKAGE);
if(indexOfPackage > 0){
endIndex = indexOfPackage;
}
String key = thumbnail.substring(WeChatPluginImageSchema.SCHEMA_ASSETS.length(), endIndex);
// flutter_assets/packages/flutter_gallery_assets/ali_connors.jpg?package=flutter_gallery_assets
AssetFileDescriptor fileDescriptor = AssetManagerUtil.openAsset(registrar, key, getPackage(thumbnail));
if (fileDescriptor != null) {
try {
......
......@@ -17,7 +17,6 @@ class _MyAppState extends State<MyApp> {
// initPlatformState();
Fluwx.registerApp(RegisterModel(
appId: "wxd930ea5d5a258f4f", doOnAndroid: true, doOnIOS: true));
}
// Platform messages are asynchronous, so we initialize in an async method.
......@@ -34,29 +33,29 @@ class _MyAppState extends State<MyApp> {
child: new FlatButton(
onPressed: () {
var fluwx = Fluwx();
fluwx.share(WeChatShareMiniProgramModel(
webPageUrl: "http://www.qq.com",
miniProgramType:
WeChatShareMiniProgramModel.MINI_PROGRAM_TYPE_RELEASE,
userName: "gh_d43f693ca31f",
path: '/pages/media',
title: "title",
description: "des",
thumbnail:
'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534532387799&di=12701cc3f20c1a78a5c7524ec33b4c59&imgtype=0&src=http%3A%2F%2Fwww.cssxt.com%2Fuploadfile%2F2017%2F1208%2F20171208110834538.jpg',
));
// fluwx.share(WeChatShareMiniProgramModel(
// webPageUrl: "http://www.qq.com",
// miniProgramType:
// WeChatShareMiniProgramModel.MINI_PROGRAM_TYPE_RELEASE,
// userName: "gh_d43f693ca31f",
// path: '/pages/media',
// title: "title",
// description: "des",
// thumbnail:
// 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534532387799&di=12701cc3f20c1a78a5c7524ec33b4c59&imgtype=0&src=http%3A%2F%2Fwww.cssxt.com%2Fuploadfile%2F2017%2F1208%2F20171208110834538.jpg',
// ));
// thumbnail: 'http://b.hiphotos.baidu.com/image/h%3D300/sign=4bfc640817d5ad6eb5f962eab1c939a3/8718367adab44aedb794e128bf1c8701a08bfb20.jpg',
// fluwx.share(
// WeChatShareWebPageModel(
// webPage: "https://github.com/JarvanMo/fluwx",
// title: "MyGithub",
// thumbnail: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534532387799&di=12701cc3f20c1a78a5c7524ec33b4c59&imgtype=0&src=http%3A%2F%2Fwww.cssxt.com%2Fuploadfile%2F2017%2F1208%2F20171208110834538.jpg',
// )
// ).then((result){
// print("--$result");
// },onError: (msg){
// print(msg);
// });
fluwx.share(
WeChatShareWebPageModel(
webPage: "https://github.com/JarvanMo/fluwx",
title: "MyGithub",
thumbnail: "assets://images/logo.png"
)
).then((result){
print("--$result");
},onError: (msg){
print(msg);
});
// fluwx.share(WeChatShareImageModel(image: "imagePath",thumbnail: "thumbanailPath"));
},
child: new Text("share ")),
......
......@@ -26,7 +26,8 @@ flutter:
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
assets:
- images/logo.png
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论