JAVA help please

102 views
Skip to first unread message

ktmom

unread,
Feb 16, 2020, 1:11:10 PM2/16/20
to Tasker
I am trying to get the first installed date for a specified package using the code at: https://android--code.blogspot.com/2017/06/android-get-app-first-install-time.html as a model.
   A1: Java Function [ 
        Return: installTime 
        Class Or Object:CONTEXT 
        Function: getPackageManager
        {PackageManager}().getPackageInfo(net.dinglisch.android.taskerm,0).firstInstallTime 
    ]

   A2: Java Function [ 
        Return: %installtime 
        Class Or Object: f 
        Function: getLong
        {long} (Object) 
        Param: installTime 
    ]


I expect a timestamp to be returned in %installtime.  A2 fails with the following error:


12.41.33/Variables doreplresult: |%installtime| -> |%installtime|
12.41.33/E Java Function: %installtime -> %installtime
12.41.33/E Java Function use app context
12.41.33/JU analyse: target: f expected: null
12.41.33/JU target: analyse done: f: class: ???  obj: null partWithoutMods: null static: false const false casted: false
12.41.33/JU analyse: returnval: long expected: null
12.41.33/JU returnval: analyse done: long: class: long  obj: null partWithoutMods: null static: true const false casted: false
12.41.33/JU initClass: class: long  obj: null partWithoutMods: long static: true const false casted: false
12.41.33/JU initClass: retnovar: init with array handling -> long
12.41.33/JU initClass: class: ???  obj: null partWithoutMods: f static: false const false casted: false
12.41.33/JU initClass: target: null: class: ???  obj: null partWithoutMods: f static: false const false casted: false
12.41.33/E Java Function: failed to init target class f
12.41.33/E result: stop task (error)
12.41.33/E Error: 1
12.41.33/MacroEdit action finished exeID 20 action no 1 code 664 status: Err next 1

Can anyone help me sort this out? 

Rich D

unread,
Feb 16, 2020, 7:12:58 PM2/16/20
to Tasker Google Groups Post


I am trying to get the first installed date for a specified package using the code at: 

This is what I came up with...




    Java Install Time (813)
    A1: App Info [  Package/App Name:net.dinglisch.android.taskerm Ignore Packages: Ignore Unlaunchable Apps:Off Get All Details:Off ] 
    A2: Java Function [ Return:my_pac_mang Class Or Object:CONTEXT Function:getPackageManager
    {PackageManager} () Param: Param: Param: Param: Param: Param: Param: ] 
    A3: Java Function [ Return:pac_time Class Or Object:my_pac_mang Function:getPackageInfo
    {PackageInfo} (String, int) Param:%app_package Param:0 Param: Param: Param: Param: Param: ] 
    A4: Java Function [ Return:package_class Class Or Object:pac_time Function:getClass
    {Class} () Param: Param: Param: Param: Param: Param: Param: ] 
    A5: Java Function [ Return:package_field Class Or Object:package_class Function:getField
    {java.lang.reflect.Field} (String) Param:"firstInstallTime" Param: Param: Param: Param: Param: Param: ] 
    A6: Java Function [ Return:%long_time Class Or Object:package_field Function:getLong
    {long} (Object) Param:pac_time Param: Param: Param: Param: Param: Param: ] 
    A7: Notify [ Title:%TIMEMS Text:%long_time Icon:null Number:0 Permanent:Off Priority:3 Repeat Alert:Off LED Colour:Red LED Rate:0 Sound File: Vibration Pattern: Category: ] 
    A8: Flash [ Text:%long_time Long:On ] 
    

From here..

Robert Ryan

unread,
Feb 16, 2020, 8:36:24 PM2/16/20
to tas...@googlegroups.com
Hi Rich, 

You only need the the Class and Field when you are dealing with static fields. Since firstInstallTime is a dynamic field, it can be gotten directly. See step A3 below. 

        Test
        
        Abort Existing Task
        
    A1: Java Function 
        Return: pacman 
        Class Or Object: CONTEXT 
        Function: getPackageManager
        {PackageManager} () 
        
    A2: Java Function 
        Return: pac_info 
        Class Or Object: pacman 
        Function: getPackageInfo
        {PackageInfo} (String, int) 
        Param: "net.dinglisch.android.taskerm" 
        Param: 0 
        
    A3: Java Function 
        Return: %install_time 
        Class Or Object: pac_info.firstInstallTime 
        Function: assign
        {long} () 
        
    A4: Flash 
        Text: %install_time 
        Long: Off 

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tasker/CADuUTArCmzewL3QkPJ0-CbTQKoWp%3Dn0PV5LN5xzMbX%3DUORF1tg%40mail.gmail.com.

Rich D

unread,
Feb 17, 2020, 7:04:48 AM2/17/20
to Tasker Google Groups Post

        
    A3: Java Function 
        Return: %install_time 
        Class Or Object: pac_info.firstInstallTime 
        Function: assign
        {long} () 
      

Hi Robert,

Thanks for the info... :)

Could you provide a screen shot or description of how you constructed A3 ?  I only see ( assign {object}  ()  ) and if I change it then %install_time does not get set...   

Robert Ryan

unread,
Feb 17, 2020, 7:30:55 AM2/17/20
to tas...@googlegroups.com
Sure, see attached. 

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
Screenshot_20200217-052827_Tasker.jpg

João Dias

unread,
Feb 17, 2020, 7:47:56 AM2/17/20
to tas...@googlegroups.com
You can get this directly with the App Info action if you enable the Get All Details option :)

Thank you for your contact.

   Join: connect multiple devices (send pushes, remote SMS, notifications) on Android, Windows, Mac, Linux
   Tasker: customize/automate anything on your phone!
   AutoApps: add advanced functionality to Tasker via plugins

     

João Dias

Rich D

unread,
Feb 17, 2020, 4:42:57 PM2/17/20
to Tasker Google Groups Post

Sure, see attached. 

Ok, got it working. It was the lowercase, uppercase, uppercase 'firstInstallTime'  that got me... Who makes up these naming structures...... ¯\_(ツ)_/¯

And because I had that wrong all the 'Function' helper would show me was 'assign {Object} ()' instead of 'assign {long} ()'

Thank you for the clarification. From the code I was copying from I do not believe I would have ever realized I could just add the '.firstInstallTime' to the 'pac_info' .

Thanks again.. 

Rich D

unread,
Feb 17, 2020, 4:45:12 PM2/17/20
to Tasker Google Groups Post

You can get this directly with the App Info action if you enable the Get All Details option :)

Ahhh...  Yup.. That would be a bit easier... :)

I had looked at all those a while ago then forgot that option was there when I recently checked that action. 

As always -  great work João .. 
Reply all
Reply to author
Forward
0 new messages