Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢

Rahul Mandaliya imandaliya

🐢
View GitHub Profile
View Open your app in play store directly
// packageName = your application package name
fun Context.openInPlayStore() {
val playStoreApp = String.format("market://details?id=%", packageName)
val playStoreUrl = String.format("https://play.google.com/store/apps/details?id=%", packageName)
val playStoragePackage = "com.android.vending"
try {
if (appInstalledOrNot(playStoragePackage)) {
packageManager.getLaunchIntentForPackage(playStoragePackage)?.let { intent ->
intent.action = Intent.ACTION_VIEW
intent.data = Uri.parse(playStoreApp)
View Create or Upload native debug symbols
// Add debugSymbolLevel line in your main app project gradle.build
debug {
ndk.debugSymbolLevel = "FULL" // /build/intermediates/merged_native_libs path of the native debug build files
}
View Calculate File Size in KB or MB
fun Uri.calculateFileSizeInMB(context: Context): String? {
val cursor: Cursor? = context.contentResolver.query(this, null, null, null, null)
if (cursor != null) {
cursor.moveToFirst()
val sizeIndex: Int = cursor.getColumnIndex(OpenableColumns.SIZE)
val imageSize: Float = cursor.getLong(sizeIndex).toFloat()
cursor.close()
if (imageSize < 1024) {
View Calculate Image Dimen in Width only
fun Uri.calculateImageDimens(context: Context): String? {
try {
context.contentResolver.openInputStream(this)?.let {
val exif = ExifInterface(it)
val width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, -1)
if (width > 0) return "$width x $width"
}
context.contentResolver.openFileDescriptor(this, "r")?.let { fd ->
val options: BitmapFactory.Options = BitmapFactory.Options()
View Save Bitmap to Image on android 11
private fun saveImageToStorage() {
try {
val uri: Uri?
val fileName = "Screenshot_${Calendar.getInstance().time}.jpg"
val imageOutStream: OutputStream? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val values = ContentValues()
values.put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
values.put(MediaStore.Images.Media.MIME_TYPE, "image/*")
values.put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES)
uri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
View Save Documents on android 11
// original link : https://androidexplained.github.io/android/android11/scoped-storage/2020/09/29/file-saving-android-11.html
private fun openDocumentToSavePDF() {
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/pdf"
val fileName = "Screenshot_${Calendar.getInstance().time}.pdf"
putExtra(Intent.EXTRA_TITLE, fileName)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
putExtra(DocumentsContract.EXTRA_INITIAL_URI, Environment.DIRECTORY_DOCUMENTS)
View FilePath.java
// Get external storage public directory file path
// original thread https://stackoverflow.com/questions/61406818/filenotfoundexception-open-failed-eperm-operation-not-permitted-during-saving
ContextWrapper cw = new ContextWrapper(mContext);
String fullPath = cw.getExternalFilesDir(Environment.DIRECTORY_MUSIC).toString();
File directory = cw.getExternalFilesDir(Environment.DIRECTORY_MUSIC);
@imandaliya
imandaliya / gist:8f8374986316b1d8401e74bc2dd9de19
Created Aug 8, 2020
The application could not be installed: INSTALL_FAILED_NO_MATCHING_ABIS in RenderScript
View gist:8f8374986316b1d8401e74bc2dd9de19
// add this line in defaultConfig
ndk {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a' , 'arm64-v8a'
}
View RoundedImageView.java
package com.rahul.android.material.support.views;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
View TransparentBar
public void setThemeTransparentBar(AppCompatActivity activity, AppBarLayout appBarLayout, Toolbar toolbar, RecyclerView recyclerView) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (appBarLayout == null || toolbar == null || recyclerView == null) return;
int color = ContextCompat.getColor(activity.getApplicationContext(), R.color.bar_transparent);
appBarLayout.setBackgroundColor(color);
toolbar.setBackgroundColor(Color.TRANSPARENT);