Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.1.3版本 微信分享单图类型 无法唤起微信 其余的分享类型都可以(分享内容均为demo中的内容) 回调只能走到onStart #91

Open
ThreeAbs opened this issue Jun 8, 2021 · 15 comments

Comments

@ThreeAbs
Copy link

ThreeAbs commented Jun 8, 2021

1623139896(1)
其中分享图片的两个 都无法唤起微信 最下边分享Web的方式可以正常使用 这是什么原因啊?

@leiyaqiang
Copy link

我也遇到了这个问题

@ThreeAbs
Copy link
Author

是androidx.core.content.FileProvider 这个的原因

@fanjie19930414
Copy link

我也遇到这个问题了 请教大佬能告知一下是怎么解决的吗? @ThreeAbs

@leiyaqiang
Copy link

leiyaqiang commented Jul 7, 2021 via email

@fanjie19930414
Copy link

var image: UMImage = UMImage(this, url) var image1: UMImage = UMImage(this, url) image.setThumb(image1) image.compressStyle = UMImage.CompressStyle.SCALE ShareAction(this) .setPlatform(platform) .withText("") .withMedia(image) .share() implementation "com.umeng.umsdk:share-core:7.1.4" implementation "com.umeng.umsdk:share-board:7.1.4" implementation "com.umeng.umsdk:share-wx:7.1.4" 发自 Outlookhttp://aka.ms/weboutlook

