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

fix:can't find assets

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