20 Nov 2019 - TVDB Scraper v3.2.0 is now available which reinstates scraping. TVDB are still in the process of fixing a number of bugs so there may still be further breakages. See this post. 2901570 (post)

Solved Install extern APK from python code in Leia
#1
Hello friends.

I have a problem and I do not know if it is a bug of Kodi 18 RC4 or is that now it can not be done this way.

I mean, I had made an addon that downloads and installs RetroArch. In Krypton it worked perfectly. But I've been testing Kodi 18 Leia.

And although the download continues to work perfectly, when I try to install the APK I get an exception, but it does not give any information in the log.

The python command that I use is:

xbmc.executebuiltin ('StartAndroidActivity ("", "android.intent.action.VIEW", "application / vnd.android.package-archive", "file:' + pathdownload + '")')

And pathdownload is correct, it points directly to the RetroArch APK. As I say, Krypton works perfectly; but in Leia, looking at the log, this error appears:

16: 49: 11.528 T: 534199280720 INFO: CPythonInvoker (1, /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.insretroarch/default.py): script successfully run
16: 49: 11.528 T: 534199280720 DEBUG: onExecutionDone (1, /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.insretroarch/default.py)
16: 49: 11.546 T: 534392075344 ERROR: CXBMCApp :: StartActivity - ExceptionOccurred launching
16: 49: 11604 T: 534199280720 INFO: Python interpreter stopped
16: 49: 11604 T: 534199280720 DEBUG: Thread LanguageInvoker 534199280720 terminating
16: 49: 11.612 T: 534200317008 ERROR: GetDirectory - Error getting plugin: //script.insretroarch/
16: 49: 11.613 T: 534200317008 DEBUG: Thread waiting 534200317008 terminating
16: 49: 11.627 T: 534392075344 DEBUG: ------ Window Deinit (DialogBusy.xml) ------
16: 49: 11.627 T: 534392075344 ERROR: CGUIMediaWindow :: GetDirectory (plugin: //script.insretroarch/) failed
16: 49: 11.627 T: 534392075344 DEBUG: CGUIMediaWindow :: GetDirectory () 16: 49: 11.628 T: 534392075344 DEBUG: ParentPath = [plugin: //script.insretroarch/]

If you need the source code of the addon or a more extensive log, just tell me. Thanks for your help.
Reply
#2
Hello again, friends.

Finally, I have managed to do it, but making a direct call to the am command (Android Manager).

Thank you very much.
Reply
#3
Thread marked solved.
Got a Kodi problem? Provide us with a full Debug log (wiki) || Usefull pages: First time user (wiki) || Troubleshooting (wiki) || Free content (wiki) || Forum rules (wiki) || VPN policy (wiki)
Reply
#4
(2019-01-15, 15:46)lunamoon Wrote: Hello again, friends.

Finally, I have managed to do it, but making a direct call to the am command (Android Manager).

Thank you very much.

Are you referring to adb? Can you post an example of the Android Manager call?; thanks...
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Twitter | Help?
Reply
#5
Hi, Lunatixz.

I did not want to use adb so I did not have to install it. And sorry, because I was wrong in my previous post, I don't use am to install an APK.
I use Package Manager (pm) to install an APK and am command to launch an APK.

So I tried directly with a call to the pm command, using subprocess.call first and in case it fails, a direct call to os.system.

So, I made a function like this:

def launch_command(command_launch):
    try:
        xbmc.log('[%s] %s' % ('LAUNCHING SUBPROCESS:', command_launch), 2)
        external_command = subprocess.call(command_launch, shell = True, executable = '/system/bin/sh')
    except Exception, e:
        try:
            xbmc.log('[%s] %s' % ('ERROR LAUNCHING COMMAND !!!', e.message, external_command), 2)
            xbmc.log('[%s] %s' % ('LAUNCHING OS:', command_launch), 2)
            external_command = os.system(command_launch)
            xbmc.sleep(500)
        except:
            xbmc.log('[%s] %s' % ('ERROR LAUNCHING COMMAND !!!', e.message, external_command), 2)

And parameter to launch_command function could be like this:

pm install -r -g -d path_to_apk

Greetings.
Reply
#6
Could you possibly elaborate on this for me?  I am trying to teach myself python.

I want to be able to install android apps through a script, but in Kodi 18, the StartAndroidActivity method to install the apk isn't working, as you said previously.  

Is there anyway you could include all the code you used in your implementation using the package manager and such?  Just seeing the working code would help me out a ton as I learn best by reverse engineering it.  Thanks in advance for any help you could provide, sir.
Reply
#7
Hello Technometry,

The truth is that there really is not much more code than what I sent in the last post.

It is simply, call launch_command function, passing pm command as an argument.

Something like this:


# I do not remember the imports exactly (I do not have the source available now)
# but I think that with these should be enough
import xbmc, xbmcaddon, xbmcgui, xbmcplugin, os, subprocess

def launch_command(command_launch):
    try:
        xbmc.log('[%s] %s' % ('LAUNCHING SUBPROCESS:', command_launch), 2)
        external_command = subprocess.call(command_launch, shell = True, executable = '/system/bin/sh')
    except Exception, e:
        try:
            xbmc.log('[%s] %s' % ('ERROR LAUNCHING COMMAND !!!', e.message, external_command), 2)
            xbmc.log('[%s] %s' % ('LAUNCHING OS:', command_launch), 2)
            external_command = os.system(command_launch)
        except:
            xbmc.log('[%s]' % ('ERROR LAUNCHING COMMAND !!!', external_command), 2)
            
# We assume that you have already downloaded the apk you want in /sdcard/Download
pathdownload = '/sdcard/Download/application.apk'
command = 'pm install -rgd' + pathdownload
launch_command(command)

And that's it, this should install the apk. The -rgd parameters are to grant it the permissions it require, to update if it already exists and to allow downgrade, if I remember correctly.

I hope you find it useful.

Greetings
Reply
#8
Thanks for the information... this looks like the local variant of adb install...  I believe this will only work on rooted devices?
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Twitter | Help?
Reply
#9
Hi, Lunatixz,

Yes, it's like a variant of the installation using the adb command, but we avoid having to install the adb package.

I think that possibly, as you say, the device has to be rooted to be able to execute the pm command.

The truth is that I can not confirm because my device (Beelink GT1 Ultimate) is rooted and therefore works. I think it's not the best option to do what we want, but at the moment is the way I have found to do it because as I said in my first post, the call to the builtin function StartAndroidActivity to install an APK does not work in Kodi 18 Leia (in Krypton it worked perfectly) and after having enabled debug mode in Kodi, in the log the only thing I can see is that it throws an exception, but without giving more information about what cause it.

Greetings.
Reply
#10
Hey lunamoon, 

Thank you so much for your response and clarification.  That little extra helps a ton.  Thank you, I will play with it soon! 

Any idea as to if the Kodi developers have posted anything in a forum about this issue or not?  I've been digging but this thread is all I could find on the issue.  StartAndroidActivity works on everything but launching the installer.  Puzzling.  The KodiAndroidInstaller addon on their site as the same issue and shows a message saying it was due to an Android API change, but I thought they would have fixed this before releasing Leia stable.  However, it has been released and this is still not working.  Weird

Anyway, thanks again for the clarification!
Reply
#11
Hi, I'm glad the code helped you.

I also thought that when Leia stable came out, they would have fixed this error.

The truth is that I have not tried in the latest version. But I guess you've already tried and it's still not working.

I imagine that they will solve it soon.

Greetings.
Reply
#12
Hi,
maybe someone can help, PLS 
when i use the launch_command 
i get this error :
22:58:38.835 T:17283  NOTICE: [LAUNCHING SUBPROCESS:] pm install -rgd /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/packages/perfectplayer.apk
22:58:40.329 T:17283 WARNING: Attempt to use invalid handle -1
Reply
#13
(2019-06-13, 00:06)kabcasa Wrote: Hi,
maybe someone can help, PLS 
when i use the launch_command 
i get this error :
22:58:38.835 T:17283  NOTICE: [LAUNCHING SUBPROCESS:] pm install -rgd /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/packages/perfectplayer.apk
22:58:40.329 T:17283 WARNING: Attempt to use invalid handle -1
Hi, Kabcasa, change the order of commands launched in launch_command function. Launch in first place os.system and, only if it launch exception, then you can launch the call to subprocess.
Reply
#14
(2019-01-10, 19:47)lunamoon Wrote: Hello friends.

I have a problem and I do not know if it is a bug of Kodi 18 RC4 or is that now it can not be done this way.

I mean, I had made an addon that downloads and installs RetroArch. In Krypton it worked perfectly. But I've been testing Kodi 18 Leia.

And although the download continues to work perfectly, when I try to install the APK I get an exception, but it does not give any information in the log.

The python command that I use is:

xbmc.executebuiltin ('StartAndroidActivity ("", "android.intent.action.VIEW", "application / vnd.android.package-archive", "file:' + pathdownload + '")')

And pathdownload is correct, it points directly to the RetroArch APK. As I say, Krypton works perfectly; but in Leia, looking at the log, this error appears:

16: 49: 11.528 T: 534199280720 INFO: CPythonInvoker (1, /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.insretroarch/default.py): script successfully run
16: 49: 11.528 T: 534199280720 DEBUG: onExecutionDone (1, /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.insretroarch/default.py)
16: 49: 11.546 T: 534392075344 ERROR: CXBMCApp :: StartActivity - ExceptionOccurred launching
16: 49: 11604 T: 534199280720 INFO: Python interpreter stopped
16: 49: 11604 T: 534199280720 DEBUG: Thread LanguageInvoker 534199280720 terminating
16: 49: 11.612 T: 534200317008 ERROR: GetDirectory - Error getting plugin: //script.insretroarch/
16: 49: 11.613 T: 534200317008 DEBUG: Thread waiting 534200317008 terminating
16: 49: 11.627 T: 534392075344 DEBUG: ------ Window Deinit (DialogBusy.xml) ------
16: 49: 11.627 T: 534392075344 ERROR: CGUIMediaWindow :: GetDirectory (plugin: //script.insretroarch/) failed
16: 49: 11.627 T: 534392075344 DEBUG: CGUIMediaWindow :: GetDirectory () 16: 49: 11.628 T: 534392075344 DEBUG: ParentPath = [plugin: //script.insretroarch/]

If you need the source code of the addon or a more extensive log, just tell me. Thanks for your help.
Would you mind posting the full addon? Im trying to update an addon I have to do something like this on the firesticks running nougat and I am struggling. I can edit code but doing it from scratch is not simple for me.
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
Install extern APK from python code in Leia00