Skip to content

Commit 7b4c835

Browse files
committed
see 04/20 log
1 parent 077e24e commit 7b4c835

File tree

13 files changed

+259
-56
lines changed

13 files changed

+259
-56
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,6 @@
165165
android:name=".feature.core.toast.ToastActivity"
166166
android:launchMode="singleTop" />
167167

168-
<provider
169-
android:name="android.support.v4.content.FileProvider"
170-
android:authorities="com.blankj.androidutilcode.provider"
171-
android:exported="false"
172-
android:grantUriPermissions="true">
173-
<meta-data
174-
android:name="android.support.FILE_PROVIDER_PATHS"
175-
android:resource="@xml/provider_paths" />
176-
</provider>
177-
178-
179168
<!--sub-->
180169
<activity
181170
android:name=".feature.sub.SubUtilActivity"

app/src/main/java/com/blankj/androidutilcode/UtilsApp.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public void initLog() {
6161
.setSingleTagSwitch(true)// 一条日志仅输出一条,默认开,为美化 AS 3.1 的 Logcat
6262
.setConsoleFilter(LogUtils.V)// log 的控制台过滤器,和 logcat 过滤器同理,默认 Verbose
6363
.setFileFilter(LogUtils.V)// log 文件过滤器,和 logcat 过滤器同理,默认 Verbose
64-
.setStackDeep(1);// log 栈深度,默认为 1
64+
.setStackDeep(1)// log 栈深度,默认为 1
65+
.setStackOffset(0);// 设置栈偏移,比如二次封装的话就需要设置,默认为 0
6566
LogUtils.d(config.toString());
6667
}
6768

app/src/main/java/com/blankj/androidutilcode/feature/core/app/AppActivity.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ public void onPermissionGranted() {
8989
AssertHelper.releaseInstallApk(new AssertHelper.OnReleasedListener() {
9090
@Override
9191
public void onReleased() {
92-
AppUtils.installApp(
93-
Config.TEST_APK_PATH,
94-
"com.blankj.androidutilcode.provider"
95-
);
92+
AppUtils.installApp(Config.TEST_APK_PATH);
9693
}
9794
});
9895
}

app/src/main/res_core/xml/provider_paths.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* 18/04/22 新增 LogUtils#,发布 1.13.15 版本
12
* 18/04/21 新增 AppUtils#relaunchApp、DeviceUtils#getABIs,发布 1.13.15 版本
23
* 18/04/20 新增 BarUtils#setNavBarColor、BarUtils#getNavBarColor
34
* 18/04/19 新增 Process#isMainProcess、Process#getCurrentProcessName,发布 1.13.14 版本

utilcode/README-CN.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -341,33 +341,36 @@ clickBlankArea2HideSoftInput : 点击屏幕空白区域隐藏软键盘
341341

