提交 3c6fa6b1 编写于 作者: B Blankj

see 09/03 log

上级 0dc2c95e
......@@ -41,7 +41,7 @@
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.19.4-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.20.0-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
......@@ -122,13 +122,25 @@
android:launchMode="singleTop" />
<activity
android:name=".feature.core.keyboard.KeyboardActivity"
android:launchMode="singleTop" />
android:launchMode="singleTop"
android:windowSoftInputMode="stateHidden" />
<activity
android:name=".feature.core.log.LogActivity"
android:launchMode="singleTop" />
<activity
android:name=".feature.core.meta_data.MetaDataActivity"
android:launchMode="singleTop">
<meta-data
android:name="activity_meta_data"
android:value="ActivityMetaData" />
</activity>
<activity
android:name=".feature.core.network.NetworkActivity"
android:launchMode="singleTop" />
<activity
android:name=".feature.core.path.PathActivity"
android:launchMode="singleTop" />
<activity
android:name=".feature.core.permission.PermissionActivity"
android:launchMode="singleTop" />
......@@ -166,6 +178,10 @@
android:name=".feature.core.toast.ToastActivity"
android:launchMode="singleTop" />
<meta-data
android:name="app_meta_data"
android:value="AppMetaData" />
<!-- sub -->
<activity
android:name=".feature.sub.SubUtilActivity"
......@@ -184,22 +200,11 @@
android:name=".feature.sub.location.LocationService"
android:launchMode="singleTop" />
<activity
android:name=".feature.sub.meta_data.MetaDataActivity"
android:launchMode="singleTop">
<meta-data
android:name="activity_meta_data"
android:value="activity" />
</activity>
<activity
android:name=".feature.sub.pinyin.PinyinActivity"
android:launchMode="singleTop"
android:screenOrientation="landscape" />
<meta-data
android:name="app_meta_data"
android:value="1234" />
</application>
</manifest>
\ No newline at end of file
......@@ -12,7 +12,6 @@ import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.feature.core.CoreUtilActivity;
import com.blankj.androidutilcode.feature.sub.SubUtilActivity;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.ScreenUtils;
/**
* <pre>
......
......@@ -17,7 +17,9 @@ import com.blankj.androidutilcode.feature.core.fragment.FragmentActivity;
import com.blankj.androidutilcode.feature.core.image.ImageActivity;
import com.blankj.androidutilcode.feature.core.keyboard.KeyboardActivity;
import com.blankj.androidutilcode.feature.core.log.LogActivity;
import com.blankj.androidutilcode.feature.core.meta_data.MetaDataActivity;
import com.blankj.androidutilcode.feature.core.network.NetworkActivity;
import com.blankj.androidutilcode.feature.core.path.PathActivity;
import com.blankj.androidutilcode.feature.core.permission.PermissionActivity;
import com.blankj.androidutilcode.feature.core.phone.PhoneActivity;
import com.blankj.androidutilcode.feature.core.process.ProcessActivity;
......@@ -43,7 +45,7 @@ public class CoreUtilActivity extends BaseBackActivity {
public static void start(Context context) {
Intent starter = new Intent(context, CoreUtilActivity.class);
context.startActivity(starter.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
context.startActivity(starter);
}
@Override
......@@ -116,10 +118,18 @@ public class CoreUtilActivity extends BaseBackActivity {
LogActivity.start(this);
}
public void metaDataClick(View view) {
MetaDataActivity.start(this);
}
public void networkClick(View view) {
NetworkActivity.start(this);
}
public void pathClick(View view) {
PathActivity.start(this);
}
public void permissionClick(View view) {
PermissionActivity.start(this);
}
......
......@@ -11,8 +11,11 @@ import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.androidutilcode.helper.DialogHelper;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SpanUtils;
/**
......@@ -23,7 +26,7 @@ import com.blankj.utilcode.util.SpanUtils;
* desc : demo about KeyboardUtils
* </pre>
*/
public class KeyboardActivity extends BaseActivity{
public class KeyboardActivity extends BaseBackActivity {
public static void start(Context context) {
Intent starter = new Intent(context, KeyboardActivity.class);
......@@ -41,7 +44,7 @@ public class KeyboardActivity extends BaseActivity{
@Override
public int bindLayout() {
return R.layout.activity_keyboard1;
return R.layout.activity_keyboard;
}
@Override
......
package com.blankj.androidutilcode.feature.sub.meta_data;
package com.blankj.androidutilcode.feature.core.meta_data;
import android.content.Context;
import android.content.Intent;
......@@ -9,7 +9,7 @@ import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.subutil.util.MetaDataUtils;
import com.blankj.utilcode.util.MetaDataUtils;
import com.blankj.utilcode.util.SpanUtils;
/**
......@@ -17,7 +17,7 @@ import com.blankj.utilcode.util.SpanUtils;
* author: Blankj
* blog : http://blankj.com
* time : 2018/05/15
* desc :
* desc : demo about MetaDataUtils
* </pre>
*/
public class MetaDataActivity extends BaseBackActivity {
......
package com.blankj.androidutilcode.feature.core.path;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.SpanUtils;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/10/13
* desc : demo about PathUtils
* </pre>
*/
public class PathActivity extends BaseBackActivity {
public static void start(Context context) {
Intent starter = new Intent(context, PathActivity.class);
context.startActivity(starter);
}
@Override
public void initData(@Nullable Bundle bundle) {
}
@Override
public int bindLayout() {
return R.layout.activity_path;
}
@Override
public void initView(Bundle savedInstanceState, View contentView) {
getToolBar().setTitle(getString(R.string.demo_path));
TextView tvAboutMetaData = findViewById(R.id.tv_about_path);
tvAboutMetaData.setText(new SpanUtils()
// .appendLine("getRootPath: " + PathUtils.getRootPath())
.append("")
.create());
}
@Override
public void doBusiness() {
}
@Override
public void onWidgetClick(View view) {
}
}
......@@ -11,7 +11,6 @@ import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.androidutilcode.feature.sub.brightness.BrightnessActivity;
import com.blankj.androidutilcode.feature.sub.flashlight.FlashlightActivity;
import com.blankj.androidutilcode.feature.sub.location.LocationActivity;
import com.blankj.androidutilcode.feature.sub.meta_data.MetaDataActivity;
import com.blankj.androidutilcode.feature.sub.pinyin.PinyinActivity;
/**
......@@ -66,10 +65,6 @@ public class SubUtilActivity extends BaseBackActivity {
LocationActivity.start(this);
}
public void metaDataClick(View view) {
MetaDataActivity.start(this);
}
public void pinyinClick(View view) {
PinyinActivity.start(this);
}
......
......@@ -48,7 +48,6 @@
android:id="@+id/et_input"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:inputType="text" />
......@@ -56,7 +55,6 @@
android:id="@+id/et_input1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:inputType="text" />
......@@ -64,7 +62,6 @@
android:id="@+id/et_input2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:inputType="text" />
......@@ -80,7 +77,6 @@
android:id="@+id/et_input4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:inputType="text" />
......@@ -88,7 +84,6 @@
android:id="@+id/et_input5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:inputType="text" />
......@@ -96,35 +91,48 @@
android:id="@+id/et_input6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:inputType="text" />
<EditText
android:id="@+id/et_input7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:inputType="text" />
<EditText
android:id="@+id/et_input8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:inputType="text" />
<EditText
android:id="@+id/et_input9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:inputType="text" />
<EditText
android:id="@+id/et_input10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:inputType="text" />
<EditText
android:id="@+id/et_input11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="text" />
<EditText
android:id="@+id/et_input12"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="text" />
<EditText
android:id="@+id/et_input13"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="text" />
</LinearLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_16">
<TextView
android:id="@+id/tv_about_path"
style="@style/TextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
......@@ -78,6 +78,13 @@
android:onClick="logClick"
android:text="@string/demo_log" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="metaDataClick"
android:text="@string/demo_meta_data" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
......@@ -85,6 +92,13 @@
android:onClick="networkClick"
android:text="@string/demo_network" />
<!--<Button-->
<!--style="@style/WideBtnStyle"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:onClick="pathClick"-->
<!--android:text="@string/demo_path" />-->
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
......
......@@ -10,7 +10,9 @@
<string name="demo_image">ImageUtils Demo</string>
<string name="demo_keyboard">KeyboardUtils Demo</string>
<string name="demo_log">LogUtils Demo</string>
<string name="demo_meta_data">MetaData Demo</string>
<string name="demo_network">NetworkUtils Demo</string>
<string name="demo_path">Path Demo</string>
<string name="demo_permission">PermissionUtils Demo</string>
<string name="demo_phone">PhoneUtils Demo</string>
<string name="demo_process">ProcessUtils Demo</string>
......
......@@ -28,13 +28,6 @@
android:onClick="locationClick"
android:text="@string/demo_location" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="metaDataClick"
android:text="@string/demo_meta_data" />
<Button
style="@style/WideBtnStyle"
android:layout_width="match_parent"
......
......@@ -3,7 +3,6 @@
<string name="demo_flashlight">FlashlightUtils Demo</string>
<string name="demo_brightness">Brightness Demo</string>
<string name="demo_location">LocationUtils Demo</string>
<string name="demo_meta_data">MetaData Demo</string>
<string name="demo_pinyin">PinyinUtils Demo</string>
<!-- Brightness 相关 -->
......
......@@ -6,8 +6,8 @@ ext {
compileSdkVersion: 27,
minSdkVersion : 14,
targetSdkVersion : 27,
versionCode : 1_019_004,
versionName : '1.19.4'// E.g. 1.9.72 => 1,009,072
versionCode : 1_020_000,
versionName : '1.20.0'// E.g. 1.9.72 => 1,009,072
]
versionConfig = [
......@@ -20,7 +20,7 @@ ext {
glide : '4.7.1',
leakcanary : '1.5.4',
retrofit : '2.4.0',
free_proguard: '0.0.6',
free_proguard: '0.0.7',
// test
junit : '4.12',
robolectric : '3.1.2'
......@@ -172,7 +172,7 @@ def configAppDependencies(Project pro) {
// LeakCanary
debugImplementation depConfig.leakcanary.android
releaseImplementation depConfig.leakcanary.android_no_op
// implementation 'com.blankj:utilcode:1.19.4'
// implementation 'com.blankj:utilcode:1.20.0'
}
}
......
......@@ -73,14 +73,6 @@ isBetterLocation : 是否更好的位置
isSameProvider : 是否相同的提供者
```
* ### MetaData 相关 -> [MetaDataUtils.java][meta_data.java] -> [Demo][meta_data.demo]
```
getMetaDataInApp : 获取 application 的 meta-data 值
getMetaDataInActivity: 获取 activity 的 meta-data 值
getMetaDataInService : 获取 service 的 meta-data 值
getMetaDataInReceiver: 获取 receiver 的 meta-data 值
```
* ### 拼音相关 -> [PinyinUtils.java][pinyin.java] -> [Demo][pinyin.demo]
```
ccs2Pinyin : 汉字转拼音
......@@ -114,8 +106,5 @@ getSurnameFirstLetter: 根据名字获取姓氏的首字母
[location.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/subutil/src/main/java/com/blankj/subutil/util/LocationUtils.java
[location.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/sub/location/LocationActivity.java
[meta_data.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/subutil/src/main/java/com/blankj/subutil/util/MetaDataUtils.java
[meta_data.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/sub/meta_data/MetaDataActivity.java
[pinyin.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/subutil/src/main/java/com/blankj/subutil/util/PinyinUtils.java
[pinyin.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/sub/pinyin/PinyinActivity.java
......@@ -73,14 +73,6 @@ isBetterLocation
isSameProvider
```
* ### About MetaData -> [MetaDataUtils.java][meta_data.java] -> [Demo][meta_data.demo]
```
getMetaDataInApp
getMetaDataInActivity
getMetaDataInService
getMetaDataInReceiver
```
* ### About Pinyin -> [PinyinUtils.java][pinyin.java] -> [Demo][pinyin.demo]
```
ccs2Pinyin
......@@ -114,8 +106,5 @@ getSurnameFirstLetter
[location.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/subutil/src/main/java/com/blankj/subutil/util/LocationUtils.java
[location.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/sub/location/LocationActivity.java
[meta_data.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/subutil/src/main/java/com/blankj/subutil/util/MetaDataUtils.java
[meta_data.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/sub/meta_data/MetaDataActivity.java
[pinyin.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/subutil/src/main/java/com/blankj/subutil/util/PinyinUtils.java
[pinyin.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/sub/pinyin/PinyinActivity.java
......@@ -26,6 +26,7 @@ public final class CloneUtils {
*/
public static <T> T deepClone(final Serializable data) {
if (data == null) return null;
//noinspection unchecked
return (T) bytes2Object(serializable2Bytes((Serializable) data));
}
......
package com.blankj.subutil.util;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.support.annotation.RequiresApi;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2018/04/15
* desc : 路径相关工具类
* </pre>
*/
public class PathUtils {
private PathUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* 获取 Android 系统根目录
* <pre>path: /system</pre>
*
* @return 系统根目录
*/
public static String getRootPath() {
return Environment.getRootDirectory().getAbsolutePath();
}
/**
* 获取 data 目录
* <pre>path: /data</pre>
*
* @return data 目录
*/
public static String getDataPath() {
return Environment.getDataDirectory().getAbsolutePath();
}
/**
* 获取缓存目录
* <pre>path: data/cache</pre>
*
* @return 缓存目录
*/
public static String getIntDownloadCachePath() {
return Environment.getDownloadCacheDirectory().getAbsolutePath();
}
/**
* 获取此应用的缓存目录
* <pre>path: /data/data/package/cache</pre>
*
* @return 此应用的缓存目录
*/
public static String getAppIntCachePath() {
return Utils.getApp().getCacheDir().getAbsolutePath();
}
/**
* 获取此应用的文件目录
* <pre>path: /data/data/package/files</pre>
*
* @return 此应用的文件目录
*/
public static String getAppIntFilesPath() {
return Utils.getApp().getFilesDir().getAbsolutePath();
}
/**
* 获取此应用的数据库文件目录
* <pre>path: /data/data/package/databases/name</pre>
*
* @param name 数据库文件名
* @return 数据库文件目录
*/
public static String getAppIntDbPath(String name) {
return Utils.getApp().getDatabasePath(name).getAbsolutePath();
}
/**
* 获取 Android 外置储存的根目录
* <pre>path: /storage/emulated/0</pre>
*
* @return 外置储存根目录
*/
public static String getExtStoragePath() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}
/**
* 获取闹钟铃声目录
* <pre>path: /storage/emulated/0/Alarms</pre>
*
* @return 闹钟铃声目录
*/
public static String getExtAlarmsPath() {
return Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS)
.getAbsolutePath();
}
/**
* 获取相机拍摄的照片和视频的目录
* <pre>path: /storage/emulated/0/DCIM</pre>
*
* @return 照片和视频目录
*/
public static String getExtDcimPath() {
return Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
.getAbsolutePath();
}
/**
* 获取文档目录
* <pre>path: /storage/emulated/0/Documents</pre>
*
* @return 文档目录
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static String getExtDocumentsPath() {
return Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)
.getAbsolutePath();
}
/**
* 获取下载目录
* <pre>path: /storage/emulated/0/Download</pre>
*
* @return 下载目录
*/
public static String getExtDownloadsPath() {
return Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.getAbsolutePath();
}
/**
* 获取视频目录
* <pre>path: /storage/emulated/0/Movies</pre>
*
* @return 视频目录
*/
public static String getExtMoviesPath() {
return Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
.getAbsolutePath();
}
/**
* 获取音乐目录
* <pre>path: /storage/emulated/0/Music</pre>
*
* @return 音乐目录
*/
public static String getExtMusicPath() {
return Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
.getAbsolutePath();
}
/**
* 获取提示音目录
* <pre>path: /storage/emulated/0/Notifications</pre>
*
* @return 提示音目录
*/
public static String getExtNotificationsPath() {
return Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS)
.getAbsolutePath();
}
/**
* 获取图片目录
* <pre>path: /storage/emulated/0/Pictures</pre>
*
* @return 图片目录
*/
public static String getExtPicturesPath() {
return Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
.getAbsolutePath();
}
/**
* 获取 Podcasts 目录
* <pre>path: /storage/emulated/0/Podcasts</pre>
*
* @return Podcasts 目录
*/
public static String getExtPodcastsPath() {
return Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS)
.getAbsolutePath();
}
/**
* 获取铃声目录
* <pre>path: /storage/emulated/0/Ringtones</pre>
*
* @return 下载目录
*/
public static String getExtRingtonesPath() {
return Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES)
.getAbsolutePath();
}
/**
* 获取此应用在外置储存中的缓存目录
* <pre>path: /storage/emulated/0/Android/data/package/cache</pre>
*
* @return 此应用在外置储存中的缓存目录
*/
public static String getAppExtCachePath() {
return Utils.getApp().getExternalCacheDir().getAbsolutePath();
}
/**
* 获取此应用在外置储存中的文件目录
* <pre>path: /storage/emulated/0/Android/data/package/files</pre>
*
* @return 此应用在外置储存中的文件目录
*/
public static String getAppExtFilePath() {
return Utils.getApp().getExternalFilesDir(null).getAbsolutePath();
}
/**
* 获取此应用在外置储存中的闹钟铃声目录
* <pre>path: /storage/emulated/0/Android/data/package/files/Alarms</pre>
*
* @return 此应用在外置储存中的闹钟铃声目录
*/
public static String getAppExtAlarmsPath() {
return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_ALARMS)
.getAbsolutePath();
}
/**
* 获取此应用在外置储存中的相机目录
* <pre>path: /storage/emulated/0/Android/data/package/files/DCIM</pre>
*
* @return 此应用在外置储存中的相机目录
*/
public static String getAppExtDcimPath() {
return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_DCIM)
.getAbsolutePath();
}
/**
* 获取此应用在外置储存中的文档目录
* <pre>path: /storage/emulated/0/Android/data/package/files/Documents</pre>
*
* @return 此应用在外置储存中的文档目录
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static String getAppExtDocumentsPath() {
return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)
.getAbsolutePath();
}
/**
* 获取此应用在外置储存中的闹钟目录
* <pre>path: /storage/emulated/0/Android/data/package/files/Download</pre>
*
* @return 此应用在外置储存中的闹钟目录
*/
public static String getAppExtDownloadPath() {
return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
.getAbsolutePath();
}
/**
* 获取此应用在外置储存中的视频目录
* <pre>path: /storage/emulated/0/Android/data/package/files/Movies</pre>
*
* @return 此应用在外置储存中的视频目录
*/
public static String getAppExtMoviesPath() {
return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_MOVIES)
.getAbsolutePath();
}
/**
* 获取此应用在外置储存中的音乐目录
* <pre>path: /storage/emulated/0/Android/data/package/files/Music</pre>
*
* @return 此应用在外置储存中的音乐目录
*/
public static String getAppExtMusicPath() {
return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_MUSIC)
.getAbsolutePath();
}
/**
* 获取此应用在外置储存中的提示音目录
* <pre>path: /storage/emulated/0/Android/data/package/files/Notifications</pre>
*
* @return 此应用在外置储存中的提示音目录
*/
public static String getAppExtNotificationsPath() {
return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_NOTIFICATIONS)
.getAbsolutePath();
}
/**
* 获取此应用在外置储存中的图片目录
* <pre>path: /storage/emulated/0/Android/data/package/files/Pictures</pre>
*
* @return 此应用在外置储存中的图片目录
*/
public static String getAppExtPicturesPath() {
return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_PICTURES)
.getAbsolutePath();
}
/**
* 获取此应用在外置储存中的 Podcasts 目录
* <pre>path: /storage/emulated/0/Android/data/package/files/Podcasts</pre>
*
* @return 此应用在外置储存中的 Podcasts 目录
*/
public static String getAppExtPodcastsPath() {
return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_PODCASTS)
.getAbsolutePath();
}
/**
* 获取此应用在外置储存中的铃声目录
* <pre>path: /storage/emulated/0/Android/data/package/files/Ringtones</pre>
*
* @return 此应用在外置储存中的铃声目录
*/
public static String getAppExtRingtonesPath() {
return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_RINGTONES)
.getAbsolutePath();
}
/**
* 获取此应用的 Obb 目录
* <pre>path: /storage/emulated/0/Android/obb/package</pre>
* <pre>一般用来存放游戏数据包</pre>
*
* @return 此应用的 Obb 目录
*/
public static String getObbPath() {
return Utils.getApp().getObbDir().getAbsolutePath();
}
public static String getFilePathByUri(Context context, Uri uri) {
String path = null;
// 以 file:// 开头的
if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
path = uri.getPath();
return path;
}
// 以 content:// 开头的,比如 content://media/extenral/images/media/17766
if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
Cursor cursor = context.getContentResolver().query(uri, new String[]{MediaStore.Images.Media.DATA}, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
if (columnIndex > -1) {
path = cursor.getString(columnIndex);
}
}
cursor.close();
}
return path;
}
// 4.4及之后的 是以 content:// 开头的,比如 content://com.android.providers.media.documents/document/image%3A235700
if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (DocumentsContract.isDocumentUri(context, uri)) {
if (isExternalStorageDocument(uri)) {
// ExternalStorageProvider
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
path = Environment.getExternalStorageDirectory() + "/" + split[1];
return path;
}
} else if (isDownloadsDocument(uri)) {
// DownloadsProvider
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
Long.valueOf(id));
path = getDataColumn(context, contentUri, null, null);
return path;
} else if (isMediaDocument(uri)) {
// MediaProvider
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[]{split[1]};
path = getDataColumn(context, contentUri, selection, selectionArgs);
return path;
}
}
}
return null;
}
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = {column};
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
final int column_index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(column_index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
private static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
private static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
private static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
}
此差异已折叠。
......@@ -2,7 +2,7 @@
Gradle:
```groovy
implementation 'com.blankj:utilcode:1.19.4'
implementation 'com.blankj:utilcode:1.20.0'
```
......@@ -350,8 +350,10 @@ getCaptureIntent : 获取拍照的意图
* ### 键盘相关 -> [KeyboardUtils.java][keyboard.java] -> [Demo][keyboard.demo]
```
showSoftInput : 动态显示软键盘
hideSoftInput : 动态隐藏软键盘
showSoftInput : 显示软键盘
showSoftInputUsingToggle : 显示软键盘用 toggle
hideSoftInput : 隐藏软键盘
hideSoftInputUsingToggle : 隐藏软键盘用 toggle
toggleSoftInput : 切换键盘显示与否状态
isSoftInputVisible : 判断软键盘是否可见
registerSoftInputChangedListener : 注册软键盘改变监听器
......@@ -397,6 +399,14 @@ json : log 字符串之 json
xml : log 字符串之 xml
```
* ### MetaData 相关 -> [MetaDataUtils.java][meta_data.java] -> [Demo][meta_data.demo]
```
getMetaDataInApp : 获取 application 的 meta-data 值
getMetaDataInActivity: 获取 activity 的 meta-data 值
getMetaDataInService : 获取 service 的 meta-data 值
getMetaDataInReceiver: 获取 receiver 的 meta-data 值
```
* ### 网络相关 -> [NetworkUtils.java][network.java] -> [Demo][network.demo]
```
openWirelessSettings : 打开网络设置界面
......@@ -808,6 +818,9 @@ getComments : 获取压缩文件中的注释链表
[log.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/LogUtils.java
[log.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/core/log/LogActivity.java
[meta_data.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/MetaDataUtils.java
[meta_data.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/core/meta_data/MetaDataActivity.java
[network.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/NetworkUtils.java
[network.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/core/network/NetworkActivity.java
......
......@@ -2,7 +2,7 @@
Gradle:
```groovy
implementation 'com.blankj:utilcode:1.19.4'
implementation 'com.blankj:utilcode:1.20.0'
```
......@@ -351,7 +351,9 @@ getCaptureIntent
* ### About Keyboard -> [KeyboardUtils.java][keyboard.java] -> [Demo][keyboard.demo]
```
showSoftInput
showSoftInputUsingToggle
hideSoftInput
hideSoftInputUsingToggle
toggleSoftInput
isSoftInputVisible
registerSoftInputChangedListener
......@@ -397,6 +399,14 @@ json
xml
```
* ### About MetaData -> [MetaDataUtils.java][meta_data.java] -> [Demo][meta_data.demo]
```
getMetaDataInApp
getMetaDataInActivity
getMetaDataInService
getMetaDataInReceiver
```
* ### About Network -> [NetworkUtils.java][network.java] -> [Demo][network.demo]
```
openWirelessSettings
......@@ -808,6 +818,9 @@ getComments
[log.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/LogUtils.java
[log.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/core/log/LogActivity.java
[meta_data.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/MetaDataUtils.java
[meta_data.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/core/meta_data/MetaDataActivity.java
[network.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/NetworkUtils.java
[network.demo]: https://github.com/Blankj/AndroidUtilCode/blob/master/app/src/main/java/com/blankj/androidutilcode/feature/core/network/NetworkActivity.java
......
......@@ -608,7 +608,7 @@ public final class BarUtils {
* Set the navigation bar's visibility.
*
* @param activity The activity.
* @param isVisible True to set notification bar visible, false otherwise.
* @param isVisible True to set navigation bar visible, false otherwise.
*/
public static void setNavBarVisibility(@NonNull final Activity activity, boolean isVisible) {
setNavBarVisibility(activity.getWindow(), isVisible);
......@@ -618,7 +618,7 @@ public final class BarUtils {
* Set the navigation bar's visibility.
*
* @param window The window.
* @param isVisible True to set notification bar visible, false otherwise.
* @param isVisible True to set navigation bar visible, false otherwise.
*/
public static void setNavBarVisibility(@NonNull final Window window, boolean isVisible) {
if (isVisible) {
......
......@@ -3,6 +3,7 @@ package com.blankj.utilcode.util;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Build;
import android.util.Log;
......@@ -24,7 +25,7 @@ import java.lang.reflect.Field;
*/
public final class KeyboardUtils {
private static int sContentViewInvisibleHeightPre;
private static int sDecorViewInvisibleHeightPre;
private static OnGlobalLayoutListener onGlobalLayoutListener;
private static OnSoftInputChangedListener onSoftInputChangedListener;
private static int sContentViewInvisibleHeightPre5497;
......@@ -67,6 +68,16 @@ public final class KeyboardUtils {
imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
}
/**
* Show the soft input using toggle.
*
* @param activity The activity.
*/
public static void showSoftInputUsingToggle(final Activity activity) {
if (isSoftInputVisible(activity)) return;
toggleSoftInput();
}
/**
* Hide the soft input.
*
......@@ -93,6 +104,16 @@ public final class KeyboardUtils {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
/**
* Hide the soft input.
*
* @param activity The activity.
*/
public static void hideSoftInputUsingToggle(final Activity activity) {
if (!isSoftInputVisible(activity)) return;
toggleSoftInput();
}
/**
* Toggle the soft input display or not.
*/
......@@ -105,35 +126,28 @@ public final class KeyboardUtils {
/**
* Return whether soft input is visible.
* <p>The minimum height is 200</p>
*
* @param activity The activity.
* @return {@code true}: yes<br>{@code false}: no
*/
public static boolean isSoftInputVisible(final Activity activity) {
return isSoftInputVisible(activity, 200);
return getDecorViewInvisibleHeight(activity) > 0;
}
/**
* Return whether soft input is visible.
*
* @param activity The activity.
* @param minHeightOfSoftInput The minimum height of soft input.
* @return {@code true}: yes<br>{@code false}: no
*/
public static boolean isSoftInputVisible(final Activity activity,
final int minHeightOfSoftInput) {
return getContentViewInvisibleHeight(activity) >= minHeightOfSoftInput;
}
private static int sDelta = 0;
private static int getContentViewInvisibleHeight(final Activity activity) {
final FrameLayout contentView = activity.findViewById(android.R.id.content);
final View contentViewChild = contentView.getChildAt(0);
private static int getDecorViewInvisibleHeight(final Activity activity) {
final View decorView = activity.getWindow().getDecorView();
final Rect outRect = new Rect();
contentViewChild.getWindowVisibleDisplayFrame(outRect);
Log.d("KeyboardUtils", "getContentViewInvisibleHeight: "
+ (contentViewChild.getBottom() - outRect.bottom));
return contentViewChild.getBottom() - outRect.bottom;
decorView.getWindowVisibleDisplayFrame(outRect);
LogUtils.d("KeyboardUtils", "getDecorViewInvisibleHeight: "
+ (decorView.getBottom() - outRect.bottom));
int delta = Math.abs(decorView.getBottom() - outRect.bottom);
if (delta <= getNavBarHeight()) {
sDelta = delta;
return 0;
}
return delta - sDelta;
}
/**
......@@ -149,16 +163,16 @@ public final class KeyboardUtils {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
final FrameLayout contentView = activity.findViewById(android.R.id.content);
sContentViewInvisibleHeightPre = getContentViewInvisibleHeight(activity);
sDecorViewInvisibleHeightPre = getDecorViewInvisibleHeight(activity);
onSoftInputChangedListener = listener;
onGlobalLayoutListener = new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (onSoftInputChangedListener != null) {
int height = getContentViewInvisibleHeight(activity);
if (sContentViewInvisibleHeightPre != height) {
int height = getDecorViewInvisibleHeight(activity);
if (sDecorViewInvisibleHeightPre != height) {
onSoftInputChangedListener.onSoftInputChanged(height);
sContentViewInvisibleHeightPre = height;
sDecorViewInvisibleHeightPre = height;
}
}
}
......@@ -168,7 +182,7 @@ public final class KeyboardUtils {
}
/**
* Register soft input changed listener.
* Unregister soft input changed listener.
*
* @param activity The activity.
*/
......@@ -186,10 +200,6 @@ public final class KeyboardUtils {
* @param activity The activity.
*/
public static void fixAndroidBug5497(final Activity activity) {
final int flags = activity.getWindow().getAttributes().flags;
if ((flags & WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) != 0) {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
final FrameLayout contentView = activity.findViewById(android.R.id.content);
final View contentViewChild = contentView.getChildAt(0);
final int paddingBottom = contentViewChild.getPaddingBottom();
......@@ -212,6 +222,19 @@ public final class KeyboardUtils {
});
}
private static int getContentViewInvisibleHeight(final Activity activity) {
final FrameLayout contentView = activity.findViewById(android.R.id.content);
final Rect outRect = new Rect();
contentView.getWindowVisibleDisplayFrame(outRect);
LogUtils.d("KeyboardUtils", "getContentViewInvisibleHeight: "
+ (contentView.getBottom() - outRect.bottom));
int delta = Math.abs(contentView.getBottom() - outRect.bottom);
if (delta <= getStatusBarHeight()) {
return 0;
}
return delta;
}
/**
* Fix the leaks of soft input.
* <p>Call the function in {@link Activity#onDestroy()}.</p>
......@@ -284,6 +307,22 @@ public final class KeyboardUtils {
*/
}
private static int getStatusBarHeight() {
Resources resources = Resources.getSystem();
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
return resources.getDimensionPixelSize(resourceId);
}
private static int getNavBarHeight() {
Resources res = Resources.getSystem();
int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId != 0) {
return res.getDimensionPixelSize(resourceId);
} else {
return 0;
}
}
///////////////////////////////////////////////////////////////////////////
// interface
///////////////////////////////////////////////////////////////////////////
......
package com.blankj.subutil.util;
package com.blankj.utilcode.util;
import android.app.Activity;
import android.app.Service;
......@@ -15,7 +15,7 @@ import android.support.annotation.NonNull;
* author: Blankj
* blog : http://blankj.com
* time : 2018/05/15
* desc :
* desc : utils about meta-data
* </pre>
*/
public final class MetaDataUtils {
......
//package com.blankj.utilcode.util;
//
//import android.os.Build;
//import android.os.Environment;
//import android.support.annotation.RequiresApi;
//
///**
// * <pre>
// * author: Blankj
// * blog : http://blankj.com
// * time : 2018/04/15
// * desc : utils about path
// * </pre>
// */
//public class PathUtils {
//
// private PathUtils() {
// throw new UnsupportedOperationException("u can't instantiate me...");
// }
//
// /**
// * Return the path of /system.
// *
// * @return the path of /system
// */
// public static String getRootPath() {
// return Environment.getRootDirectory().getAbsolutePath();
// }
//
// /**
// * Return the path of /data.
// *
// * @return the path of /data
// */
// public static String getDataPath() {
// return Environment.getDataDirectory().getAbsolutePath();
// }
//
// /**
// * Return the path of download/cache.
// *
// * @return the path of download/cache
// */
// public static String getInternalDownloadCachePath() {
// return Environment.getDownloadCacheDirectory().getAbsolutePath();
// }
//
// /**
// * Return the path of /data/data/package/cache.
// *
// * @return the path of /data/data/package/cache
// */
// public static String getInternalAppCachePath() {
// return Utils.getApp().getCacheDir().getAbsolutePath();
// }
//
// /**
// * Return the path of /data/data/package/files.
// *
// * @return the path of /data/data/package/files
// */
// public static String getInternalAppFilesPath() {
// return Utils.getApp().getFilesDir().getAbsolutePath();
// }
//
// /**
// * Return the path of /data/data/package/databases/name.
// *
// * @param name The name of database.
// * @return the path of /data/data/package/databases/name
// */
// public static String getInternalAppDbPath(String name) {
// return Utils.getApp().getDatabasePath(name).getAbsolutePath();
// }
//
// /**
// * Return the path of /storage/emulated/0.
// *
// * @return the path of /storage/emulated/0
// */
// public static String getExternalStoragePath() {
// return Environment.getExternalStorageDirectory().getAbsolutePath();
// }
//
// /**
// * Return the path of /storage/emulated/0/Alarms.
// *
// * @return the path of /storage/emulated/0/Alarms
// */
// public static String getExternalAlarmsPath() {
// return Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS)
// .getAbsolutePath();
// }
//
// /**
// * Return the path of /storage/emulated/0/DCIM.
// *
// * @return the path of /storage/emulated/0/DCIM
// */
// public static String getExternalDcimPath() {
// return Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
// .getAbsolutePath();
// }
//
// /**
// * Return the path of /storage/emulated/0/Documents.
// *
// * @return the path of /storage/emulated/0/Documents
// */
// @RequiresApi(api = Build.VERSION_CODES.KITKAT)
// public static String getExternalDocumentsPath() {
// return Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)
// .getAbsolutePath();
// }
//
// /**
// * Return the path of /storage/emulated/0/Download.
// *
// * @return the path of /storage/emulated/0/Download
// */
// public static String getExtDownloadsPath() {
// return Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
// .getAbsolutePath();
// }
//
// /**
// * 获取视频目录
// * <pre>path: /storage/emulated/0/Movies</pre>
// *
// * @return 视频目录
// */
// public static String getExtMoviesPath() {
// return Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
// .getAbsolutePath();
// }
//
// /**
// * 获取音乐目录
// * <pre>path: /storage/emulated/0/Music</pre>
// *
// * @return 音乐目录
// */
// public static String getExtMusicPath() {
// return Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
// .getAbsolutePath();
// }
//
// /**
// * 获取提示音目录
// * <pre>path: /storage/emulated/0/Notifications</pre>
// *
// * @return 提示音目录
// */
// public static String getExtNotificationsPath() {
// return Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS)
// .getAbsolutePath();
// }
//
// /**
// * 获取图片目录
// * <pre>path: /storage/emulated/0/Pictures</pre>
// *
// * @return 图片目录
// */
// public static String getExtPicturesPath() {
// return Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
// .getAbsolutePath();
// }
//
// /**
// * 获取 Podcasts 目录
// * <pre>path: /storage/emulated/0/Podcasts</pre>
// *
// * @return Podcasts 目录
// */
// public static String getExtPodcastsPath() {
// return Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS)
// .getAbsolutePath();
// }
//
// /**
// * 获取铃声目录
// * <pre>path: /storage/emulated/0/Ringtones</pre>
// *
// * @return 下载目录
// */
// public static String getExtRingtonesPath() {
// return Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的缓存目录
// * <pre>path: /storage/emulated/0/Android/data/package/cache</pre>
// *
// * @return 此应用在外置储存中的缓存目录
// */
// public static String getAppExtCachePath() {
// return Utils.getApp().getExternalCacheDir().getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的文件目录
// * <pre>path: /storage/emulated/0/Android/data/package/files</pre>
// *
// * @return 此应用在外置储存中的文件目录
// */
// public static String getAppExtFilePath() {
// return Utils.getApp().getExternalFilesDir(null).getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的闹钟铃声目录
// * <pre>path: /storage/emulated/0/Android/data/package/files/Alarms</pre>
// *
// * @return 此应用在外置储存中的闹钟铃声目录
// */
// public static String getAppExtAlarmsPath() {
// return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_ALARMS)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的相机目录
// * <pre>path: /storage/emulated/0/Android/data/package/files/DCIM</pre>
// *
// * @return 此应用在外置储存中的相机目录
// */
// public static String getAppExtDcimPath() {
// return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_DCIM)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的文档目录
// * <pre>path: /storage/emulated/0/Android/data/package/files/Documents</pre>
// *
// * @return 此应用在外置储存中的文档目录
// */
// @RequiresApi(api = Build.VERSION_CODES.KITKAT)
// public static String getAppExtDocumentsPath() {
// return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的闹钟目录
// * <pre>path: /storage/emulated/0/Android/data/package/files/Download</pre>
// *
// * @return 此应用在外置储存中的闹钟目录
// */
// public static String getAppExtDownloadPath() {
// return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的视频目录
// * <pre>path: /storage/emulated/0/Android/data/package/files/Movies</pre>
// *
// * @return 此应用在外置储存中的视频目录
// */
// public static String getAppExtMoviesPath() {
// return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_MOVIES)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的音乐目录
// * <pre>path: /storage/emulated/0/Android/data/package/files/Music</pre>
// *
// * @return 此应用在外置储存中的音乐目录
// */
// public static String getAppExtMusicPath() {
// return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_MUSIC)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的提示音目录
// * <pre>path: /storage/emulated/0/Android/data/package/files/Notifications</pre>
// *
// * @return 此应用在外置储存中的提示音目录
// */
// public static String getAppExtNotificationsPath() {
// return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_NOTIFICATIONS)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的图片目录
// * <pre>path: /storage/emulated/0/Android/data/package/files/Pictures</pre>
// *
// * @return 此应用在外置储存中的图片目录
// */
// public static String getAppExtPicturesPath() {
// return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_PICTURES)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的 Podcasts 目录
// * <pre>path: /storage/emulated/0/Android/data/package/files/Podcasts</pre>
// *
// * @return 此应用在外置储存中的 Podcasts 目录
// */
// public static String getAppExtPodcastsPath() {
// return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_PODCASTS)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用在外置储存中的铃声目录
// * <pre>path: /storage/emulated/0/Android/data/package/files/Ringtones</pre>
// *
// * @return 此应用在外置储存中的铃声目录
// */
// public static String getAppExtRingtonesPath() {
// return Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_RINGTONES)
// .getAbsolutePath();
// }
//
// /**
// * 获取此应用的 Obb 目录
// * <pre>path: /storage/emulated/0/Android/obb/package</pre>
// * <pre>一般用来存放游戏数据包</pre>
// *
// * @return 此应用的 Obb 目录
// */
// public static String getObbPath() {
// return Utils.getApp().getObbDir().getAbsolutePath();
// }
//}
......@@ -67,7 +67,9 @@ public final class SDCardUtils {
(StorageManager) Utils.getApp().getSystemService(Context.STORAGE_SERVICE);
try {
Class<?> storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
//noinspection JavaReflectionMemberAccess
Method getVolumeList = StorageManager.class.getMethod("getVolumeList");
//noinspection JavaReflectionMemberAccess
Method getPath = storageVolumeClazz.getMethod("getPath");
Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
Object result = getVolumeList.invoke(sm);
......@@ -102,6 +104,7 @@ public final class SDCardUtils {
.getSystemService(Context.STORAGE_SERVICE);
List<String> paths = new ArrayList<>();
try {
//noinspection JavaReflectionMemberAccess
Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths");
getVolumePathsMethod.setAccessible(true);
Object invoke = getVolumePathsMethod.invoke(storageManager);
......
package com.blankj.utilcode.util;
import android.content.ContentResolver;
import android.content.CursorLoader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.content.FileProvider;
import java.io.File;
......@@ -29,8 +31,7 @@ public final class UriUtils {
* @param file The file.
* @return uri
*/
public static Uri file2Uri(final File file) {
if (file == null) return null;
public static Uri file2Uri(@NonNull final File file) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
String authority = Utils.getApp().getPackageName() + ".utilcode.provider";
return FileProvider.getUriForFile(Utils.getApp(), authority, file);
......@@ -47,14 +48,23 @@ public final class UriUtils {
* <p>e.g. {@link MediaStore.Images.Media#DATA}</p>
* @return file
*/
public static File uri2File(final Uri uri, final String columnName) {
if (uri == null) return null;
public static File uri2File(@NonNull final Uri uri, final String columnName) {
if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
return new File(uri.getPath());
}
CursorLoader cl = new CursorLoader(Utils.getApp());
cl.setUri(uri);
cl.setProjection(new String[]{columnName});
Cursor cursor = cl.loadInBackground();
int columnIndex = cursor.getColumnIndexOrThrow(columnName);
cursor.moveToFirst();
return new File(cursor.getString(columnIndex));
Cursor cursor = null;
try {
cursor = cl.loadInBackground();
int columnIndex = cursor.getColumnIndexOrThrow(columnName);
cursor.moveToFirst();
return new File(cursor.getString(columnIndex));
} finally {
if (cursor != null) {
cursor.close();
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册