________________________________ 发件人: FFFFFFFFFFj @.> 发送时间: 2021年7月7日 11:02 收件人: umeng/MultiFunctionAndroidDemo @.> 抄送: leiyaqiang @.>; Comment @.> 主题: Re: [umeng/MultiFunctionAndroidDemo] 7.1.3版本 微信分享单图类型 无法唤起微信 其余的分享类型都可以(分享内容均为demo中的内容) 回调只能走到onStart (#91) 我也遇到这个问题了 请教大佬能告知一下是怎么解决的吗? @ThreeAbshttps://github.com/ThreeAbs ― You are receiving this because you commented. Reply to this email directly, view it on GitHub<#91 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGLZ2ET33VXEBVHL25MI5U3TWO7UPANCNFSM46JLA6DQ.

感谢大佬回复 我的代码和你一样 分享图片还是不会吊起微信 我看了友盟的日志 是报这个问题 但是不着调怎么解决。。。
错误类型:Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

@jarvan11
Copy link

jarvan11 commented Aug 2, 2021

是androidx.core.content.FileProvider 这个的原因

设置了也不行

@jarvan11
Copy link

jarvan11 commented Aug 2, 2021

是androidx.core.content.FileProvider 这个的原因

设置了也不行

https://developer.umeng.com/docs/128606/detail/200753

@xwdz
Copy link

xwdz commented Aug 9, 2021

我也遇到了同样的问题;即使在设置了fileprovider的情况下。 version 7.1.5

@xwdz
Copy link

xwdz commented Aug 9, 2021

已经找到问题;

  1. 检查 manifest 里面是否设置了 fileprovider
  2. 检查app init 的时候是否设置了.fileprovider 后缀

我是从6.x 升至 9.x版本;
目前看来是之前sdk内部帮我们凭拼接了.fileprovider 后缀,后续的版本则没有帮我们拼接了;

 // 加上后缀即可
 final String fileProvider = application.getPackageName() + ".fileprovider";
                UMConfigure.setLogEnabled(BuildConfig.DEBUG);
                PlatformConfig.setWXFileProvider(fileProvider);
                PlatformConfig.setQQFileProvider(fileProvider);
                PlatformConfig.setSinaFileProvider(fileProvider);

@leiyaqiang
Copy link

leiyaqiang commented Aug 16, 2021 via email

@jarvan11
Copy link

jarvan11 commented Aug 16, 2021 via email

@pczhu
Copy link

pczhu commented Apr 27, 2022

哪位解决了?是必须要v4的包还是androidx的包也可以?我咋看不懂上面各位说啥呢 T T

@pczhu
Copy link

pczhu commented Apr 27, 2022

搞明白了。就算用androidx的fileprovider 也要加implementation 'com.android.support:support-v4:30.0.0' 的依赖才行

@liuzhenli
Copy link

是的,这里的坑点就是androidx项目需要引入supprot-v4包

@liuzhenli
Copy link

liuzhenli commented Sep 30, 2022

我发现我们不用引用support-v4包,support-v4包下的FileProvider就是一个类,我们先创建同样的包名路径(android.support.v4.content),然后把代码copy一下就可以了

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package android.support.v4.content;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.res.XmlResourceParser;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.net.Uri.Builder;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import org.xmlpull.v1.XmlPullParserException;

public class FileProvider extends ContentProvider {
    private static final String[] COLUMNS = new String[]{"_display_name", "_size"};
    private static final String META_DATA_FILE_PROVIDER_PATHS = "android.support.FILE_PROVIDER_PATHS";
    private static final String TAG_ROOT_PATH = "root-path";
    private static final String TAG_FILES_PATH = "files-path";
    private static final String TAG_CACHE_PATH = "cache-path";
    private static final String TAG_EXTERNAL = "external-path";
    private static final String ATTR_NAME = "name";
    private static final String ATTR_PATH = "path";
    private static final File DEVICE_ROOT = new File("/");
    private static HashMap<String, FileProvider.PathStrategy> sCache = new HashMap();
    private FileProvider.PathStrategy mStrategy;

    public FileProvider() {
    }

    public boolean onCreate() {
        return true;
    }

    public void attachInfo(Context context, ProviderInfo info) {
        super.attachInfo(context, info);
        if (info.exported) {
            throw new SecurityException("Provider must not be exported");
        } else if (!info.grantUriPermissions) {
            throw new SecurityException("Provider must grant uri permissions");
        } else {
            this.mStrategy = getPathStrategy(context, info.authority);
        }
    }

    public static Uri getUriForFile(Context context, String authority, File file) {
        FileProvider.PathStrategy strategy = getPathStrategy(context, authority);
        return strategy.getUriForFile(file);
    }

    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        File file = this.mStrategy.getFileForUri(uri);
        if (projection == null) {
            projection = COLUMNS;
        }

        String[] cols = new String[projection.length];
        Object[] values = new Object[projection.length];
        int i = 0;
        String[] arr$ = projection;
        int len$ = projection.length;

        for(int i$ = 0; i$ < len$; ++i$) {
            String col = arr$[i$];
            if ("_display_name".equals(col)) {
                cols[i] = "_display_name";
                values[i++] = file.getName();
            } else if ("_size".equals(col)) {
                cols[i] = "_size";
                values[i++] = file.length();
            }
        }

        cols = copyOf(cols, i);
        values = copyOf(values, i);
        MatrixCursor cursor = new MatrixCursor(cols, 1);
        cursor.addRow(values);
        return cursor;
    }

    public String getType(Uri uri) {
        File file = this.mStrategy.getFileForUri(uri);
        int lastDot = file.getName().lastIndexOf(46);
        if (lastDot >= 0) {
            String extension = file.getName().substring(lastDot + 1);
            String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
            if (mime != null) {
                return mime;
            }
        }

        return "application/octet-stream";
    }

    public Uri insert(Uri uri, ContentValues values) {
        throw new UnsupportedOperationException("No external inserts");
    }

    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        throw new UnsupportedOperationException("No external updates");
    }

    public int delete(Uri uri, String selection, String[] selectionArgs) {
        File file = this.mStrategy.getFileForUri(uri);
        return file.delete() ? 1 : 0;
    }

    public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
        File file = this.mStrategy.getFileForUri(uri);
        int fileMode = modeToMode(mode);
        return ParcelFileDescriptor.open(file, fileMode);
    }

    private static FileProvider.PathStrategy getPathStrategy(Context context, String authority) {
        synchronized(sCache) {
            FileProvider.PathStrategy strat = (FileProvider.PathStrategy)sCache.get(authority);
            if (strat == null) {
                try {
                    strat = parsePathStrategy(context, authority);
                } catch (IOException var6) {
                    throw new IllegalArgumentException("Failed to parse android.support.FILE_PROVIDER_PATHS meta-data", var6);
                } catch (XmlPullParserException var7) {
                    throw new IllegalArgumentException("Failed to parse android.support.FILE_PROVIDER_PATHS meta-data", var7);
                }

                sCache.put(authority, strat);
            }

            return strat;
        }
    }

    private static FileProvider.PathStrategy parsePathStrategy(Context context, String authority) throws IOException, XmlPullParserException {
        FileProvider.SimplePathStrategy strat = new FileProvider.SimplePathStrategy(authority);
        ProviderInfo info = context.getPackageManager().resolveContentProvider(authority, PackageManager.GET_META_DATA);
        XmlResourceParser in = info.loadXmlMetaData(context.getPackageManager(), "android.support.FILE_PROVIDER_PATHS");
        if (in == null) {
            throw new IllegalArgumentException("Missing android.support.FILE_PROVIDER_PATHS meta-data");
        } else {
            int type;
            while((type = in.next()) != 1) {
                if (type == 2) {
                    String tag = in.getName();
                    String name = in.getAttributeValue((String)null, "name");
                    String path = in.getAttributeValue((String)null, "path");
                    File target = null;
                    if ("root-path".equals(tag)) {
                        target = buildPath(DEVICE_ROOT, path);
                    } else if ("files-path".equals(tag)) {
                        target = buildPath(context.getFilesDir(), path);
                    } else if ("cache-path".equals(tag)) {
                        target = buildPath(context.getCacheDir(), path);
                    } else if ("external-path".equals(tag)) {
                        target = buildPath(Environment.getExternalStorageDirectory(), path);
                    }

                    if (target != null) {
                        strat.addRoot(name, target);
                    }
                }
            }

            return strat;
        }
    }

    private static int modeToMode(String mode) {
        int modeBits;
        if ("r".equals(mode)) {
            modeBits = 268435456;
        } else if (!"w".equals(mode) && !"wt".equals(mode)) {
            if ("wa".equals(mode)) {
                modeBits = 704643072;
            } else if ("rw".equals(mode)) {
                modeBits = 939524096;
            } else {
                if (!"rwt".equals(mode)) {
                    throw new IllegalArgumentException("Invalid mode: " + mode);
                }

                modeBits = 1006632960;
            }
        } else {
            modeBits = 738197504;
        }

        return modeBits;
    }

    private static File buildPath(File base, String... segments) {
        File cur = base;
        String[] arr$ = segments;
        int len$ = segments.length;

        for(int i$ = 0; i$ < len$; ++i$) {
            String segment = arr$[i$];
            if (segment != null) {
                cur = new File(cur, segment);
            }
        }

        return cur;
    }

    private static String[] copyOf(String[] original, int newLength) {
        String[] result = new String[newLength];
        System.arraycopy(original, 0, result, 0, newLength);
        return result;
    }

    private static Object[] copyOf(Object[] original, int newLength) {
        Object[] result = new Object[newLength];
        System.arraycopy(original, 0, result, 0, newLength);
        return result;
    }

    static class SimplePathStrategy implements FileProvider.PathStrategy {
        private final String mAuthority;
        private final HashMap<String, File> mRoots = new HashMap();

        public SimplePathStrategy(String authority) {
            this.mAuthority = authority;
        }

        public void addRoot(String name, File root) {
            if (TextUtils.isEmpty(name)) {
                throw new IllegalArgumentException("Name must not be empty");
            } else {
                try {
                    root = root.getCanonicalFile();
                } catch (IOException var4) {
                    throw new IllegalArgumentException("Failed to resolve canonical path for " + root, var4);
                }

                this.mRoots.put(name, root);
            }
        }

        public Uri getUriForFile(File file) {
            String path;
            try {
                path = file.getCanonicalPath();
            } catch (IOException var7) {
                throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
            }

            Entry<String, File> mostSpecific = null;
            Iterator i$ = this.mRoots.entrySet().iterator();

            while(true) {
                Entry root;
                String rootPath;
                do {
                    do {
                        if (!i$.hasNext()) {
                            if (mostSpecific == null) {
                                throw new IllegalArgumentException("Failed to find configured root that contains " + path);
                            }

                             rootPath = ((File)mostSpecific.getValue()).getPath();
                            if (rootPath.endsWith("/")) {
                                path = path.substring(rootPath.length());
                            } else {
                                path = path.substring(rootPath.length() + 1);
                            }

                            path = Uri.encode((String)mostSpecific.getKey()) + '/' + Uri.encode(path, "/");
                            return (new Builder()).scheme("content").authority(this.mAuthority).encodedPath(path).build();
                        }

                        root = (Entry)i$.next();
                        rootPath = ((File)root.getValue()).getPath();
                    } while(!path.startsWith(rootPath));
                } while(mostSpecific != null && rootPath.length() <= ((File)mostSpecific.getValue()).getPath().length());

                mostSpecific = root;
            }
        }

        public File getFileForUri(Uri uri) {
            String path = uri.getEncodedPath();
            int splitIndex = path.indexOf(47, 1);
            String tag = Uri.decode(path.substring(1, splitIndex));
            path = Uri.decode(path.substring(splitIndex + 1));
            File root = (File)this.mRoots.get(tag);
            if (root == null) {
                throw new IllegalArgumentException("Unable to find configured root for " + uri);
            } else {
                File file = new File(root, path);

                try {
                    file = file.getCanonicalFile();
                } catch (IOException var8) {
                    throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
                }

                if (!file.getPath().startsWith(root.getPath())) {
                    throw new SecurityException("Resolved path jumped beyond configured root");
                } else {
                    return file;
                }
            }
        }
    }

    interface PathStrategy {
        Uri getUriForFile(File var1);

        File getFileForUri(Uri var1);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants