Saturday, July 7, 2018

applications - Get new installed app name with Tasker


I'm trying to set up the following Tasker project: when a new app is installed on one of my devices, send a notification to all the other devices with the name of the app. Ideally, if I find a functioning API, the task will query the API for the app link on the Play Store using the name.


Anyway, my question is: is it possible to get the new installed app name with Tasker? Or at least the package name.



Answer



Yes, of course it is possible. The easiest way is the native way, the way which Android apps use to know which app has been installed in the system. They get to know that information by listening to a broadcast intent with action android.intent.action.PACKAGE_ADDED. The data it carries has the package name.


Provided that you've setup in PC, you can check this info on your own by installing a new app in your system followed by executing


adb shell dumpsys activity

Look for the string android.intent.action.PACKAGE_ADDED under Historical broadcasts [background]. Example:


#7: BroadcastRecord{426162e8 u0 android.intent.action.PACKAGE_ADDED}

act=android.intent.action.PACKAGE_ADDED dat=package:de.defim.apk.protectedapps flg=0x8000010 (has extras)
extras: Bundle[{android.intent.extra.UID=10150, android.intent.extra.user_handle=0}]

As for the Tasker, it allows listening to broadcasts as a trigger. Setup Tasker like this:




  • Profile: Event → System → Intent Received



    • Action: android.intent.action.PACKAGE_ADDED

    • Scheme: package

    • leave the rest untouched





  • Task: (Actions):




    • Variables → Variable Split



      • Name: %intent_data



      • Splitter: :


        The package name would now be saved in the variable %intent_data2 (a local variable). Use it wherever you want.






    In order to get the app label, you can either use Tasker's inbuilt functionality or use aapt (requires root access)




    • App → Test App:




      • Type: Package Name

      • Data: %intent_data2


      • Store Result In: %App_name


        The app label can now be retrieved from the variable %App_name.









See Accessing Intent Data for more info on intent handling in Tasker.


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...