How to get LAC and Cell id for LTE Network - java

i am using GsmCellLocation to get LAC and cell id for 3G network with below code :
mCid = gmsCellLocation.getCid() & 0xffff;
mLac = gmsCellLocation.getLac();
and is there any library or formula how to get/calculate the correct LAC and cell id for LTE network (4G) ? Thanks.

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfoList = telephonyManager.getAllCellInfo();
for (int i = 0; i < cellInfoList.size(); i++) {
if (cellInfoList.get(i) instanceof CellInfoLte) {
CellInfoLte cellInfoLte = (CellInfoLte) cellInfoList.get(i);
mCid = cellInfoLte.getCellIdentity().getCi();
mLac = cellInfoLte.getCellIdentity().getTac();
}
}
Note the method name, it is getCi for LTE. Also, getTac for LTE instead of getLac. See this answer for more.

I hope this might help you :
public class MobileInfoRecognizer {
public String getCellInfo(CellInfo cellInfo) {
String additional_info;
if (cellInfo instanceof CellInfoGsm) {
CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
CellIdentityGsm cellIdentityGsm = cellInfoGsm.getCellIdentity();
additional_info = "cell identity " + cellIdentityGsm.getCid() + "\n"
+ "Mobile country code " + cellIdentityGsm.getMcc() + "\n"
+ "Mobile network code " + cellIdentityGsm.getMnc() + "\n"
+ "local area " + cellIdentityGsm.getLac() + "\n";
} else if (cellInfo instanceof CellInfoLte) {
CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
CellIdentityLte cellIdentityLte = cellInfoLte.getCellIdentity();
additional_info = "cell identity " + cellIdentityLte.getCid() + "\n"
+ "Mobile country code " + cellIdentityLte.getMcc() + "\n"
+ "Mobile network code " + cellIdentityLte.getMnc() + "\n"
+ "physical cell " + cellIdentityLte.getPci() + "\n"
+ "Tracking area code " + cellIdentityLte.getTac() + "\n";
} else if (cellInfo instanceof CellInfoWcdma){
CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
CellIdentityWcdma cellIdentityWcdma = cellInfoWcdma.getCellIdentity();
additional_info = "cell identity " + cellIdentityWcdma.getCid() + "\n"
+ "Mobile country code " + cellIdentityWcdma.getMcc() + "\n"
+ "Mobile network code " + cellIdentityWcdma.getMnc() + "\n"
+ "local area " + cellIdentityWcdma.getLac() + "\n";
}
return additional_info;
}
}

Related

Get value from multiple checkbox's selected and display in TextArea

I will have display all the toppings the user selected and there can be more than one but my code only display one at a time. Please advise.
Here is my code for toppings part:
public String toppingsSelect()
{
String toppingsSelectString = "";
if(tomatoCheckBox.isSelected())
{
toppingsSelectString = "Tomato";
}
if(greenPeppersCheckBox.isSelected())
{
toppingsSelectString = "Green Peppers";
}
if(mushroomsCheckBox.isSelected())
{
toppingsSelectString = "Mushrooms";
}
if(blackOlivesCheckBox.isSelected())
{
toppingsSelectString = "Black Olives";
}
if(sausageCheckBox.isSelected())
{
toppingsSelectString = "Sausage";
}
if(extraCheeseCheckBox.isSelected())
{
toppingsSelectString = "Extra Cheese";
}
return toppingsSelectString;
}
displayString = "Pizza type : " + crustSelect() + "\n" +
"Pizza size : " + sizeSelect() + "\n" +
"Toppings : " + toppingsSelect() + "\n" +
"Amount Due : " + dollarDecimalFormat.format(totalPriceFloat);
outputTextArea.setText(displayString);
Each time you assign a value to toppingsSelectString it replace the precedent value. You should put for exemple toppingsSelectString += " " + "Tomato";

Vaadin Charts Tooltip dynamic formatter

