Skip to content

Instantly share code, notes, and snippets.

View Puneet1796's full-sized avatar
🏠
Working from home

Puneet Verma Puneet1796

🏠
Working from home
View GitHub Profile
// This extension function will get the value from LiveData.
// It should be used in testing.
// For Queries returning values wrapped around LiveData.
@Throws(InterruptedException::class)
fun <T> LiveData<T>.getValueBlocking(): T? {
var value: T? = null
val latch = CountDownLatch(1)
val innerObserver = Observer<T> {
value = it
latch.countDown()
@tatocaster
tatocaster / RealPathUtil.java
Last active April 3, 2024 00:27
Real Path Utility class for Android, works for all API
public class RealPathUtil {
public static String getRealPath(Context context, Uri fileUri) {
String realPath;
// SDK < API11
if (Build.VERSION.SDK_INT < 11) {
realPath = RealPathUtil.getRealPathFromURI_BelowAPI11(context, fileUri);
}
// SDK >= 11 && SDK < 19
else if (Build.VERSION.SDK_INT < 19) {