How to detect unknown phone number in call logs (android provider) - android

I would like to detect the unknown phone number in my call logs list.
An unknown number on the phone is either -1 or -2.
My question is how to detect this type of call?.
I try to detect with :
number = Integer.parseInt(number);
if(number < 0){
}
but it is not working.

Try the following:
1) Log everything.
Put
Log.debug("ClassName", "number = " +number);
2) number = Integer.parseInt(number);
does not look quite right.
try
assuming incomingPhoneNumber is defined as a String.
String incomingPhoneNumber;
try{
int phoneNumber = Integer.parseInt(incomingPhoneNumber);
}catch (Exception e) {
Log.debug("ClassName", "error = "+e.getMessage());
}
in eclipse you need to goto window -->Show View --> Logcat to and examine the log message but you should also just set breakpoints and run in debug mode. Step one line at a time.
Tell us if you get a negative number for the incoming call.
3) Place breakpoints at the very beginning and run in debug mode. Tell us what you get.
4) Communicate with the user questions. People are trying to help but you need to answer our questions for us to help you. For example we do need to see the definition for number to know if
the code is going to work.

Related

Check if RS232 response contains malformed chars

I have android platform on one end and arduino on the other, connected via serial. Everything works fine, however in some cases arduino restarts itself and causes a flow of unknown characters while its restarting to the serial.
Here is a serial log while arduino is rebooting:
�z������"&O�Z&���B
���F ���cd�:{����t�>��+������2�~����. ���r���DD���^��.�.B�.��ڮ2t��Z:��,R��A�ڢr��Ckˡ���.-���N^���b�����^���
Question is, how can I check on android end if the response was malformed?
You should probably add some kind of "framing" to your messages. CR/LF isn't enough.
For example, put a special "preamble" at the front, and watch for it on the Android side. Choose something that will not occur in the body ("payload") of the message. And choose something that is very unlikely to occur in the random chars that show up on a reboot, a couple of chars long.
You could also put a CRC at the end. "Fletcher" is easy.
I ended up using simple solution like this:
private String filterData(String receivedStr) {
if (receivedStr.contains(RECV_HEADER) && receivedStr.contains(mReadRules.RECV_END)) {
int header_pos = receivedStr.indexOf(RECV_HEADER);
int crc_pos = receivedStr.indexOf(RECV_END);
return receivedStr.substring(header_pos, crc_pos);
} else {
return null;
}
}
It also extracts message if its wrapped around with malformed data.

how reliable is android Build.SERIAL

I have an app that checks the value returned by Build.SERIAL, and then uses that as a sort of validation when transferring data between the app and the website. Everything is working fine except for occasionally a user is unable to connect. In the docs it says Build.SERIAL returns the serial id if available, My question is does this mean that some devices will have it and some won't, or does it mean that a device may be able to retrieve it at some times, and others it won't?
I was assuming its the first, but I'm have users that are having an issue with it and I cannot repeat it. And when I tried searching for more information on what exactly "If available" meant I couldn't really find anything.
EDIT Just for more clarification, I have a user that has a serial id and can use the software just fine. The problem is occasionally he gets an error saying the serial id is not registered, I have not been able to recreate the problem so I am only guessing that the device sometimes does not grab the serial id. I was wondering if anyone could confirm that this is, or is not, an issue. I have already put some things in place to catch the error if it happens again, but it seems to be randomly happening.
EDIT 2 So i found out that the Build.serial is still returning the serial id so that is not the problem, ill eventually figure it out, but for now I'll just leave this question up until someone can explain when it is or isn't available in case it helps someone in the future.
Build.SERIAL can be empty or sometimes return a different value (proof 1, proof 2) than what you can see in your device's settings.
There are several ways to get that number depending on the device's manufacturer and Android version, so I decided to compile every possible solution I could found in a single gist. Here's a simplified version of it :
public static String getSerialNumber() {
String serialNumber;
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serialNumber = (String) get.invoke(c, "gsm.sn1");
if (serialNumber.equals(""))
serialNumber = (String) get.invoke(c, "ril.serialnumber");
if (serialNumber.equals(""))
serialNumber = (String) get.invoke(c, "ro.serialno");
if (serialNumber.equals(""))
serialNumber = (String) get.invoke(c, "sys.serialnumber");
if (serialNumber.equals(""))
serialNumber = Build.SERIAL;
// If none of the methods above worked
if (serialNumber.equals(""))
serialNumber = null;
} catch (Exception e) {
e.printStackTrace();
serialNumber = null;
}
return serialNumber;
}
I try to update the gist regularly whenever I can test on a new device or Android version. Contributions are welcome too.