342342
* ### 日志相关 -> [LogUtils.java][log.java] -> [Demo][log.demo]
343343
```
344-
getConfig : 获取 log 配置
345-
Config.setLogSwitch : 设置 log 总开关
346-
Config.setConsoleSwitch : 设置 log 控制台开关
347-
Config.setGlobalTag : 设置 log 全局 tag
348-
Config.setLogHeadSwitch : 设置 log 头部信息开关
349-
Config.setLog2FileSwitch: 设置 log 文件开关
350-
Config.setDir : 设置 log 文件存储目录
351-
Config.setFilePrefix : 设置 log 文件前缀
352-
Config.setBorderSwitch : 设置 log 边框开关
353-
Config.setConsoleFilter : 设置 log 控制台过滤器
354-
Config.setFileFilter : 设置 log 文件过滤器
355-
Config.setStackDeep : 设置 log 栈深度
356-
v : tag 为类名的 Verbose 日志
357-
vTag : 自定义 tag 的 Verbose 日志
358-
d : tag 为类名的 Debug 日志
359-
dTag : 自定义 tag 的 Debug 日志
360-
i : tag 为类名的 Info 日志
361-
iTag : 自定义 tag 的 Info 日志
362-
w : tag 为类名的 Warn 日志
363-
wTag : 自定义 tag 的 Warn 日志
364-
e : tag 为类名的 Error 日志
365-
eTag : 自定义 tag 的 Error 日志
366-
a : tag 为类名的 Assert 日志
367-
aTag : 自定义 tag 的 Assert 日志
368-
file : log 到文件
369-
json : log 字符串之 json
370-
xml : log 字符串之 xml
344+
getConfig : 获取 log 配置
345+
Config.setLogSwitch : 设置 log 总开关
346+
Config.setConsoleSwitch : 设置 log 控制台开关
347+
Config.setGlobalTag : 设置 log 全局 tag
348+
Config.setLogHeadSwitch : 设置 log 头部信息开关
349+
Config.setLog2FileSwitch : 设置 log 文件开关
350+
Config.setDir : 设置 log 文件存储目录
351+
Config.setFilePrefix : 设置 log 文件前缀
352+
Config.setBorderSwitch : 设置 log 边框开关
353+
Config.setSingleTagSwitch: 设置 log 单一 tag 开关(为美化 AS 3.1 的 Logcat)
354+
Config.setConsoleFilter : 设置 log 控制台过滤器
355+
Config.setFileFilter : 设置 log 文件过滤器
356+
Config.setStackDeep : 设置 log 栈深度
357+
Config.setStackOffset : 设置 log 栈偏移
358+
log : 自定义 tag 的 type 日志
359+
v : tag 为类名的 Verbose 日志
360+
vTag : 自定义 tag 的 Verbose 日志
361+
d : tag 为类名的 Debug 日志
362+
dTag : 自定义 tag 的 Debug 日志
363+
i : tag 为类名的 Info 日志
364+
iTag : 自定义 tag 的 Info 日志
365+
w : tag 为类名的 Warn 日志
366+
wTag : 自定义 tag 的 Warn 日志
367+
e : tag 为类名的 Error 日志
368+
eTag : 自定义 tag 的 Error 日志
369+
a : tag 为类名的 Assert 日志
370+
aTag : 自定义 tag 的 Assert 日志
371+
file : log 到文件
372+
json : log 字符串之 json
373+
xml : log 字符串之 xml
371374
```
372375

373376
* ### 网络相关 -> [NetworkUtils.java][network.java] -> [Demo][network.demo]

utilcode/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,12 @@ Config.setLog2FileSwitch
350350
Config.setDir
351351
Config.setFilePrefix
352352
Config.setBorderSwitch
353+
Config.setSingleTagSwitch
353354
Config.setConsoleFilter
354355
Config.setFileFilter
355356
Config.setStackDeep
357+
Config.setStackOffset
358+
log
356359
v
357360
vTag
358361
d

utilcode/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,15 @@
88
android:multiprocess="true"
99
android:theme="@style/ActivityTranslucent"
1010
android:windowSoftInputMode="stateHidden|stateAlwaysHidden" />
11+
12+
<provider
13+
android:name="android.support.v4.content.FileProvider"
14+
android:authorities="${applicationId}.utilcode.provider"
15+
android:exported="false"
16+
android:grantUriPermissions="true">
17+
<meta-data
18+
android:name="android.support.FILE_PROVIDER_PATHS"
19+
android:resource="@xml/provider_paths" />
20+
</provider>
1121
</application>
1222
</manifest>

utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ private AppUtils() {
3333
throw new UnsupportedOperationException("u can't instantiate me...");
3434
}
3535

