1 안드로이드 버전 업데이트, 이제 버전 V7 AndroidX가 V4를 포기 라이브러리 테스트를 가지고 있기 때문에
7 안드로이드 시작 후 FileProvider는 V4 가방을 시도
그러나 적응 안드로이드 (10) 후, 대신 Androidx 도서관이 될 것입니다
androidx.core.content.FileProvider;
이 위치에서, 같은 QQ 마이크로 문자로 구문 분석, 당신은 QQ이 기능 과정에서 유효성 검사에 Androidx 라이브러리 FileProvider 리드의 새 버전을 사용하지 않은 마이크로 채널로 인해 온라인 소스 getFPUriToPath 기능 장애를 발견 할 것이다 실패는, 이제 간단한 해결책이 단계 인증을 제거하는 것입니다. 직관적으로,이 단계는 전체 유효성에 영향을주지 않습니다.
수정 된 소스 코드는 다음과
package com.aiocw.aihome.easylauncher.common;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.net.Uri;
import androidx.core.content.FileProvider;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
public class ProviderTools {
public static String getFPUriToPath(Context context, Uri uri) {
try {
List<PackageInfo> packs = context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS);
if (packs != null) {
String fileProviderClassName = FileProvider.class.getName();
for (PackageInfo pack : packs) {
ProviderInfo[] providers = pack.providers;
if (providers != null) {
for (ProviderInfo provider : providers) {
if (uri.getAuthority().equals(provider.authority)) {
// if (provider.name.equalsIgnoreCase(fileProviderClassName)) {
Class<FileProvider> fileProviderClass = FileProvider.class;
try {
Method getPathStrategy = fileProviderClass.getDeclaredMethod("getPathStrategy", Context.class, String.class);
getPathStrategy.setAccessible(true);
Object invoke = getPathStrategy.invoke(null, context, uri.getAuthority());
if (invoke != null) {
String PathStrategyStringClass = FileProvider.class.getName() + "$PathStrategy";
Class<?> PathStrategy = Class.forName(PathStrategyStringClass);
Method getFileForUri = PathStrategy.getDeclaredMethod("getFileForUri", Uri.class);
getFileForUri.setAccessible(true);
Object invoke1 = getFileForUri.invoke(invoke, uri);
if (invoke1 instanceof File) {
String filePath = ((File) invoke1).getAbsolutePath();
return filePath;
}
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
break;
// }
// break;
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}