Skip to content

Commit 4aebc40

Browse files
committed
修改FileProvider可自定义
1 parent 102e14b commit 4aebc40

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

app/src/main/java/com/rain/photopicker/MyApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public void onCreate() {
2121

2222
context = this;
2323

24+
PhotoPick.setAuthority(getString(R.string.file_provider_authorities));
2425
PhotoPick.init(getApplicationContext());
2526
}
2627

library/src/main/java/com/rain/library/PhotoPick.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static PhotoPick getInstance() {
1313
}
1414

1515
private static int toolbarBackGround;
16+
private static String authority;
1617
private static Context mContext;
1718

1819

@@ -26,6 +27,7 @@ public static void init(Context context, int toolbarBackGroundId) {
2627
if (mContext != null) return;
2728
toolbarBackGround = toolbarBackGroundId;
2829
mContext = context.getApplicationContext();
30+
2931
}
3032

3133
public static int getToolbarBackGround() {
@@ -41,6 +43,14 @@ public static void setToolbarBackGround(int toolbarBackGroundId) {
4143
toolbarBackGround = toolbarBackGroundId;
4244
}
4345

46+
public static String getAuthority() {
47+
return authority;
48+
}
49+
50+
public static void setAuthority(String authorityPath) {
51+
authority = authorityPath;
52+
}
53+
4454

4555
public static void checkInit() {
4656
if (mContext == null) {

library/src/main/java/com/rain/library/PhotoPickAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void selectPicFromCamera() {
204204
// Android7.0以上URI
205205
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
206206
//通过FileProvider创建一个content类型的Uri
207-
cameraUri = FileProvider.getUriForFile(context, "com.rain.photopicker.provider", imageFile);
207+
cameraUri = FileProvider.getUriForFile(context, PhotoPick.getAuthority(), imageFile);
208208
//添加这一句表示对目标应用临时授权该Uri所代表的文件,私有目录读写权限
209209
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
210210
} else {

library/src/main/java/com/rain/library/ui/PhotoPickActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void selectPicFromCamera() {
248248
// Android7.0以上URI
249249
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
250250
//通过FileProvider创建一个content类型的Uri
251-
cameraUri = FileProvider.getUriForFile(this, "com.rain.photopicker.provider", imageFile);
251+
cameraUri = FileProvider.getUriForFile(this, PhotoPick.getAuthority(), imageFile);
252252
//添加这一句表示对目标应用临时授权该Uri所代表的文件,私有目录读写权限
253253
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
254254
} else {

0 commit comments

Comments
 (0)