Skip to content

Instantly share code, notes, and snippets.

@OrenBochman
Last active September 22, 2018 16:52
Show Gist options
  • Save OrenBochman/e92932ae9fd38606d0faba205d9c8740 to your computer and use it in GitHub Desktop.
Save OrenBochman/e92932ae9fd38606d0faba205d9c8740 to your computer and use it in GitHub Desktop.
android analytics

android analytics

tasks

  1. is this an instant app or a regular app
  2. what is the apk size (actually the apk size) Getting Installed App Size
  3. what is the available memory
//required
// device with
// API 9 +
// Play 9.0
// emulator with google apis
// sdk
// google play sevices rev 30+
// google repository 26+
//gen sha1 pass (linux/mac)
// keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
//gen sha1 pass (windows)
// keytool -list -v -keystore C:\Documents and Settings\[User Name]\.android\debug.keystore -alias androiddebugkey -storepass android -keypass android
//download and add a json.config to the app directory of the project
// add a line to the dependency block of the project level
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:3.0.0'
}
}
// add a plugin into the app module
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
// add a `implementation` dependenct on firebase core
dependencies {
// ...
implementation 'com.google.firebase:firebase-core:9.0.2' //use the latest
}
//check by lanching and inspect logcat you can filter for 'FirebaseInitProvider initilised successfully'
//add features that you want
com.google.firebase:firebase-core:16.0.3 Analytics
com.google.firebase:firebase-database:16.0.1 Realtime Database
//com.google.firebase:firebase-firestore:17.1.0 Cloud Firestore
//com.google.firebase:firebase-storage:16.0.1 Storage
com.crashlytics.sdk.android:crashlytics:2.9.5 Crashlytics
com.google.firebase:firebase-auth:16.0.3 Authentication
//com.google.firebase:firebase-messaging:17.3.0 Cloud Messaging
//com.google.firebase:firebase-config:16.0.0 Remote Config
//com.google.firebase:firebase-invites:16.0.3 Invites and Dynamic Links
//com.google.firebase:firebase-ads:15.0.1 AdMob
//com.google.firebase:firebase-appindexing:16.0.1 App Indexing
//com.google.firebase:firebase-perf:16.1.0 Performance Monitoring
//com.google.firebase:firebase-functions:16.1.0 Cloud Functions for Firebase Client SDK
//com.google.firebase:firebase-ml-vision:17.0.0 ML Kit (Vision)
//com.google.firebase:firebase-ml-model-interpreter:16.2.0 ML Kit (Custom Model)
int sysVersion= Build.VERSION.SDK_INT;
if (pkgName != null) {// packageName
PackageManager pm = getPackageManager();
try {
Class<?> clz = pm.getClass();
if (sysVersion>16) {
Method myUserId=UserHandle.class.getDeclaredMethod("myUserId");//ignore check this when u set ur min SDK < 17
int userID = (Integer) myUserId.invoke(pm);
Method getPackageSizeInfo = clz.getDeclaredMethod(
"getPackageSizeInfo", String.class,int.class,
IPackageStatsObserver.class);//remember add int.class into the params
getPackageSizeInfo.invoke(pm,pkgName, userID, new PkgSizeObserver());
} else {//for old API
Method getPackageSizeInfo = clz.getDeclaredMethod(
"getPackageSizeInfo", String.class,
IPackageStatsObserver.class);
getPackageSizeInfo.invoke(pm, pkgName, new PkgSizeObserver());
}
} catch (Exception ex) {
Log.e(TAG, "NoSuchMethodException");
ex.printStackTrace();
throw ex;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment