Я попробовал несколько вариантов, и ни один из них не помог. Все права предоставлены(
Код: Выделить всё
Permission.INTERNET, Permission.ACCESS_NETWORK_STATE, Permission.ACCESS_COARSE_LOCATION, Permission.ACCESS_FINE_LOCATION, Permission.READ_PHONE_STATE). Местоположение (геолокация) включено. Но цикл for cell_info в cell_info_listКод: Выделить всё
from kivy.app import App
if (platform == 'android'):
import android
from android.permissions import request_permissions, Permission
from jnius import autoclass, cast
request_permissions([
Permission.INTERNET,
Permission.ACCESS_NETWORK_STATE,
Permission.ACCESS_COARSE_LOCATION,
Permission.ACCESS_FINE_LOCATION,
Permission.READ_PHONE_STATE,
])
def get_cell_location():
try:
PythonActivity = autoclass('org.kivy.android.PythonActivity')
android_context = PythonActivity.mActivity
TelephonyManager = autoclass('android.telephony.TelephonyManager')
tel_manager = cast('android.telephony.TelephonyManager',
android_context.getSystemService(android_context.TELEPHONY_SERVICE))
cell_info_list = tel_manager.getAllCellInfo()
for cell_info in cell_info_list:
if isinstance(cell_info, autoclass('android.telephony.CellInfoGsm')):
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMcc()
mnc = cell_identity.getMnc()
lac = cell_identity.getLac()
cid = cell_identity.getCid()
network_type = TelephonyManager.NETWORK_TYPE_GSM
elif isinstance(cell_info, autoclass('android.telephony.CellInfoCdma')):
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getSystemId()
mnc = cell_identity.getNetworkId()
lac = cell_identity.getBasestationId()
cid = cell_identity.getBasestationId()
network_type = TelephonyManager.NETWORK_TYPE_CDMA
elif isinstance(cell_info, autoclass('android.telephony.CellInfoLte')):
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMccString()
mnc = cell_identity.getMncString()
lac = cell_identity.getTac()
cid = cell_identity.getCi()
network_type = TelephonyManager.NETWORK_TYPE_LTE
elif isinstance(cell_info, autoclass('android.telephony.CellInfoWcdma')):
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMcc()
mnc = cell_identity.getMnc()
lac = cell_identity.getLac()
cid = cell_identity.getCid()
network_type = TelephonyManager.NETWORK_TYPE_UMTS
elif isinstance(cell_info, autoclass('android.telephony.CellInfoNr')):
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMccString()
mnc = cell_identity.getMncString()
lac = cell_identity.getTac()
cid = cell_identity.getNci()
network_type = TelephonyManager.NETWORK_TYPE_NR
else:
mcc = ""
mnc = ""
lac = ""
cid = ""
network_type = ""
continue
print(f"{mcc}\n{mnc}\n{lac}\n{cid}\n{str(network_type)}")
except Exception as e:
print(str(e))
class MyApp(MDApp):
def __init__(self, * * k w a r g s ) : < b r / > s u p e r ( ) . _ _ i n i t _ _ ( * * k w a r g s ) < b r / > s e l f . s c r e e n = B u i l d e r . l o a d _ s t r i n g ( K V ) < b r / > < b r / > d e f b u i l d ( s e l f ) : < b r / > g e t _ c e l l _ l o c a t i o n ( ) < b r / > r e t u r n s e l f . s c r e e n < b r / > < b r / > i f _ _ n a m e _ _ = = & q u o t ; _ _ m a i n _ _ & q u o t ; : < b r / > M y A p p ( ) . r u n ( ) < b r / > < / c o d e > < b r / > д о п о л н и т е л ь н ы е в о з м о ж н о с т и ф у н к ц и и п о л у ч е н и я < / p > < b r / > < c o d e > d e f g e t _ c e l l _ l o c a t i o n ( ) : < b r / > t r y : < b r / > P y t h o n A c t i v i t y = a u t o c l a s s ( ' o r g . k i v y . a n d r o i d . P y t h o n A c t i v i t y ' ) < b r / > a n d r o i d _ c o n t e x t = P y t h o n A c t i v i t y . m A c t i v i t y < b r / > < b r / > T e l e p h o n y M a n a g e r = a u t o c l a s s ( ' a n d r o i d . t e l e p h o n y . T e l e p h o n y M a n a g e r ' ) < b r / > t e l _ m a n a g e r = c a s t ( ' a n d r o i d . t e l e p h o n y . T e l e p h o n y M a n a g e r ' , < b r / > a n d r o i d _ c o n t e x t . g e t S y s t e m S e r v i c e ( a n d r o i d _ c o n t e x t . T E L E P H O N Y _ S E R V I C E ) ) < b r / > < b r / > c e l l _ i n f o _ l i s t = t e l _ m a n a g e r . g e t A l l C e l l I n f o ( ) < b r / > < b r / > f o r c e l l _ i n f o i n c e l l _ i n f o _ l i s t : < b r / > c e l l _ t y p e = c e l l _ i n f o . g e t _ c e l l _ t y p e ( ) < b r / > i f c e l l _ t y p e = = a u t o c l a s s ( ' a n d r o i d . t e l e p h o n y . C e l l I n f o $ C e l l T y p e ' ) . G S M : < b r / > c e l l _ i d e n t i t y = c e l l _ i n f o . g e t C e l l I d e n t i t y ( ) < b r / > m c c = c e l l _ i d e n t i t y . g e t M c c ( ) , < b r / > m n c = c e l l _ i d e n t i t y . g e t M n c ( ) < b r / > l a c = c e l l _ i d e n t i t y . g e t L a c ( ) < b r / > c i d = c e l l _ i d e n t i t y . g e t C i d ( ) < b r / > n e t w o r k _ t y p e = a u t o c l a s s ( ' a n d r o i d . t e l e p h o n y . T e l e p h o n y M a n a g e r ' ) . N E T W O R K _ T Y P E _ G S M < b r / > e l i f c e l l _ t y p e = = a u t o c l a s s ( ' a n d r o i d . t e l e p h o n y . C e l l I n f o $ C e l l T y p e ' ) . C D M A : < b r / > c e l l _ i d e n t i t y = c e l l _ i n f o . g e t C e l l I d e n t i t y ( ) < b r / > m c c = c e l l _ i d e n t i t y . g e t S y s t e m I d ( ) < b r / > m n c = c e l l _ i d e n t i t y . g e t N e t w o r k I d ( ) < b r / > l a c = c e l l _ i d e n t i t y . g e t B a s e s t a t i o n I d ( ) < b r / > c i d = c e l l _ i d e n t i t y . g e t B a s e s t a t i o n I d ( ) < b r / > n e t w o r k _ t y p e = a u t o c l a s s ( ' a n d r o i d . t e l e p h o n y . T e l e p h o n y M a n a g e r ' ) . N E T W O R K _ T Y P E _ C D M A < b r / > e l i f c e l l _ t y p e = = a u t o c l a s s ( ' a n d r o i d . t e l e p h o n y . C e l l I n f o $ C e l l T y p e ' ) . L T E : < b r / > cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMccString()
mnc = cell_identity.getMncString()
lac = cell_identity.getTac()
cid = cell_identity.getCi()
network_type = autoclass('android.telephony.TelephonyManager').NETWORK_TYPE_LTE
elif cell_type == autoclass('android.telephony.CellInfo$CellType').WCDMA:
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMcc()
mnc = cell_identity.getMnc()
lac = cell_identity.getLac()
cid = cell_identity.getCid()
network_type = autoclass('android.telephony.TelephonyManager').NETWORK_TYPE_UMTS
elif cell_type == autoclass('android.telephony.CellInfo$CellType').NR:
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMccString()
mnc = cell_identity.getMncString()
lac = cell_identity.getTac()
cid = cell_identity.getNci()
network_type = autoclass('android.telephony.TelephonyManager').NETWORK_TYPE_NR
else:
mcc = ""
mnc = ""
lac = ""
cid = ""
network_type = ""
continue
print(f"{mcc}\n{mnc}\n{lac}\n{cid}\n{str(network_type)}")
except Exception as e:
print(str(e))
Код: Выделить всё
def get_cell_location():
try:
PythonActivity = autoclass('org.kivy.android.PythonActivity')
android_context = PythonActivity.mActivity
TelephonyManager = autoclass('android.telephony.TelephonyManager')
tel_manager = cast('android.telephony.TelephonyManager',
android_context.getSystemService(android_context.TELEPHONY_SERVICE))
cell_info_list = tel_manager.getAllCellInfo()
for cell_info in cell_info_list:
cell_type = cell_info.getClass().getSimpleName()
if cell_type == "CellInfoGsm":
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMcc()
mnc = cell_identity.getMnc()
lac = cell_identity.getLac()
cid = cell_identity.getCid()
network_type = TelephonyManager.NETWORK_TYPE_GSM
elif cell_type == "CellInfoCdma":
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getSystemId()
mnc = cell_identity.getNetworkId()
lac = cell_identity.getBasestationId()
cid = cell_identity.getBasestationId()
network_type = TelephonyManager.NETWORK_TYPE_CDMA
elif cell_type == "CellInfoLte":
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMccString()
mnc = cell_identity.getMncString()
lac = cell_identity.getTac()
cid = cell_identity.getCi()
network_type = TelephonyManager.NETWORK_TYPE_LTE
elif cell_type == "CellInfoWcdma":
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMcc()
mnc = cell_identity.getMnc()
lac = cell_identity.getLac()
cid = cell_identity.getCid()
network_type = TelephonyManager.NETWORK_TYPE_UMTS
elif cell_type == "CellInfoNr":
cell_identity = cell_info.getCellIdentity()
mcc = cell_identity.getMccString()
mnc = cell_identity.getMncString()
lac = cell_identity.getTac()
cid = cell_identity.getNci()
network_type = TelephonyManager.NETWORK_TYPE_NR
else:
mcc = ""
mnc = ""
lac = ""
cid = ""
network_type = ""
continue
print(f"{mcc}\n{mnc}\n{lac}\n{cid}\n{str(network_type)}")
except Exception as e:
print(str(e))
Код: Выделить всё
def get_cell_location():
try:
service_state = tel_manager.getServiceState()
cell_location = tel_manager.getCellLocation()
if isinstance(cell_location, autoclass('android.telephony.gsm.GsmCellLocation')):
gsm_cell_location = cell_location
mcc = gsm_cell_location.getMobileCountryCode()
mnc = gsm_cell_location.getMobileNetworkCode()
lac = gsm_cell_location.getLac()
cid = gsm_cell_location.getCid()
network_type = TelephonyManager.NETWORK_TYPE_GSM
elif isinstance(cell_location, autoclass('android.telephony.cdma.CdmaCellLocation')):
cdma_cell_location = cell_location
mcc = service_state.getSystemId()
mnc = service_state.getNetworkId()
lac = cdma_cell_location.getBaseStationId()
cid = cdma_cell_location.getBaseStationId()
network_type = TelephonyManager.NETWORK_TYPE_CDMA
elif isinstance(cell_location, autoclass('android.telephony.CellIdentityLte')):
lte_cell_identity = cell_location
mcc = lte_cell_identity.getMccString()
mnc = lte_cell_identity.getMncString()
lac = lte_cell_identity.getTac()
cid = lte_cell_identity.getCi()
network_type = TelephonyManager.NETWORK_TYPE_LTE
elif isinstance(cell_location, autoclass('android.telephony.CellIdentityWcdma')):
wcdma_cell_identity = cell_location
mcc = wcdma_cell_identity.getMcc()
mnc = wcdma_cell_identity.getMnc()
lac = wcdma_cell_identity.getLac()
cid = wcdma_cell_identity.getCid()
network_type = TelephonyManager.NETWORK_TYPE_UMTS
elif isinstance(cell_location, autoclass('android.telephony.CellIdentityLte')):
nr_cell_identity = cell_location
mcc = nr_cell_identity.getMccString()
mnc = nr_cell_identity.getMncString()
lac = nr_cell_identity.getTac()
cid = nr_cell_identity.getNCi()
network_type = TelephonyManager.NETWORK_TYPE_NR
else:
mcc = ""
mnc = ""
lac = ""
cid = ""
network_type = ""
continue
print(f"{mcc}\n{mnc}\n{lac}\n{cid}\n{str(network_type)}")
except Exception as e:
print(str(e))
Код: Выделить всё
def get_cell_location():
try:
PythonActivity = autoclass('org.kivy.android.PythonActivity')
android_context = PythonActivity.mActivity
cell_info_manager = cast('android.telephony.CellInfoManager', android_context.getSystemService(android_context.CELL_INFO_SERVICE))
# Or try instead of the first lines
# android_context = android_activity.get_context()
# cell_info_manager = cast('android.telephony.CellInfoManager', context.getSystemService(context.CELL_INFO_SERVICE))
cell_info_list = cell_info_manager.getCellInfo()
print(len(cell_info_list))
for cell_info in cell_info_list:
cell_type = type(cell_info)
if cell_type == autoclass('android.telephony.CellInfoGsm'):
gsm_cell_info = cell_info.getCellIdentity()
mcc = gsm_cell_info.getMcc()
mnc = gsm_cell_info.getMnc()
lac = gsm_cell_info.getLac()
cid = gsm_cell_info.getCid()
network_type = 'GSM'
elif cell_type == autoclass('android.telephony.CellInfoCdma'):
cdma_cell_info = cell_info.getCellIdentity()
mcc = cdma_cell_info.getSystemId()
mnc = cdma_cell_info.getNetworkId()
lac = cdma_cell_info.getBasestationId()
cid = cdma_cell_info.getBasestationId()
network_type = 'CDMA'
elif cell_type == autoclass('android.telephony.CellInfoLte'):
lte_cell_info = cell_info.getCellIdentity()
mcc = lte_cell_info.getMccString()
mnc = lte_cell_info.getMncString()
lac = lte_cell_info.getTac()
cid = lte_cell_info.getCi()
network_type = 'LTE'
elif cell_type == autoclass('android.telephony.CellInfoWcdma'):
wcdma_cell_info = cell_info.getCellIdentity()
mcc = wcdma_cell_info.getMcc()
mnc = wcdma_cell_info.getMnc()
lac = wcdma_cell_info.getLac()
cid = wcdma_cell_info.getCid()
network_type = 'WCDMA'
elif cell_type == autoclass('android.telephony.CellInfoNr'):
nr_cell_info = cell_info.getCellIdentity()
mcc = nr_cell_info.getMccString()
mnc = nr_cell_info.getMncString()
lac = nr_cell_info.getTac()
cid = nr_cell_info.getNci()
network_type = 'NR'
else:
mcc = ""
mnc = ""
lac = ""
cid = ""
network_type = ""
continue
print(f"{mcc}\n{mnc}\n{lac}\n{cid}\n{str(network_type)}")
except Exception as e:
print(str(e))
UPD:
Данные тоже есть у меня обновление для башен отключено в инженерном меню. Включение ничего не изменило. Но из документации нужно как-то реализовать запрос на обновление и потом обратный звонок
Подробнее здесь: https://stackoverflow.com/questions/790 ... tower-data
Мобильная версия