Stopping an Android app using ADB
adb shell am force-stop com.my.app.package
References
https://stackoverflow.com/questions/3117095/stopping-an-android-app-from-console
Just Daily Notes
adb shell am force-stop com.my.app.package
References
https://stackoverflow.com/questions/3117095/stopping-an-android-app-from-console
Tap X,Y position:
adb shell input tap 500 1450
Swipe X1 Y1 X2 Y2 [duration(ms)]:
adb shell input swipe 100 500 100 1450 100
LongPress X Y:
adb shell input swipe 100 500 100 500 250
References
https://stackoverflow.com/questions/7789826/adb-shell-input-events
cmd = 'adb exec-out screencap' pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) img_bytes = pipe.stdout.read() img = np.array(Image.frombuffer('RGBA', (960, 540), img_bytes[12:], 'raw', 'RGBX', 0, 1))
adb -s 127.0.0.1:62025 shell ip link show
adb -s 127.0.0.1:62025 shell ifconfig eth1
References
https://stackoverflow.com/questions/1720346/how-to-get-the-android-emulators-ip-address
https://stackoverflow.com/questions/16033900/what-is-the-ip-address-of-android-emulator
set up forwarding of host port 6100 to device port 7100
adb forward tcp:6100 tcp:7100
When your device is trying to access local port 3000, that request will be routed to your laptop’s port 3000.
adb reverse tcp:3000 tcp:3000
References
https://blog.usejournal.com/adb-port-forwarding-and-reversing-d2bc71835d43
list all running apps
adb shell ps
check app is running
adb shell ps "com.klab.captain283.global"
References
https://stackoverflow.com/questions/16691487/how-to-detect-running-app-using-adb-command
adb shell pm list packages -f
References
https://www.aftvnews.com/how-to-determine-the-package-name-of-an-android-app/
Start adb daemon on remote device
adb devices
$ adb devices * daemon not running. starting it now on port 5037 * * daemon started successfully * List of devices attached 5200fe4259bcc000 device
do client to server port forwarding using ssh on port 5037
References
https://dontbelievethebyte.github.io/articles/2015/01/15/debug-remotely-on-android-via-ssh-tunnel/
https://developer.android.com/studio/command-line/adb
https://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
//get destination to update file and set Uri //TODO: First I wanted to store my update .apk file on internal storage for my app but apparently android does not allow you to open and install //aplication with existing package from there. So for me, alternative solution is Download directory in external storage. If there is better //solution, please inform us in comment String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/"; String fileName = "AppName.apk"; destination += fileName; final Uri uri = Uri.parse("file://" + destination); //Delete update file if exists File file = new File(destination); if (file.exists()) //file.delete() - test this, I think sometimes it doesnt work file.delete(); //get url of app on server String url = Main.this.getString(R.string.update_app_url); //set downloadmanager DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setDescription(Main.this.getString(R.string.notification_description)); request.setTitle(Main.this.getString(R.string.app_name)); //set destination request.setDestinationUri(uri); // get download service and enqueue file final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); final long downloadId = manager.enqueue(request); //set BroadcastReceiver to install app when .apk is downloaded BroadcastReceiver onComplete = new BroadcastReceiver() { public void onReceive(Context ctxt, Intent intent) { Intent install = new Intent(Intent.ACTION_VIEW); install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); install.setDataAndType(uri, manager.getMimeTypeForDownloadedFile(downloadId)); startActivity(install); unregisterReceiver(this); finish(); } }; //register receiver for when .apk download is compete registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
References
https://stackoverflow.com/questions/4967669/android-install-apk-programmatically
https://stackoverflow.com/questions/39147608/android-install-apk-with-intent-view-action-not-working-with-file-provider/40131196#40131196
yourRecyclerView.getLayoutManager().findFirstVisibleItemPosition();
you probably need to cast your LayoutManager to a LinearLayoutManager or GridLayoutManager (you have to cast to the correct type you are using) to access these findVisibleXXXX() methods.