Does Vaadin Charts provide a way for formatting the tooltip on the fly.
I would like to bind some logic to the value presentation on the tooltip.
In place of SOME_STRING, I need reverseNormalization func to alter the values.
Map coefficients = new HashMap();
Chart chart = new Chart(ChartType.LINE);
Configuration conf = chart.getConfiguration();
Tooltip tooltip = conf.getTooltip();
tooltip.setFormatter(
"function() { " +
"return SOME_STRING }"
);
func reverseNormalization(String name, Double normalizedValue) {
return normalizedValue * coefficients.get(name);;
}
Here is an example:
conf.getTooltip().setPointFormatter(
"function() { " +
"var category = this.x; " +
"var multiplier = 10; " +
"switch (category) " +
"{ " +
" case 0: " +
" multiplier = 10; " +
" break; " +
" case 1: " +
" multiplier = 20; " +
" break; " +
" case 2: " +
" multiplier = 30; " +
" break; " +
" default: " +
" multiplier = 50; " +
"}" +
"var tipTxt = this.series.name + ': <b>' + this.y*multiplier + '</b><br>'; " +
"return tipTxt; " +
"}"
);
this.x will give you the category value (starting from zero) of the point which tooltip is presenting. You can use the this.x, this.y and this.series.name to apply your dynamic calculations and format.

Formatting a return string

I am trying to format this return string to display ratings at one decimal place.
return String.format(title + "," + genre + "," + releaseYear + "(" + (getRating() == -1 ? "No ratings" : getRating()) + "): " + numOfDeaths + " deaths");
I keep getting an error saying too few parameters passed.
You want java.text.DecimalFormat.
DecimalFormat df = new DecimalFormat("0.0##");
String result = df.format(getRating());
return String.format(title + "," + genre + "," + releaseYear + "(" + (getRating() == -1 ? "No ratings" : result) + "): " + numOfDeaths + " deaths");

Is there any possibility to get the currentStockLevel from this method?

