Updated on 2026-08-14
This commit is contained in:
parent
93c85e4ce9
commit
035a084339
7 changed files with 47 additions and 16 deletions
|
|
@ -1,7 +1,11 @@
|
|||
package com.tangem.tap.common.extensions
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import androidx.annotation.AnyRes
|
||||
import androidx.core.content.ContextCompat
|
||||
|
||||
fun Context.readFile(fileName: String): String =
|
||||
|
|
@ -19,4 +23,20 @@ fun Context.readAssetAsString(fileName: String): String {
|
|||
|
||||
fun Context.isPermissionGranted(permission: String): Boolean {
|
||||
return ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
||||
/**
|
||||
* Get uri to any resource type via given Resource Instance
|
||||
* @param resId - resource id
|
||||
* @throws Resources.NotFoundException if the given ID does not exist.
|
||||
* @return - Uri to resource by the given ID
|
||||
*/
|
||||
@Throws(Resources.NotFoundException::class)
|
||||
fun Context.resourceUri(@AnyRes resId: Int): Uri {
|
||||
return Uri.parse(
|
||||
ContentResolver.SCHEME_ANDROID_RESOURCE +
|
||||
"://" + resources.getResourcePackageName(resId)
|
||||
+ '/' + resources.getResourceTypeName(resId)
|
||||
+ '/' + resources.getResourceEntryName(resId),
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue