• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps My applications doesn't recall!

Kanashin

Lurker
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!
 
Back
Top Bottom