I need the currentStockLevel for another void Method in java, is there any possibility to get it?
I think no, because of void right?
public void receive (int currentStock)
{
String outLine;
if (currentStockLevel > 0)
outLine = productCode;
{
outLine = ". Current Stock: " + currentStockLevel;
outLine += " Current Stock changed from " + currentStockLevel;
currentStockLevel += currentStock;
outLine += " to " + currentStockLevel;
int storeCost = wholeSalePrice * currentStockLevel;
System.out.println (productCode + ":" + " Received " + currentStockLevel + "." + " Store Cost " + "$" + storeCost + "." + " New stock level: " + currentStockLevel);
}

clearing a JLabel not working [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have read several posts suggesting to clear a JLabel (displayEntered) on a panel (display) with text by using the setText(" "). However, I have tried this and the outcome is it is just posting the array entered twice and does not clear the first set. I have an action shown below when a button is pressed both times; the first is to enter the data entered (I have the same code 4 times for the 4 different possible objects to enter but just put in the one since it's basically the same), which works fine and the second is to remove a specific one shown. My code is long, so am just putting that in. If someone wants something else please let me know. Thanks, I'd appreciate any input!
//adds the Herb data to the Array and list
enterHerbData.addActionListener(new ActionListener(){
#Override
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("Enter")){
Name = NameTxt.getText();
Colors = ColorTxt.getText();
ID = (int) IDCmbo.getSelectedItem();
Flavor = FlavorTxt.getText();
if(((String) MedicinalCmbo.getSelectedItem()).equals("Yes"))
Medicinal = true;
else
Medicinal = false;
if(((String) SeasonalCmbo.getSelectedItem()).equals("Yes"))
Seasonal = true;
else
Seasonal = false;
plants[count] = new Herb(Name, ID, Colors, Flavor, Medicinal, Seasonal);
String displayArraytemp = " ";
if(plants[count] != null){
if(plants[count] instanceof Flower){
displayArraytemp = ((count + 1) + ": " + plants[count].getID() + ", " + plants[count].getName() + ", " + ((Flower)plants[count]).getColor() + ", " + ((Flower)plants[count]).getSmell() + ", Thorny: " + ((Flower)plants[count]).getThorns() + "\n");
}
else if(plants[count] instanceof Fungus){
displayArraytemp = ((count + 1) + ": " + plants[count].getID() + ", " + plants[count].getName() + ", " + ((Fungus)plants[count]).getColor() + ", Poisonous: " + ((Fungus)plants[count]).getPoisonous() + "\n");
}
else if(plants[count] instanceof Weed){
displayArraytemp = ((count + 1) + ": " + plants[count].getID() + ", " + plants[count].getName() + ", " + ((Weed)plants[count]).getColor() + ", Edible: " + ((Weed)plants[count]).getEdible() + ", Medicinal: " + ((Weed)plants[count]).getMedicinal() + ", Poisonous: " + ((Weed)plants[count]).getPoisonous() + "\n");
}
else if(plants[count] instanceof Herb){
displayArraytemp = ((count + 1) + ": " + plants[count].getID() + ", " + plants[count].getName() + ", " + ((Herb)plants[count]).getColor() + ", " + ((Herb)plants[count]).getFlavor() + ", Medicinal: " + ((Herb)plants[count]).getMedicinal() + ", Poisonous: " + ((Herb)plants[count]).getSeasonal() + "\n");
}
sb.append("<html>" + displayArraytemp).
append("<br> ");
displayArray = sb.toString();
}
displayEntered.setText(displayArray);
count++;
frameB.setVisible(false);
}
}
});
//removes the data to the Array and panel
ActionListener RemoveAction = new ActionListener(){
#Override
public void actionPerformed(ActionEvent RemoveAction){
if(RemoveAction.getActionCommand().equals("Enter")){
if((Btn1).isSelected()){
String displayArraytemp2 = " ";
if(count >= 1){
for(int n = 0; n < count; n++){
plants[n] = plants[n+1];
}
count--;
frameB.setVisible(false);
displayEntered.setOpaque(true);
for(int n = 0; n < 25; n++){
if(plants[n] != null){
if(plants[n] instanceof Flower){
displayArraytemp2 = ((n + 1) + ": " + plants[n].getID() + ", " + plants[n].getName() + ", " + ((Flower)plants[n]).getColor() + ", " + ((Flower)plants[n]).getSmell() + ", Thorny: " + ((Flower)plants[n]).getThorns() + "\n");
}
else if(plants[n] instanceof Fungus){
displayArraytemp2 = ((n + 1) + ": " + plants[n].getID() + ", " + plants[n].getName() + ", " + ((Fungus)plants[n]).getColor() + ", Poisonous: " + ((Fungus)plants[n]).getPoisonous() + "\n");
}
else if(plants[n] instanceof Weed){
displayArraytemp2 = ((n + 1) + ": " + plants[n].getID() + ", " + plants[n].getName() + ", " + ((Weed)plants[n]).getColor() + ", Edible: " + ((Weed)plants[n]).getEdible() + ", Medicinal: " + ((Weed)plants[n]).getMedicinal() + ", Poisonous: " + ((Weed)plants[n]).getPoisonous() + "\n");
}
else if(plants[n] instanceof Herb){
displayArraytemp2 = ((n + 1) + ": " + plants[n].getID() + ", " + plants[n].getName() + ", " + ((Herb)plants[n]).getColor() + ", " + ((Herb)plants[n]).getFlavor() + ", Medicinal: " + ((Herb)plants[n]).getMedicinal() + ", Poisonous: " + ((Herb)plants[n]).getSeasonal() + "\n");
}
sb.append("<html>" + displayArraytemp2).
append("<br> ");
displayArray = sb.toString();
}
}
}
displayEntered.setText(" ");
displayEntered.setText(displayArray);
}
}
}};
Your real problem is that you are re-using sb without clearing it.

Categories

Resources