Android List available apps
#1
Is there any way that we can request the apps available on android from within an addon. We already have the view where we see installed apps and can start those from within Kodi.
But I want to use this functionality to let the user choose an app from a list instead of showing a file dialog/browser.This is easier for the user compared with having to type in some 'am' command with intents etc.
Reply
#2
I solved this by using a list of pre-defined internet browsers.
I check if there is any folder with the name of the browser package, if it exists it calls the browser. If it does not exist, call Google play to install the browser.

But if you want to see all the apps installed by the user can use the command:
os.listdir ()
https://www.tutorialspoint.com/python/os_listdir.htm

Android Apps installed:
'/data/data/'
or
'/storage/sdcard0/Android/data/'

A sample of my code:
Code:
import xbmc, xbmcplugin, xbmcgui, xbmc, xbmcaddon
import urllib, urllib2, re, HTMLParser, os
import webbrowser

addon_id = 'plugin.video.YOUR_ADDON_NAME'
selfAddon = xbmcaddon.Addon(id=addon_id)
addon_dir = xbmc.translatePath( selfAddon.getAddonInfo('path') )
G_header = 'YOUR_ADDON_Title'

def msg(text):
    dialog = xbmcgui.Dialog()
    ok = dialog.ok(G_header, text)

def dlgYN(text):
    dialog = xbmcgui.Dialog()
    return dialog.yesno(G_header, text)

def get_system_platform():
    platform = "unknown"
    if xbmc.getCondVisibility('system.platform.linux') and not xbmc.getCondVisibility('system.platform.android'):
        platform = "linux"
    elif xbmc.getCondVisibility('system.platform.linux') and xbmc.getCondVisibility('system.platform.android'):
        platform = "android"
    elif xbmc.getCondVisibility( "system.platform.xbox" ):
        platform = "xbox"
    elif xbmc.getCondVisibility( "system.platform.windows" ):
        platform = "windows"
    elif xbmc.getCondVisibility( "system.platform.osx" ):
        platform = "osx"
    elif xbmc.getCondVisibility( "system.platform.ios" ):
        platform = "ios"
    return platform
    
#=################ loads the variable myOS ################=#
myOS = get_system_platform()
#=#########################################################=#


def android_browser():
    #Name the most common browsers
    nav_name = ['Free Adblocker', 'Adblock Plus', 'Chrome', 'Firefox', 'Opera']
    
    #Package name of the respective browsers
    nav_pack = ['com.hsv.freeadblockerbrowser', 'org.adblockplus.browser', 'com.android.chrome', 'org.mozilla.firefox', 'com.opera.browser']
    
    dialog = xbmcgui.Dialog()
    ret = dialog.select('Choose one of the Browsers', nav_name)
    saida = [ret, nav_name[ret], nav_pack[ret]]
    return saida

def open_nav(url):
    if myOS == 'android' :
        retBrowser = android_browser()
        if retBrowser[0] > -1 :
            app = retBrowser[2]
            
            #--- Android dir
            try:
                #[root access]  --- Chrome dir
                appDir = '/data/data/' + retBrowser[2]
            except:
                
                #Normal dir
                #addon_dir -->>>> '/storage/sdcard0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.video.YOUR_ADDON_NAME'
                
                #appDir -->>>> '/storage/sdcard0/Android/data/ (App's dir)'
                appDir = addon_dir.split('org.xbmc.kodi')[0] + retBrowser[2]
            #---------------------------
            
            #--- If the package directory exists, it means that the app is installed
            if os.path.exists(appDir):
                if app == 'com.android.chrome':
                    intent = ''
                else:
                    intent = 'android.intent.action.VIEW'
                dataType = ''
                dataURI = url
                cmd = 'StartAndroidActivity("%s", "%s", "%s", "%s")' % (app, intent, dataType, dataURI)
                xbmc.executebuiltin(cmd)
                
            #If the package directory does not exist, redirect to Google play install the respective app link
            else:
                acao = dlgYN('The app ' + retBrowser[1] +  ' is not installed on your Android system!\nDo you want to install this app now?')
                if acao == True:
                    app = 'com.android.vending'
                    intent = 'android.intent.action.VIEW'
                    dataType = ''
                    dataURI = 'market://details?id=' + retBrowser[2]

                    cmd = 'StartAndroidActivity("%s", "%s", "%s", "%s")' % (app, intent, dataType, dataURI)
                    xbmc.executebuiltin(cmd)
    
    #Other operating systems open the default browser in a new tab (new=2)        
    elif myOS == 'linux' :
        webbrowser.open(url, new=2)
        
    elif myOS == 'windows' :
        webbrowser.open(url, new=2)
        
    elif myOS == 'osx' : #I have never tested this option, I do not have Apple's operating system to test.
        webbrowser.open(url, new=2)
        
    else:
        msg('Operating system does not support this Add on function')
        
#--------------------------        
open_nav('https://www.google.com')
#--------------------------
Reply
#3
(2017-08-23, 00:01)antrrax Wrote: I solved this by using a list of pre-defined internet browsers.
I check if there is any folder with the name of the browser package, if it exists it calls the browser. If it does not exist, call Google play to install the browser.

But if you want to see all the apps installed by the user can use the command:
os.listdir ()
https://www.tutorialspoint.com/python/os_listdir.htm

Android Apps installed:
'/data/data/'
or
'/storage/sdcard0/Android/data/'

A sample of my code:
...

I already thought about looping through the applications folder, but it doesnt give me the nice names and icons. In your example you also need to know possible application before so that you can match on them. In my setup I just want to get the list of apps just like when you open up the android apps view in Kodi.The only thing is I want to show that in a dialog and execute the app myself from the addon. So its not a specific app, it can be any app installed by the user.

A better example: I want to have a list of shortcuts to games installed on Android in my addon to launch. The user can add any app/game by opening up a dialog and selecting the app/game from the list of installed android apps.
Reply

Logout Mark Read Team Forum Stats Members Help
List available apps0