Manifest:
<receiver android:name=".CallReceiver">
<intent-filter android:priority="100" >
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
code:
public void onReceive(Context context, Intent intent) {
.
.
.
Bundle b = intent.getExtras();
String incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
if(incommingNumber.length()!=0)
{. . . . .}
NullPointer error goes away if i type
String incommingNumber = "123";
any Ideas?
The problem are these lines:
b.getString return null and null.length() throws the error. You need to add a check like this.
This is how getString works:
-> http://developer.android.com/reference/android/os/Bundle.html#getString%28java.lang.String,%20java.lang.String%29
-> http://developer.android.com/reference/android/telephony/TelephonyManager.html