新增 支持Content Uri编辑脚本
This commit is contained in:
@@ -136,6 +136,8 @@ public class PFiles {
|
||||
return new String(bytes, encoding);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
} finally {
|
||||
closeSilently(is);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +220,7 @@ public class PFiles {
|
||||
}
|
||||
}
|
||||
|
||||
public static void write(FileOutputStream fileOutputStream, String text) {
|
||||
public static void write(OutputStream fileOutputStream, String text) {
|
||||
write(fileOutputStream, text, "utf-8");
|
||||
}
|
||||
|
||||
@@ -226,9 +228,10 @@ public class PFiles {
|
||||
public static void write(OutputStream outputStream, String text, String encoding) {
|
||||
try {
|
||||
outputStream.write(text.getBytes(encoding));
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
} finally {
|
||||
closeSilently(outputStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +134,25 @@ public class IntentUtil {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public static boolean viewFile(Context context, Uri uri, String mimeType, String fileProviderAuthority) {
|
||||
if (uri.getScheme().equals("file")) {
|
||||
return viewFile(context, uri.getPath(), mimeType, fileProviderAuthority);
|
||||
} else {
|
||||
try {
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW)
|
||||
.setDataAndType(uri, mimeType)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean viewFile(Context context, String path, String mimeType, String fileProviderAuthority) {
|
||||
try {
|
||||
Uri uri = getUriOfFile(context, path, fileProviderAuthority);
|
||||
|
||||
Reference in New Issue
Block a user