ダイヤル パッドから番号を取得し、代わりに別の番号を呼び出すアプリを開発しようとしています。しかし、電話をかけたい電話番号で番号形式の例外が発生します。
これがコードです。
public class testing extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
// get phone number from bundle
String phoneNumber = intent.getExtras().getString(Intent.EXTRA_PHONE_NUMBER);
// Toast.makeText(context, "Call: "+phoneNumber+" - ABORTING CALL.", Toast.LENGTH_LONG).show();
//
if (phoneNumber == "") {
phoneNumber = "0";
}
int checknumber = Integer.parseInt(phoneNumber);
if (checknumber == 4444) {
Toast.makeText(context, "hello", Toast.LENGTH_LONG).show();
setResultData(null);
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.setData(Uri.parse("tel:6768886877"));
context.startActivity(callIntent);
}
else {
Toast.makeText(context, "kkkk", Toast.LENGTH_LONG).show();
}
}
}
}
以下は私のエラーのログです
01-04 20:16:24.941: E/AndroidRuntime(28536): java.lang.RuntimeException: Unable to start receiver vu.alhadji.vudial.testing: java.lang.NumberFormatException: Invalid int: "2156689451"
01-04 20:16:24.941: E/AndroidRuntime(28536): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2126)
01-04 20:16:24.941: E/AndroidRuntime(28536): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
01-04 20:16:24.941: E/AndroidRuntime(28536): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
01-04 20:16:24.941: E/AndroidRuntime(28536): at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 20:16:24.941: E/AndroidRuntime(28536): at android.os.Looper.loop(Looper.java:137)
01-04 20:16:24.941: E/AndroidRuntime(28536): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-04 20:16:24.941: E/AndroidRuntime(28536): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 20:16:24.941: E/AndroidRuntime(28536): at java.lang.reflect.Method.invoke(Method.java:511)
01-04 20:16:24.941: E/AndroidRuntime(28536): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:812)
01-04 20:16:24.941: E/AndroidRuntime(28536): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:579)
01-04 20:16:24.941: E/AndroidRuntime(28536): at dalvik.system.NativeStart.main(Native Method)
01-04 20:16:24.941: E/AndroidRuntime(28536): Caused by: java.lang.NumberFormatException: Invalid int: "2156689451"
01-04 20:16:24.941: E/AndroidRuntime(28536): at java.lang.Integer.invalidInt(Integer.java:138)
01-04 20:16:24.941: E/AndroidRuntime(28536): at java.lang.Integer.parse(Integer.java:378)
01-04 20:16:24.941: E/AndroidRuntime(28536): at java.lang.Integer.parseInt(Integer.java:366)
01-04 20:16:24.941: E/AndroidRuntime(28536): at java.lang.Integer.parseInt(Integer.java:332)
01-04 20:16:24.941: E/AndroidRuntime(28536): at vu.alhadji.vudial.testing.onReceive(testing.java:24)
01-04 20:16:24.941: E/AndroidRuntime(28536): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2119)
01-04 20:16:24.941: E/AndroidRuntime(28536): ... 10 more