Skip to content

Instantly share code, notes, and snippets.

View saurabhkpatel's full-sized avatar
🎯
Focusing

Saurabh Patel saurabhkpatel

🎯
Focusing
View GitHub Profile
@saurabhkpatel
saurabhkpatel / printActivityFlags.java
Last active May 6, 2024 10:43
[Android] : Print Activity Flags, it will be useful for the debug.
public static void printActivityFlags(String activityName, Intent intent) {
Field[] declaredFields = Intent.class.getDeclaredFields();
StringBuilder stringBuilder = new StringBuilder(activityName + " => ");
for (Field field : declaredFields) {
if (field.getName().startsWith("FLAG_")) { // Fetch all the flag names which start from "FLAG_"
try {
int flag = field.getInt(null);
if ((intent.getFlags() | flag) == intent.getFlags()) { // checking that flag is present or not.
stringBuilder.append(field.getName());
stringBuilder.append("|");
@saurabhkpatel
saurabhkpatel / MoveDirectoryContents.java
Last active April 30, 2021 03:14
Move Directory contents : Android/Java
/**
* This utility method moves contents from sourceDirectory to destinationDirectory
*
* @param sourceDirectory : from where to get contents
* @param destinationDirectory : where to move contents
* @return true if success, false otherwise.
*/
public static boolean moveDirectoryContents(@NonNull File sourceDirectory, @NonNull File destinationDirectory) {
if (!sourceDirectory.exists()) {
return false;
@saurabhkpatel
saurabhkpatel / dynamic_feature_module_androidmanifest.txt
Last active May 24, 2018 06:35
dynamic feature module Manifest file.
<manifest package="com.saurabh.dynamic_feature"
<!--split tag : declare your module as a new split apk of your application-->
split="custom_dynamic_feature"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution">
<!--split dist:module : define module attributes/configs-->
<dist:module
dist:onDemand="true"
dist:title="@string/title_dynamic_feature">
// new plugin
apply plugin: 'com.android.dynamic-feature'
android {
...
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// add main/base module's dependency
// In the base module’s build.gradle file.
android {
// Specifies dynamic feature modules that have a dependency on this base module.
dynamicFeatures = [':features:kotlin',
':features:java',
':features:native',
':features:assets',
":dynamic_feature"]
}
android.buildTypes {
release {
// You must use the following property to specify additional ProGuard
// rules for dynamic feature modules.
consumerProguardFiles 'proguard-rules-dynamic-features.pro'
}
}
private fun createSliceWithHeaderAndRow(sliceUri: Uri): Slice? {
return list(context, sliceUri, ListBuilder.INFINITY) {
header {
title = "Get a ride."
subtitle = "Ride in 4 min."
summary = "Work in 45 min | Home in 15 min."
}
row {
title = "Home"
subtitle = "15 miles | 15 min | $15.23"