Skip to content

Android

Are you ready to step into the heart of a global Android revolution, where millions of users and developers collaborate to improve the open source mobile operating system, giving you endless possibilities to customize your device and operating system. Unleash your creativity and make your smartphone, tablet, or smartwatch truly your own with the endless array of apps and features available on Android, tailored to fit your unique needs and preferences. Our job at KBVE will be to provide you with everything you need to deploy your own Android application on almost any device!

This one page guide is meant to serve as your resource manual moving forward, we will start with the cheat sheet below, that makes it easy to reference back in the future.

The ADB cheat sheet is an essential resource for navigating and managing Android operating systems and applications via the Android Debug Bridge (ADB). It offers a comprehensive list of basic commands that facilitate various tasks such as installing apps, debugging issues, and accessing device logs. While the cheat sheet covers a wide range of functionalities, it’s important to note that some commands require root access, and certain Android versions may necessitate specific tweaks to the standard commands. This makes the cheat sheet a versatile and indispensable tool for both novice users and experienced developers working with Android devices.

Android ADB Device commands are commands that you can use to control the Android device over USB from a computer. You can use them to list all devices, restart the ADB server, and reboot connected devices.

CommandDescriptionNotes / Variants
adb devicesList all connected devices.
adb devices -lQuery additional information (model, product, transport ID).Useful for identifying multiple devices.
adb get-stateDisplay the current device state (device, offline, or unauthorized).
adb get-serialnoQuery the device’s serial number.
adb rootLaunch the ADB daemon (adbd) with root permissions.May fail on production builds: adbd cannot run as root in production builds.
adb start-serverStart the ADB server daemon.Runs automatically if missing when using other ADB commands.
adb kill-serverTerminate the ADB server process.Use to restart ADB cleanly if it becomes unresponsive.
adb rebootReboot the currently connected device.Accepts optional args like bootloader or recovery.
adb helpDisplay general help and usage information.Lists all supported subcommands.

ADB shell is a command-line interface that you can use to access the shell and run various commands on your Android device. You can use ADB shell commands to perform actions such as changing the resolution of your device display, uninstalling bloatware or system apps, enabling and disabling features, modifying the system files, ect..

CommandDescriptionNotes / Variants
adb shellLaunch the interactive shell terminal on the connected device.Equivalent to opening a remote terminal session.
adb -s $deviceString $deviceCommandSend a command ($deviceCommand) to a specific device identified by $deviceString.Useful when multiple devices are connected.
adb shell pwdPrint the current working directory on the device.
adb shell lsList the contents of the current directory.
adb shell ls -sList directory contents with file size information.
adb shell ls -RRecursively list contents of all subdirectories.
adb shell netstatDisplay current TCP/IP network connections.Useful for debugging sockets and ports.
adb shell dumpsysDump system service information and status reports.A powerful diagnostic tool for system introspection.
adb shell dumpsys iphonesybinfoRetrieve IMEI and related telephony information.Typo in some Android versions — should be iphonesubinfo.
adb shell dumpsys batteryDisplay current battery status and related data.
adb shell dumpsys battery set level $vManually set battery level from 0 to 100.Useful for testing low-power states.
adb shell dumpsys battery resetReset battery state to default (real readings).
adb shell dumpsys activity $packageDump activity information for a specific package.
adb shell pm list featuresList available hardware and software features.
adb shell service listList all registered Android system services.Often used before running targeted dumpsys queries.
adb shell wmBase command for WindowManager operations.Placeholder — requires subcommands.
adb shell wm sizeShow the current screen resolution.
adb shell wm size $WxHSet custom screen resolution (e.g., 1080x1920).
adb shell wm size resetReset screen resolution to default.
adb shell wm densityShow the current display density (DPI).
adb shell wm density resetReset display density to system default.
adb shell psList all running processes on the device.Similar to Linux ps command.
exitExit the current ADB shell session.Returns to the host terminal.

Android Key Events - A quick breakdown for each event and how the operating system handles them.

Generic Android Keyevents:

Terminal window
adb shell input keyevent
KeycodeCommand ExampleDescription
0adb shell input keyevent 0Keycode 0
1adb shell input keyevent 1Soft Left
2adb shell input keyevent 2Soft Right
3adb shell input keyevent 3Home Button Event
4adb shell input keyevent 4Back Button Event
5adb shell input keyevent 5Call Event
6adb shell input keyevent 6End Call / Hangup Event
7adb shell input keyevent 7Keycode 0
8adb shell input keyevent 8Keycode 1 — Number 1
9adb shell input keyevent 9Keycode 2 — Number 2
10adb shell input keyevent 10Keycode 3 — Number 3
11adb shell input keyevent 11Keycode 4 — Number 4
12adb shell input keyevent 12Keycode 5 — Number 5
13adb shell input keyevent 13Keycode 6 — Number 6
14adb shell input keyevent 14Keycode 7 — Number 7
15adb shell input keyevent 15Keycode 8 — Number 8
16adb shell input keyevent 16Keycode 9 — Number 9
17adb shell input keyevent 17STAR (*) Key
18adb shell input keyevent 18Pound (#) Key
  • Koltin: open class KeyEvent: InputEvent, Parcelable

  • Java: public class KeyEvent extends InputEvent implements Parcelable


In Android, there are several ways to store data persistently. The choice of storage mechanism depends on the nature of the data and the requirements of the app. Below are the primary methods for data storage in Android:

Comparison of Storage Options

Storage MethodVisibilityPersistenceComplexityBest For
SharedPreferencesPrivateUntil app uninstallLowSmall key-value pairs
Internal StoragePrivateUntil app uninstallLowPrivate files
External StoragePublicUntil manually deletedMediumLarge/shared files
SQLite DatabasePrivateUntil app uninstallHighStructured data
RoomPrivateUntil app uninstallMedium-HighStructured data with compile-time safety

When choosing a storage method, consider the type of data you’re storing, how much data you need to store, the required level of security, and the complexity you’re willing to manage in your app.

  1. SharedPreferences

SharedPreferences is a framework that allows you to save and retrieve key-value pairs of primitive data types.

Use Cases

  • Storing user preferences.
  • Saving settings or configuration data.

Advantages:

  • Simple to use for small amounts of data
  • Data persists across app restarts

Disadvantages:

  • Not suitable for large or complex data structures
  • Not encrypted by default

Java Code Example

// Saving data to SharedPreferences
SharedPreferences sharedPref = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("key_name", "value");
editor.apply();
// Retrieving data from SharedPreferences
SharedPreferences sharedPref = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
String value = sharedPref.getString("key_name", "default_value");
  1. Internal Storage

Internal Storage is used to store private data within the device’s internal memory.

Use Cases

  • Storing sensitive data.
  • Files that should not be accessible to other apps.

Advantages:

  • Data is private to the app.
  • Files are removed when the app is uninstalled.

Disadvantages:

  • Limited by device storage.
  • Not easily accessible for backup.

Java Code Example

// Writing to internal storage
String filename = "myfile";
String fileContents = "Hello, World!";
FileOutputStream fos = openFileOutput(filename, Context.MODE_PRIVATE);
fos.write(fileContents.getBytes());
fos.close();
// Reading from internal storage
FileInputStream fis = openFileInput(filename);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
String fileContents = sb.toString();
fis.close();
  1. External Storage

External Storage is used to store public data on the shared external storage. It’s typically used for storing larger files.

Use Cases

  • Storing media files (images, videos, audio)
  • Documents that need to be shared with other apps.

Advantages:

  • Larger storage capacity
  • Files can be shared with other apps

Disadvantages:

  • Not secure, as other apps can access the files
  • Files may remain after app uninstallation

Permissions

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Java Code Example

// Writing to external storage
String filename = "myfile";
String fileContents = "Hello, World!";
File file = new File(getExternalFilesDir(null), filename);
FileOutputStream fos = new FileOutputStream(file);
fos.write(fileContents.getBytes());
fos.close();
// Reading from external storage
File file = new File(getExternalFilesDir(null), filename);
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
String fileContents = sb.toString();
fis.close();
  1. SQLite Database

SQLite is a lightweight relational database embedded within Android.

Use Cases

  • Structured data storage.
  • Complex querying requirements.
  • Managing complex data relationships

Advantages:

  • Efficient for complex queries and large datasets
  • Supports transactions and data integrity

Disadvantages:

  • More complex to set up and use compared to other options
  • Overkill for simple data storage needs

Java Code Example

// Creating a database helper
public class MyDatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "mydatabase.db";
private static final int DATABASE_VERSION = 1;
public MyDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE mytable (id INTEGER PRIMARY KEY, name TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS mytable");
onCreate(db);
}
}
// Using the database helper
MyDatabaseHelper dbHelper = new MyDatabaseHelper(context);
SQLiteDatabase db = dbHelper.getWritableDatabase();
// Inserting data
ContentValues values = new ContentValues();
values.put("name", "John Doe");
long newRowId = db.insert("mytable", null, values);
// Querying data
Cursor cursor = db.query("mytable", new String[]{"id", "name"}, null, null, null, null, null);
while (cursor.moveToNext()) {
long itemId = cursor.getLong(cursor.getColumnIndexOrThrow("id"));
String itemName = cursor.getString(cursor.getColumnIndexOrThrow("name"));
}
cursor.close();
db.close();
  1. Room Database

Room is an abstraction layer over SQLite that provides a more robust database access while harnessing the full power of SQLite.

Use Cases:

  • When you need a robust database solution but want to avoid the complexity of raw SQLite

Advantages:

  • Compile-time verification of SQL queries
  • Convenient annotations to define database structure
  • Easy integration with other Architecture components

Disadvantages:

  • Adds additional dependencies to your project
  • May be overkill for very simple data storage needs

Java Code Example

// Define Entity
@Entity(tableName = "user")
public class User {
@PrimaryKey
public int id;
public String name;
}
// Define DAO
@Dao
public interface UserDao {
@Insert
void insert(User user);
@Query("SELECT * FROM user WHERE id = :id")
User getUserById(int id);
}
// Define Database
@Database(entities = {User.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {
public abstract UserDao userDao();
}
// Using Room
AppDatabase db = Room.databaseBuilder(getApplicationContext(),
AppDatabase.class, "mydatabase").build();
UserDao userDao = db.userDao();
// Inserting data
User user = new User();
user.id = 1;
user.name = "John Doe";
userDao.insert(user);
// Querying data
User user = userDao.getUserById(1);
  1. Content Providers

Content Providers manage access to a structured set of data. They encapsulate the data and provide mechanisms for defining data security.

Use Cases

  • Sharing data between different applications.
  • Accessing data from other applications.

Java Code Example

// Querying a content provider
Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI,
null,
null,
null,
null);
while (cursor.moveToNext()) {
String id = cursor.getString(
cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(
cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
}
cursor.close();

This part of the guide goes into the specific parts of React Native and Android, we do try to keep all our react native notes into one area. We recommend going to the rn section as well, but there might be double notes in this section.