Skip to content

Instantly share code, notes, and snippets.

Subscribe to my newsletter:

Wajahat Karim wajahatkarim3

Subscribe to my newsletter:
View GitHub Profile
View Demo.kt
object YourKeys {
init {
external fun apiKey(): String
View Demo.cpp
#include <jni.h>
#include <string>
extern "C" JNIEXPORT jstringJNICALL
Java_com_package_name_YourKeys_apiKey(JNIEnv *env, jobject object) {
std::string api_key = "your_api_key";
return env->NewStringUTF(api_key.c_str());
View Demo.kt
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.texturelabs.rosera.pop_movies"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
View Demo.kt
object Constants {
const val API_KEY = "abcdefg2q4qsaf34rtyy421k"
View strings.xml
<?xml version="1.0" encoding="utf-8"?>
<!--API Key-->
<string name="api_key">abcdefg2q4qsaf34rtyy421k</string>
View Demo.kt
val securePreferences = EncryptedSharedPreferences.create(
// Storing Data in Preferences
with(securePreferences.edit()) {
View Demo.kt
val keyGenParameterSpec = MasterKeys.AES256_GCM_SPEC
val mainKeyAlias = MasterKeys.getOrCreate(keyGenParameterSpec)
View Demo.kt
val preferences = getSharedPreferences("normal_prefs", MODE_PRIVATE)
// Storing Data in Preferences
with(preferences.edit()) {
putBoolean("Bool", true)
putString("String", "Some normal string value")
putInt("Integer", 10)
View Demo.kt
object CustomerData {
var customerId =123
var name =John
var totalBill = 284.34
var purchasedItems: List<Item> = arrayListOf()
fun addItem(item: Item) {
totalBill = calculateBill()
View Demo.kt
// Get the DataStore object
private val settingsDataStore by preferencesDataStore(name = “app_settings”)
// Get the keys
val myStrKey = stringPreferencesKey("myStrKey")
// Read the values through coroutine scopes
lifecycleScope.launch { { pref ->
// Read the values here