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')
#--------------------------