Android notifications via ADB

I am writing a shell script that allows you to install .apk on all Android phones connected to the computer in parallel using Terminal . At my company, we run tests on many devices, so this speeds up the installation process.

Question: I'm looking for a way to quickly determine which phones had an .apk installed using some kind of feedback / notification. Ideally, you should be able to see which phones got the .apk by simply looking at it (some sound or on-screen flash) or simply unlocking the device (for example, a recently installed application was open).

Any ideas on how I can do this?

I read about running applications, but it looks like this is not something you could only do with .apk (you will also need to specify activity ...).

Any ideas would be much appreciated!

Thanks!

+4
source share
4 answers

Found my solution!

I used:

aapt dump badging 

thinking that it will simply output the package name. It turns out that it outputs a lot more useful information. One of the lines that I noticed is the launch of the application. I was able to isolate this line with grep, and then disabled startup activity like this:

 aapt dump badging $1 | grep launchable | cut -d "'" -f 2 

Then a command appears that allows you to run the application if you know one of its actions. Adding this line triggers the action that was retrieved using the command above.

 adb -s $deviceID shell am start -a android.intent.action.MAIN -n $packageName/$launchableActivity 

I put this line in a for loop right after the install command. After installing the application after that, the application script will try to run it. Very comfortably!

Thanks for the help !: D

+4
source

Use the package manager to check if the APK is installed:

 pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [FILTER] pm list packages: prints all packages, optionally only those whose package name contains the text in FILTER. Options: -f: see their associated file. -d: filter to only show disbled packages. -e: filter to only show enabled packages. -s: filter to only show system packages. -3: filter to only show third party packages. -i: see the installer for the packages. -u: also include uninstalled packages. 

eg

 $ adb shell pm list packages com.example.mypkg 
+2
source

You can use "start adb shell am start" with the arguments you will need to look for to start a new package.

If you are worried not to confuse the obsolete, adb delete the old file before installing the new one or better yet show how you show your version of the spray display.

In fact, you can use the beginning to trigger an action that is unknown to trigger, so you can use it to directly trigger an “activity” that will display the current version. It’s your choice if you make it available in the normal way of the application or use it only once as a splash.

You should also be able to analyze the output of the adb installation command - you will need to see if it sends errors / success to stderr or stdout.

UPDATE: Here's how to do an operation that you can use to turn on the screen and display a message, for example:

 adb shell 'am start -n com.example.testreport/.ReportActivity -e result PASS' 

The code is heavily cut from the built-in AlarmClock of an earlier version of Android, this will require:

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

in manifest

 package com.example.testreport; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; import android.util.Log; import android.view.Gravity; import android.view.WindowManager; import android.view.WindowManager.LayoutParams; import android.widget.TextView; public class ReportActivity extends Activity { PowerManager.WakeLock sScreenWakeLock; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(android.view.Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); } protected void onStart() { super.onStart(); if (sScreenWakeLock == null) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); sScreenWakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "ReportActivity Wakelock"); sScreenWakeLock.acquire(); } TextView tv=new TextView(this); tv.setTextSize(30); tv.setGravity(Gravity.CENTER); Intent i = getIntent(); if ((i != null) && (i.hasExtra("result"))) tv.setText(i.getStringExtra("result")); else tv.setText("???"); setContentView(tv); } protected void onStop() { if (sScreenWakeLock != null) { sScreenWakeLock.release(); sScreenWakeLock = null; } super.onStop(); } } 

He probably can use some refinement and improvement; for example, at the moment you cannot turn off the phone with the power button, unless you stop the action by moving to lose visibility.

+1
source

One way to see how this is done is through an application that verifies application installation. In particular, a checklist of the applications that must be installed on the device, and when the PackageManager completes the installation, it is updated based on this translation.

Besides the fact that you do this outside the application level, I don’t think it’s possible if you don’t sniff the USB port that goes to the device and do not determine the commands and payload and do not specify (HACK)

0
source

All Articles