Get network operator name in Appcelerator Titanium

人盡茶涼 提交于 2020-01-06 19:57:32

问题


I am looking to get the name of the operator for the user's Android device.

E.g. "Verizon" or "Vodafone", I think I have found the Android equivalent documented here called getSimOperatorName() from http://developer.android.com/reference/android/telephony/TelephonyManager.html#getNetworkOperatorName()

I am scanning over the documentation for Appcelerator Titanium, but can't seem to find a way of doing this in the docs (http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network).

Is this possible in Appcelerator Titanium?


回答1:


You can use tinetworkinfo Module

Ex:-

var netInfo = require('com.clever_apps.tinetworkinfo');

var win = Ti.UI.createWindow({exitOnClose: true});

var testLabel = Ti.UI.createLabel({
    height:"80%",
    width:"90%",
    top:0
});

var refreshButton = Ti.UI.createButton({
    title:"Refresh Data",
    height:"15%",
    bottom:"5%"
});
refreshButton.addEventListener("click", getTelephonyData);

win.add(testLabel);
win.add(refreshButton);
getTelephonyData();
win.open();


function getTelephonyData(){
    var imei = netInfo.getIMEI();
    var cellid = netInfo.getCellID();
    var lac = netInfo.getLac();
    var mnc = netInfo.getMNC();
    var mmc = netInfo.getMMC();


    var outString = "IMEI: "+imei+"\nCell ID: "+cellid+"\nLAC: "+lac+"\nMNC: "+mnc+"\nMMC: "+mmc;
    testLabel.text = outString;
}



回答2:


Currently there is no API that will return you that information. For that, you need to create your own Android module.




回答3:


I could not get tinetworkinfo Module working. However, a module named TelephonyManager worked fine.

I ran this in the terminal for the project:

gittio install com.goyya.telephonymanager

Then this code to get the network operator name:

var telephonymanager = require("com.goyya.telephonymanager");
Ti.API.log('networkOperatorName:   ' + telephonymanager.networkOperatorName);


来源:https://stackoverflow.com/questions/35708100/get-network-operator-name-in-appcelerator-titanium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!