Skip to content

Commit

Permalink
V 1.3.8 解决Provider冲突导致其他app也引用该库后无法安装的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
smuyyh committed Mar 16, 2017
1 parent 76a61c9 commit aab709d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 228 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Android 图片选择器。充分自由定制,极大程度简化使用,支持
## 依赖
```
dependencies {
compile 'com.yuyh.imgsel:library:1.3.7'
compile 'com.yuyh.imgsel:library:1.3.8'
}
```

## 版本

**V1.3.7 图片裁剪适配android-7.0**
**V1.3.8 图片裁剪适配android-7.0 解决Provider冲突**

## 注意事项

Expand Down
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
version = "1.3.7" // 版本号
version = "1.3.8" // 版本号

android {
compileSdkVersion 23
Expand All @@ -11,8 +11,8 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
versionCode 15
versionName "1.3.7"
versionCode 16
versionName "1.3.8"
}
buildTypes {
release {
Expand Down
8 changes: 6 additions & 2 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
android:name=".ImgSelActivity"
android:theme="@style/SelTheme" />

<meta-data
android:name="APP_ID"
android:value="${applicationId}" />

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.yuyh.library.imgsel.provider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
android:resource="@xml/provider_paths" />
</provider>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ public Uri getImageContentUri(File imageFile) {
String filePath = imageFile.getAbsolutePath();
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Images.Media._ID },
new String[]{MediaStore.Images.Media._ID},
MediaStore.Images.Media.DATA + "=? ",
new String[] { filePath }, null);
new String[]{filePath}, null);

if (cursor != null && cursor.moveToFirst()) {
int id = cursor.getInt(cursor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ private void showCameraAction() {
FileUtils.createFile(tempFile);

Uri uri = FileProvider.getUriForFile(getActivity(),
BuildConfig.APPLICATION_ID + ".provider", tempFile);
FileUtils.getApplicationId(getActivity()) + ".provider", tempFile);

List<ResolveInfo> resInfoList = getActivity().getPackageManager()
.queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
Expand Down
229 changes: 11 additions & 218 deletions library/src/main/java/com/yuyh/library/imgsel/utils/FileUtils.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package com.yuyh.library.imgsel.utils;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Environment;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.channels.FileChannel;
import java.text.DecimalFormat;

/**
* @author yuyh.
Expand Down Expand Up @@ -91,216 +83,17 @@ public static String createFile(File file) {
return "";
}

public static String getImageCachePath(String path){
return createDir(path);
}

/**
* 获取图片缓存目录
*
* @return 创建失败, 返回""
*/
public static String getImageCachePath(Context context) {
String path = createDir(createRootPath(context) + File.separator + "img" + File.separator);
return path;
}

/**
* 获取图片裁剪缓存目录
*
* @return 创建失败, 返回""
*/
public static String getImageCropCachePath(Context context) {
String path = createDir(createRootPath(context) + File.separator + "imgCrop" + File.separator);
return path;
}

/**
* 将内容写入文件
*
* @param filePath eg:/mnt/sdcard/demo.txt
* @param content 内容
*/
public static void writeFileSdcard(String filePath, String content, boolean isAppend) {
try {
FileOutputStream fout = new FileOutputStream(filePath, isAppend);
byte[] bytes = content.getBytes();
fout.write(bytes);
fout.close();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 打开Asset下的文件
*
* @param context
* @param fileName
* @return
*/
public static InputStream openAssetFile(Context context, String fileName) {
AssetManager am = context.getAssets();
InputStream is = null;
try {
is = am.open(fileName);
} catch (IOException e) {
e.printStackTrace();
}
return is;
}

/**
* 获取Raw下的文件内容
*
* @param context
* @param resId
* @return 文件内容
*/
public static String getFileFromRaw(Context context, int resId) {
if (context == null) {
return null;
}

StringBuilder s = new StringBuilder();
try {
InputStreamReader in = new InputStreamReader(context.getResources().openRawResource(resId));
BufferedReader br = new BufferedReader(in);
String line;
while ((line = br.readLine()) != null) {
s.append(line);
}
return s.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

/**
* 文件拷贝
*
* @param src 源文件
* @param desc 目的文件
*/
public static void fileChannelCopy(File src, File desc) {
FileInputStream fi = null;
FileOutputStream fo = null;
try {
fi = new FileInputStream(src);
fo = new FileOutputStream(desc);
FileChannel in = fi.getChannel();//得到对应的文件通道
FileChannel out = fo.getChannel();//得到对应的文件通道
in.transferTo(0, in.size(), out);//连接两个通道,并且从in通道读取,然后写入out通道
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fo != null) fo.close();
if (fi != null) fi.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

/**
* 转换文件大小
*
* @param fileLen 单位B
* @return
*/
public static String formatFileSizeToString(long fileLen) {
DecimalFormat df = new DecimalFormat("#.00");
String fileSizeString = "";
if (fileLen < 1024) {
fileSizeString = df.format((double) fileLen) + "B";
} else if (fileLen < 1048576) {
fileSizeString = df.format((double) fileLen / 1024) + "K";
} else if (fileLen < 1073741824) {
fileSizeString = df.format((double) fileLen / 1048576) + "M";
} else {
fileSizeString = df.format((double) fileLen / 1073741824) + "G";
}
return fileSizeString;
}

/**
* 删除指定文件
*
* @param file
* @return
* @throws IOException
*/
public static boolean deleteFile(File file) throws IOException {
return deleteFileOrDirectory(file);
}

/**
* 删除指定文件,如果是文件夹,则递归删除
*
* @param file
* @return
* @throws IOException
*/
public static boolean deleteFileOrDirectory(File file) throws IOException {
try {
if (file != null && file.isFile()) {
return file.delete();
}
if (file != null && file.isDirectory()) {
File[] childFiles = file.listFiles();
// 删除空文件夹
if (childFiles == null || childFiles.length == 0) {
return file.delete();
}
// 递归删除文件夹下的子文件
for (int i = 0; i < childFiles.length; i++) {
deleteFileOrDirectory(childFiles[i]);
}
return file.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}

/***
* 获取文件扩展名
*
* @param filename 文件名
* @return
*/
public static String getExtensionName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot > -1) && (dot < (filename.length() - 1))) {
return filename.substring(dot + 1);
}
}
return filename;
}

/**
* 获取文件内容
*
* @param path
* @return
*/
public static String getFileOutputString(String path) {
public static String getApplicationId(Context appContext) throws IllegalArgumentException {
ApplicationInfo applicationInfo = null;
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(path), 8192);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = bufferedReader.readLine()) != null) {
sb.append("\n").append(line);
applicationInfo = appContext.getPackageManager().getApplicationInfo(appContext.getPackageName(), PackageManager.GET_META_DATA);
if (applicationInfo == null) {
throw new IllegalArgumentException(" get application info = null, has no meta data! ");
}
bufferedReader.close();
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
LogUtils.d(appContext.getPackageName() + " " + applicationInfo.metaData.getString("APP_ID"));
return applicationInfo.metaData.getString("APP_ID");
} catch (PackageManager.NameNotFoundException e) {
throw new IllegalArgumentException(" get application info error! ", e);
}
return null;
}
}

0 comments on commit aab709d

Please sign in to comment.