November 13th, 2011, 08:53 PM
|
#1 (permalink)
|
|
New Member
Join Date: Sep 2011
Posts: 4
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
|
My applications doesn't recall!
Hello!
I'm developing an application for old man that needs help. One feature of the application is the call-again function.
But the applications doesn't call again and I don't know why!
I have this code:
Code:
public class MainActivity extends Activity {
TelephonyManager tm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}
private void call() {
try {
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
+ "1111111")));
} catch (Exception e) {
e.printStackTrace();
}
}
private PhoneStateListener mPhoneListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
try {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText(MainActivity.this, "CALL_STATE_RINGING",
Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Toast.makeText(MainActivity.this, "CALL_STATE_OFFHOOK",
Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_IDLE:
//(Trying) SystemClock.sleep(10000);
Toast.makeText(MainActivity.this, "CALL_STATE_IDLE",
Toast.LENGTH_SHORT).show(); // This is shown!
call(); // This doesn't call again !
break;
default:
Toast.makeText(MainActivity.this, "default",
Toast.LENGTH_SHORT).show();
Log.i("Default", "Unknown phone state=" + state);
}
} catch (Exception e) {
Log.i("Exception", "PhoneStateListener() e = " + e);
}
}
};
}
Thank-you very very much!
|
|
|