36+
/**
37+
* Install the app.
38+
* <p>Target APIs greater than 25 must hold
39+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
40+
*
41+
* @param filePath The path of file.
42+
*/
43+
public static void installApp(final String filePath) {
44+
installApp(getFileByPath(filePath));
45+
}
46+
47+
/**
48+
* Install the app.
49+
* <p>Target APIs greater than 25 must hold
50+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
51+
*
52+
* @param file The file.
53+
*/
54+
public static void installApp(final File file) {
55+
if (!isFileExists(file)) return;
56+
Utils.getApp().startActivity(IntentUtils.getInstallAppIntent(file, true));
57+
}
58+
3659
/**
3760
* Install the app.
3861
* <p>Target APIs greater than 25 must hold
@@ -42,6 +65,7 @@ private AppUtils() {
4265
* @param authority Target APIs greater than 23 must hold the authority of a FileProvider
4366
* defined in a {@code <provider>} element in your app's manifest.
4467
*/
68+
@Deprecated
4569
public static void installApp(final String filePath, final String authority) {
4670
installApp(getFileByPath(filePath), authority);
4771
}
@@ -55,11 +79,45 @@ public static void installApp(final String filePath, final String authority) {
5579
* @param authority Target APIs greater than 23 must hold the authority of a FileProvider
5680
* defined in a {@code <provider>} element in your app's manifest.
5781
*/
82+
@Deprecated
5883
public static void installApp(final File file, final String authority) {
5984
if (!isFileExists(file)) return;
6085
Utils.getApp().startActivity(IntentUtils.getInstallAppIntent(file, authority, true));
6186
}
6287

88+
/**
89+
* Install the app.
90+
* <p>Target APIs greater than 25 must hold
91+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
92+
*
93+
* @param activity The activity.
94+
* @param filePath The path of file.
95+
* @param requestCode If &gt;= 0, this code will be returned in
96+
* onActivityResult() when the activity exits.
97+
*/
98+
public static void installApp(final Activity activity,
99+
final String filePath,
100+
final int requestCode) {
101+
installApp(activity, getFileByPath(filePath), requestCode);
102+
}
103+
104+
/**
105+
* Install the app.
106+
* <p>Target APIs greater than 25 must hold
107+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
108+
*
109+
* @param activity The activity.
110+
* @param file The file.
111+
* @param requestCode If &gt;= 0, this code will be returned in
112+
* onActivityResult() when the activity exits.
113+
*/
114+
public static void installApp(final Activity activity,
115+
final File file,
116+
final int requestCode) {
117+
if (!isFileExists(file)) return;
118+
activity.startActivityForResult(IntentUtils.getInstallAppIntent(file), requestCode);
119+
}
120+
63121
/**
64122
* Install the app.
65123
* <p>Target APIs greater than 25 must hold
@@ -72,6 +130,7 @@ public static void installApp(final File file, final String authority) {
72130
* @param requestCode If &gt;= 0, this code will be returned in
73131
* onActivityResult() when the activity exits.
74132
*/
133+
@Deprecated
75134
public static void installApp(final Activity activity,
76135
final String filePath,
77136
final String authority,
@@ -91,6 +150,7 @@ public static void installApp(final Activity activity,
91150
* @param requestCode If &gt;= 0, this code will be returned in
92151
* onActivityResult() when the activity exits.
93152
*/
153+
@Deprecated
94154
public static void installApp(final Activity activity,
95155
final File file,
96156
final String authority,

utilcode/src/main/java/com/blankj/utilcode/util/CrashUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void uncaughtException(final Thread t, final Throwable e) {
8080
final String time = FORMAT.format(new Date(System.currentTimeMillis()));
8181
final StringBuilder sb = new StringBuilder();
8282
final String head = "************* Log Head ****************" +
83-
"\nThe time of Crash : " + time +
83+
"\nTime Of Crash : " + time +
8484
"\nDevice Manufacturer: " + Build.MANUFACTURER +
8585
"\nDevice Model : " + Build.MODEL +
8686
"\nAndroid Version : " + Build.VERSION.RELEASE +

utilcode/src/main/java/com/blankj/utilcode/util/IntentUtils.java

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,68 @@ private IntentUtils() {
2727
throw new UnsupportedOperationException("u can't instantiate me...");
2828
}
2929

30+
/**
31+
* Return the intent of install app.
32+
* <p>Target APIs greater than 25 must hold
33+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
34+
*
35+
* @param filePath The path of file.
36+
* @return the intent of install app
37+
*/
38+
public static Intent getInstallAppIntent(final String filePath) {
39+
return getInstallAppIntent(getFileByPath(filePath), false);
40+
}
41+
42+
/**
43+
* Return the intent of install app.
44+
* <p>Target APIs greater than 25 must hold
45+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
46+
*
47+
* @param file The file.
48+
* @return the intent of install app
49+
*/
50+
public static Intent getInstallAppIntent(final File file) {
51+
return getInstallAppIntent(file, false);
52+
}
53+
54+
/**
55+
* Return the intent of install app.
56+
* <p>Target APIs greater than 25 must hold
57+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
58+
*
59+
* @param filePath The path of file.
60+
* @param isNewTask True to add flag of new task, false otherwise.
61+
* @return the intent of install app
62+
*/
63+
public static Intent getInstallAppIntent(final String filePath, final boolean isNewTask) {
64+
return getInstallAppIntent(getFileByPath(filePath), isNewTask);
65+
}
66+
67+
/**
68+
* Return the intent of install app.
69+
* <p>Target APIs greater than 25 must hold
70+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
71+
*
72+
* @param file The file.
73+
* @param isNewTask True to add flag of new task, false otherwise.
74+
* @return the intent of install app
75+
*/
76+
public static Intent getInstallAppIntent(final File file, final boolean isNewTask) {
77+
if (file == null) return null;
78+
Intent intent = new Intent(Intent.ACTION_VIEW);
79+
Uri data;
80+
String type = "application/vnd.android.package-archive";
81+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
82+
data = Uri.fromFile(file);
83+
} else {
84+
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
85+
String authority = Utils.getApp().getPackageName() + ".utilcode.provider";
86+
data = FileProvider.getUriForFile(Utils.getApp(), authority, file);
87+
}
88+
intent.setDataAndType(data, type);
89+
return getIntent(intent, isNewTask);
90+
}
91+
3092
/**
3193
* Return the intent of install app.
3294
* <p>Target APIs greater than 25 must hold
@@ -37,8 +99,9 @@ private IntentUtils() {
3799
* defined in a {@code <provider>} element in your app's manifest.
38100
* @return the intent of install app
39101
*/
102+
@Deprecated
40103
public static Intent getInstallAppIntent(final String filePath, final String authority) {
41-
return getInstallAppIntent(FileUtils.getFileByPath(filePath), authority);
104+
return getInstallAppIntent(getFileByPath(filePath), authority, false);
42105
}
43106

44107
/**
@@ -51,10 +114,29 @@ public static Intent getInstallAppIntent(final String filePath, final String aut
51114
* defined in a {@code <provider>} element in your app's manifest.
52115
* @return the intent of install app
53116
*/
117+
@Deprecated
54118
public static Intent getInstallAppIntent(final File file, final String authority) {
55119
return getInstallAppIntent(file, authority, false);
56120
}
57121

122+
/**
123+
* Return the intent of install app.
124+
* <p>Target APIs greater than 25 must hold
125+
* {@code <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />}</p>
126+
*
127+
* @param filePath The path of file.
128+
* @param authority Target APIs greater than 23 must hold the authority of a FileProvider
129+
* defined in a {@code <provider>} element in your app's manifest.
130+
* @param isNewTask True to add flag of new task, false otherwise.
131+
* @return the intent of install app
132+
*/
133+
@Deprecated
134+
public static Intent getInstallAppIntent(final String filePath,
135+
final String authority,
136+
final boolean isNewTask) {
137+
return getInstallAppIntent(getFileByPath(filePath), authority, isNewTask);
138+
}
139+
58140
/**
59141
* Return the intent of install app.
60142
* <p>Target APIs greater than 25 must hold
@@ -66,6 +148,7 @@ public static Intent getInstallAppIntent(final File file, final String authority
66148
* @param isNewTask True to add flag of new task, false otherwise.
67149
* @return the intent of install app
68150
*/
151+
@Deprecated
69152
public static Intent getInstallAppIntent(final File file,
70153
final String authority,
71154
final boolean isNewTask) {
@@ -451,6 +534,20 @@ private static Intent getIntent(final Intent intent, final boolean isNewTask) {
451534
return isNewTask ? intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) : intent;
452535
}
453536

537+
private static File getFileByPath(final String filePath) {
538+
return isSpace(filePath) ? null : new File(filePath);
539+
}
540+
541+
private static boolean isSpace(final String s) {
542+
if (s == null) return true;
543+
for (int i = 0, len = s.length(); i < len; ++i) {
544+
if (!Character.isWhitespace(s.charAt(i))) {
545+
return false;
546+
}
547+
}
548+
return true;
549+
}
550+
454551
// /**
455552
// * 获取选择照片的 Intent
456553
// *

0 commit comments

Comments
 (0)