When we want to get minor and major with this code we get null in both , but in log we get the values :
when we want to get minor and major with this code we get null in both , but in log we get the values :
Beacon firstBeacon = beacons.iterator().next();
Log.i(TAG,"The first beacon " + firstBeacon.toString() + " is about " + firstBeacon.getDistance() + " meters away.");
Log.i(TAG, "The first beacon I see has minor id "+beacons.iterator().next().getId3());
Log.i(TAG, "The first beacon I see has major id "+beacons.iterator().next().getId2());
String minor = beacons.iterator().next().getId3();
String major = beacons.iterator().next().getId2();
You can try
ArrayList<Beacon> mylist = new ArrayList<Beacon>(beacons);
for (int j = 0; j < mylist.size(); j++) {
String rangedUUID = mylist.get(j).getId1().toString();
String rangedMajor = mylist.get(j).getId2().toString();
String rangedMinor = mylist.get(j).getId3().toString();
}
or you can replace this
String minor = beacons.iterator().next().getId3();
String major = beacons.iterator().next().getId2();
with
String minor = firstBeacon.getId3();
String major = firstBeacon.getId2();
Because
beacons.iterator().next()
give next beacon
Related
In my app i send four basic commands to OBD ports and get back hex data...
I don't know why if i send the command:
ME: 010c
Car: 10c410c0000
Why the message don't start with 4?
And get only 410c and the data that the obd receive from car?
I use this method for manage hex response and convert it to human readable data, and RawData is a String that take the message and clear all space, like this
41 0c 00 00 = 410c0000
public String getCalculatedResult() {
//TODO devo convertire i dati da esadecimale a decimale ed effettuare i calcoli
int calculatedData = 0;
String dataToShow = null;
//Log.d("ObdCommand", "rawData: " + rawData.substring(3));
calculatedData = Integer.parseInt(rawData.substring(7), 16);
if (Pattern.compile(Pattern.quote(rawData.substring(3,4)),
Pattern.CASE_INSENSITIVE).matcher("410D").find()){
Log.d("ObdCommand", "dentro 410D: ");
//Velocità veicolo km/h
dataToShow = String.valueOf(calculatedData) + " Km/h";
Log.d("ObdCommand", "rawData: " + dataToShow);
}else if (Pattern.compile(Pattern.quote(rawData.substring(3,4)),
Pattern.CASE_INSENSITIVE).matcher("410C").find()){
Log.d("ObdCommand", "dentro 410C: ");
//Giri minuto veicolo rpm
calculatedData = calculatedData/4;
dataToShow = String.valueOf(calculatedData) + " rpm";
}else if (rawData.substring(3).startsWith("4105")){
//Temperatura refrigetante C°
calculatedData = calculatedData - 40;
dataToShow = String.valueOf(calculatedData) + " C°";
}else if (rawData.substring(3).startsWith("4151")){
//Tipo di carburante
if (rawData.substring(7).startsWith("09")){
//Benzina
dataToShow = "Benzina";
}else if (rawData.substring(7).startsWith("0d")){
//Metano
dataToShow = "Metano";
}
}
return dataToShow;
}
I use the rawData.substring(7) because 3 is the characters that i tell at the start of post
10c
And the other 4 are
410c
So i get only the value that i need to decimal... but sometimes i get outof bound....
Someone have some idea to get this with no problems?
Thanks
hi i have problem in displaying a value into my TextView..
For example i will input 1,2,3,4 then i like to display the output in this manner in my TextView..How can i do that? please help me, thank you in advance
1 appeared 1 times
2 appeared 1 times
3 appeared 1 times
4 appeared 1 times
here's my code:
String []values = ( sum.getText().toString().split(","));
double[] convertedValues = new double[values.length];
Arrays.sort(convertedValues);
int i=0;
int c=0;
while(i<values.length-1){
while(values[i]==values[i+1]){
c++;
i++;
}
table.setText(values[i] + " appeared " + c + " times");
c=1;
i++;
if(i==values.length-1)
table.setText(values[i] + " appeared " + c + " times");
Make your textView to support multipleLines and after that create in code a StringBuffer and append to it the results, something like
resultString.append(result).append(" appeared").append(c).append(" times\n");
after that you set text for textView like:
textView.setText(resultString.toString());
Here is the idea :
// this is test string, you can read it from your textView
String []values = ( "2, 1, 3, 5, 1, 2".toString().split(","));
int [] intValues = new int[values.length];
// convert string values to int
for (int i = 0; i < values.length; ++i) {
intValues[i] = Integer.parseInt(values[i].trim());
}
// sort integer array
Arrays.sort(intValues);
StringBuilder output = new StringBuilder();
// iterate and count occurrences
int count = 1;
// you don't need internal loop, one loop is enough
for (int i = 0; i < intValues.length; ++i) {
if (i == intValues.length - 1 || intValues[i] != intValues[i + 1]) {
// we found end of "equal" sequence
output.append(intValues[i] + " appeared " + count + " times\n");
count = 1; // reset count
} else {
count++; // continue till we count all equal values
}
}
System.out.println(output.toString()); // prints what you extected
table.setText(output.toString()); // display output
Is there any way to access automatically any Log in Logcat by a double click ?
Actually, when there is an error crashing my Android Application, I can double click on the line saying for instance
at com.myapp.mypackage$Class.function(File.java:117)
And by Double-clicking on this line, I am automatically redirected to the related line of my code.
But, when I try to generate the same line in another Log, example :
Log.e("TAG", "at com.myapp.mypackage$Class.function(File.java:117)");
The Double-Click doesn't work anymore ...
Any ideas ?
If you want to create a log in logcat that can be clicked and go to your line use the following method to create it:
Enjoy!
public static void showLogCat(String tag, String msg) {
StackTraceElement[] stackTraceElement = Thread.currentThread()
.getStackTrace();
int currentIndex = -1;
for (int i = 0; i < stackTraceElement.length; i++) {
if (stackTraceElement[i].getMethodName().compareTo("showLogCat") == 0)
{
currentIndex = i + 1;
break;
}
}
String fullClassName = stackTraceElement[currentIndex].getClassName();
String className = fullClassName.substring(fullClassName
.lastIndexOf(".") + 1);
String methodName = stackTraceElement[currentIndex].getMethodName();
String lineNumber = String
.valueOf(stackTraceElement[currentIndex].getLineNumber());
Log.i(tag, msg);
Log.i(tag + " position", "at " + fullClassName + "." + methodName + "("
+ className + ".java:" + lineNumber + ")");
}
If you don't mind the clutter in your log, you can easily just add a new Exception() to the log message
Log.e("TAG", "Looky here see", new Exception());
I am having a string(number) with special characters. I want to search for a sub-string(comprising of digits only) & also I want to detect the starting index & ending index of matching sub-string in the string.
For example: main string: (+91)-1231212 1231
Sub-string to search: 1212
Currently I am using the following code to do this but in place of 1212,it searched for 12312. For other cases, it works fine.
String sss0 = "1212";
String sss1 = "(+91)-1231212 1231";
sss0 = sss0.replaceAll("[^\\d]","");
System.out.println("*************************"+sss0);
String ptn = "" + sss0.charAt(0);
for(int jj=0; jj<sss0.length()-1; jj++){
ptn += "[^" + sss0.charAt(jj) + sss0.charAt(jj+1) + "]*?" + sss0.charAt(jj+1);
}
System.out.println("ptn: " + ptn);
Pattern p300 = Pattern.compile(ptn);
Matcher m300 = p300.matcher(sss1);
if(m300.find()){
System.out.println("start, stop: " + m300.start() + "," + (m300.end()-1 ));
System.out.println("substring: " + sss1.substring(m300.start(), m300.end()));
}
Please help me. Thanks in advance.
Try this :
int start = sss1.indexOf(sss0);
if(start != -1) {
System.out.println("Start : " + start);
System.out.println("End : " + start.length()); //maybe add +1 here depending on what you mean by end index.
}
You can also put this in a loop to find all occurences of the substring.
pseudocode:
pattern = ""
foreach char c in sss0:
pattern += c + "[^0-9]*"
found_substring = match(pattern, sss1)
the idea being to intersperse the literal characters you're looking for with the pattern that you're willing to skip over.
Is there any way to access automatically any Log in Logcat by a double click ?
Actually, when there is an error crashing my Android Application, I can double click on the line saying for instance
at com.myapp.mypackage$Class.function(File.java:117)
And by Double-clicking on this line, I am automatically redirected to the related line of my code.
But, when I try to generate the same line in another Log, example :
Log.e("TAG", "at com.myapp.mypackage$Class.function(File.java:117)");
The Double-Click doesn't work anymore ...
Any ideas ?
If you want to create a log in logcat that can be clicked and go to your line use the following method to create it:
Enjoy!
public static void showLogCat(String tag, String msg) {
StackTraceElement[] stackTraceElement = Thread.currentThread()
.getStackTrace();
int currentIndex = -1;
for (int i = 0; i < stackTraceElement.length; i++) {
if (stackTraceElement[i].getMethodName().compareTo("showLogCat") == 0)
{
currentIndex = i + 1;
break;
}
}
String fullClassName = stackTraceElement[currentIndex].getClassName();
String className = fullClassName.substring(fullClassName
.lastIndexOf(".") + 1);
String methodName = stackTraceElement[currentIndex].getMethodName();
String lineNumber = String
.valueOf(stackTraceElement[currentIndex].getLineNumber());
Log.i(tag, msg);
Log.i(tag + " position", "at " + fullClassName + "." + methodName + "("
+ className + ".java:" + lineNumber + ")");
}
If you don't mind the clutter in your log, you can easily just add a new Exception() to the log message
Log.e("TAG", "Looky here see", new Exception());