Skip to content

Instantly share code, notes, and snippets.

View AbreuY's full-sized avatar
🎯
Focusing

AbreuY

🎯
Focusing
  • 127.0.0.1
View GitHub Profile
@AbreuY
AbreuY / CurrentVersionCode.java
Created August 15, 2020 19:40
Get current version code in android app
static int getCurrentVersionCode(Activity activity) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return (int) activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).getLongVersionCode();
} else {
//noinspection deprecation
return activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionCode;
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, e.toString());
@AbreuY
AbreuY / markdown-text-101.md
Created July 29, 2020 01:38 — forked from matthewzring/markdown-text-101.md
A guide to Markdown on Discord.

Markdown Text 101

Want to inject some flavor into your everyday text chat? You're in luck! Discord uses Markdown, a simple plain text formatting system that'll help you make your sentences stand out. Here's how to do it! Just add a few characters before & after your desired text to change your text! I'll show you some examples...

Sweet Styles

Italics *italics* or _italics_

Underline italics __*underline italics*__

public static String[] getStorageDirectories() {
final Pattern DIR_SEPARATOR = Pattern.compile("/");
// Final set of paths
final Set<String> rv = new HashSet<String>();
// Primary physical SD-CARD (not emulated)
final String rawExternalStorage = System.getenv("EXTERNAL_STORAGE");
// All Secondary SD-CARDs (all exclude primary) separated by ":"
final String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE");
// Primary emulated SD-CARD
@AbreuY
AbreuY / IntentExtensions.kt
Created June 8, 2020 03:48 — forked from MeNiks/RealPathUtil.kt
Kotlin code to get real path / sd card path from intent data while browsing file.
// Extension on intent
fun Intent?.getFilePath(context: Context): String {
return this?.data?.let { data -> RealPathUtil.getRealPath(context, data) ?: "" } ?: ""
}
fun Uri?.getFilePath(context: Context): String {
return this?.let { uri -> RealPathUtil.getRealPath(context, uri) ?: "" } ?: ""
}
@AbreuY
AbreuY / Util.java
Created April 11, 2020 10:05
[Solución] Android 8.0 Only fullscreen opaque activities can request orientation
@SuppressLint("SourceLockedOrientationActivity")
public static void chequeaVersion(Activity activity){
//Verifica si es diferente de android O
if (android.os.Build.VERSION.SDK_INT != Build.VERSION_CODES.O){
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Log.d("TAG", "No es android O");
}else{
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Log.d("TAG", "Es android O");
}
@AbreuY
AbreuY / GetExternalSdCardPath.java
Created March 6, 2019 03:28 — forked from PauloLuan/GetExternalSdCardPath.java
how to get the external sd card path on android.
public static String getExternalSdCardPath() {
String path = null;
File sdCardFile = null;
List<String> sdCardPossiblePath = Arrays.asList("external_sd", "ext_sd", "external", "extSdCard");
for (String sdPath : sdCardPossiblePath) {
File file = new File("/mnt/", sdPath);
if (file.isDirectory() && file.canWrite()) {
@AbreuY
AbreuY / EachDirectoryPath.md
Created March 6, 2019 01:26 — forked from granoeste/EachDirectoryPath.md
[Android] How to get the each directory path.

System directories

Method Result
Environment.getDataDirectory() /data
Environment.getDownloadCacheDirectory() /cache
Environment.getRootDirectory() /system

External storage directories

@AbreuY
AbreuY / SdcardFolder.java
Created March 6, 2019 01:23 — forked from jerolimov/SdcardFolder.java
Load Android SDCard Folder for different devices (Android Standard, Samsung Galaxy S, HTC Incredible)
private String getSdcardFolder() {
File externalStorage = Environment.getExternalStorageDirectory();
if (externalStorage.exists() && externalStorage.canWrite()) {
File trySubDir1 = new File(externalStorage, "external_sd");
File trySubDir2 = new File(externalStorage, "sd");
if (trySubDir1.exists() && trySubDir1.canWrite()) {
return trySubDir1.getAbsolutePath();
} else if (trySubDir2.exists() && trySubDir2.canWrite()) {
return trySubDir2.getAbsolutePath();
} else {
@AbreuY
AbreuY / StorageHelper.java
Created March 6, 2019 01:22 — forked from maxlord/StorageHelper.java
Получение пути к флешке Android
String sdCardPath = null;
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
sdCardPath = Environment.getExternalStorageDirectory().getAbsolutePath();
} else {
List<String> possiblePaths = new ArrayList<String>();
possiblePaths.add("/storage/sdcard1 "); //!< Motorola Xoom
possiblePaths.add("/storage/extsdcard "); //!< Samsung SGS3
possiblePaths.add("/storage/sdcard0/external_sdcard"); // user request
possiblePaths.add("/mnt/extsdcard");
@AbreuY
AbreuY / EqualSpacingItemDecoration.java
Created February 3, 2019 04:44 — forked from alexfu/EqualSpacingItemDecoration.java
Add equal spacing to RecyclerView items automatically. Can handle horizontal, vertical, and grid display modes
import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class EqualSpacingItemDecoration extends RecyclerView.ItemDecoration {
private final int spacing;
private int displayMode;
public static final int HORIZONTAL = 0;