基于boxing的AndroidQ适配
iDeMonnnnnn 2021-01-14 23:38 收藏
Qboxing - 基于boxing的AndroidQ适配
相较于boxing:
1. 兼容AndroidQ
2. 适配AndroidX
3. 100%的Kotlin代码
开始使用
添加依赖
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.iDeMonnnnnn:Qboxing:$latest_version'
}
添加权限
注意申请运行时权限。
<!--如果你使用相机相关功能必须要添加,否则可忽略-->
<uses-permission android:name="android.permission.CAMERA" />
<!--存储权限在低于AndroidQ的手机上还是需要的-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
如何使用
1.初始化
使用前,必须调用此方法初始化。
//初始化,提供一个全局的Context
Boxing.init(this)
2.FileProvider
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.file.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
3.获取图片路径
使用newPath代替path,兼容了AndroidQ无法直接通过文件路径获取非作用域文件的问题。
media.path ---> media.newPath
4.更多
使用效果
其他
如果你有问题或者建议,请Issues.
致谢
MIT License
Copyright (c) 2021 DeMon
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.