Why does logcat ignore log statements with tag "PHONE"?

I was setting a listener on my call button and at first I just wanted to make sure that the listener was working, so I put a log statement inside of it. But for some mysterious reason, it refused to print when I clicked it! So maybe the call button was null, I thought, and added an else statement...but it didn't print anything from either the if or the else statement!!! It would print the statements before and after, but totally ignore everything in the if-else structure. Here's the code:
ImageButton call = (ImageButton) v.findViewById(R.id.callButton);
Log.d("MEETINGS", "ABOUT TO WORK W/ CALL");
Log.e("MEETINGS", "" + (call != null));
if (call != null) {
Log.d("PHONE", "setting stuff on call...");
call.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d("PHONE", "on call : " + phone);
}
});
} else {
System.out.println("why is this messed up");
Log.d("PHONE", "call button was null!");
}
System.out.println("what the heck is going on");
After at least 15 minutes of trying to unravel the mystery of how Java could just decide to skip both the if and the else, I tried giving the log statement a different tag.
And eureka! That did the trick! I changed "PHONE" to "BLAH" and suddenly the world made sense again! Curious, I changed it to "phone" and it refuses to print again.
Moral of the story: never use the tag "phone" or "PHONE" in logcat!!!
Can someone please explain to me how and/or why logcat ignores messages with the tag "PHONE"?
See the documentation for isLoggable(). I'm guessing debug output for the "PHONE" tag has been disabled on your phone to suppress output from the actual phone application.
I believe you should be able to run "getprop log.tag.PHONE" in a shell on the phone to retrieve the minimum severity level required for messages tagged "PHONE" to be printed.

Getting next alarm information when there is no such function

I have this code in my app
Alarm1 = Settings.System.getString(getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED);
Its working on htcs,motorolas,but not on galaxy s phones.The application crashes.
Would the following catch the error without crashing the application service?
String Alarm1=null;
try{
Alarm1 = Settings.System.getString(getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED);
}
catch (Exception e) {
Log.i("Exception", "Exception next alarm not found = " + e);
}
if (TextUtils.isEmpty(Alarm1)) {
//if i am i here either no alarm is set or couldn't read it from the phone
//do something else
}
Unless there is a different code for the galaxy s, and can i find it.How can i make it throw an exception on a phone that works, for testing purposes?Thanks.
I have the same problem on a widget i developed, it seems that on Galaxy S there is no entry on settings.db with ID NEXT_ALARM_FORMATTED, this makes the app crash. Sadly using try/catch it's not enough to solve the issue, widget still crashes.
I don't have a Galaxy S to debug the issue, if you find any workaround (other than inserting using sqlite3 the row con settings.db) let me know. Maybe you can try to simulate this behaviour by passing an invalid ID to the Settings function, i will try later today...
P.S. To temporary fix this on galaxy s you can (via adb shell)
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
UPDATE "system" SET value='' WHERE name='next_alarm_formatted';
Settings.System.NEXT_ALARM_FORMATTED is deprecated since API 21. Use the following instead:
AlarmManager.AlarmClockInfo alarmInfo = am.getNextAlarmClock();
where am is an instance of AlarmManager.

How to check if vibration happened, in logcat?

I searched in the web but i couldn find a single article dealing in a straight forward way on how to find the vibrate on/off logs in logcat. If anybody who is aware of the procedure, please enlighten me. Once again i need it specifically to check if my app triggers vibrator or not...
Vibration data is not logged by default. Fortunately, there is some code in HardwareServices.java that can be enabled to provide exactly what you want. Keep in mind that since this is part of the framework, changing it will require you to rebuild and reflash your device. If you are running on an ADP or the emulator this should be easy. It might be a bit more challenging if you are doing this on another device.
Locate the following code and replace false with true and you should be all set.
if (false) {
String s = "";
int N = pattern.length;
for (int i=0; i<N; i++) {
s += " " + pattern[i];
}
Log.i(TAG, "vibrating with pattern: " + s);
}

Categories

Resources