1. Download our Official Android App: Forums for Android!

Apps My applications doesn't recall!

Discussion in 'Android Development' started by Kanashin, Nov 13, 2011.

  1. Kanashin

    Kanashin Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    4
    Joined:
    Sep 27, 2011

    Sep 27, 2011
    4
    0
    25
    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 (Text):
    1. public class MainActivity extends Activity {
    2.  
    3.     TelephonyManager tm;
    4.  
    5.     @Override
    6.     public void onCreate(Bundle savedInstanceState) {
    7.         super.onCreate(savedInstanceState);
    8.  
    9.         tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    10.         tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
    11.     }
    12.  
    13.     private void call() {
    14.         try {
    15.             startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
    16.                     + "1111111")));
    17.         } catch (Exception e) {
    18.             e.printStackTrace();
    19.         }
    20.     }
    21.  
    22.     private PhoneStateListener mPhoneListener = new PhoneStateListener() {
    23.         public void onCallStateChanged(int state, String incomingNumber) {
    24.             try {
    25.                 switch (state) {
    26.                 case TelephonyManager.CALL_STATE_RINGING:
    27.                     Toast.makeText(MainActivity.this, "CALL_STATE_RINGING",
    28.                             Toast.LENGTH_SHORT).show();
    29.                     break;
    30.                 case TelephonyManager.CALL_STATE_OFFHOOK:
    31.                     Toast.makeText(MainActivity.this, "CALL_STATE_OFFHOOK",
    32.                             Toast.LENGTH_SHORT).show();
    33.                     break;
    34.                 case TelephonyManager.CALL_STATE_IDLE:
    35.                     //(Trying) SystemClock.sleep(10000);
    36.                     Toast.makeText(MainActivity.this, "CALL_STATE_IDLE",
    37.                             Toast.LENGTH_SHORT).show(); // This is shown!
    38.                     call(); // This doesn't call again !
    39.                     break;
    40.                 default:
    41.                     Toast.makeText(MainActivity.this, "default",
    42.                             Toast.LENGTH_SHORT).show();
    43.                     Log.i("Default", "Unknown phone state=" + state);
    44.                 }
    45.             } catch (Exception e) {
    46.                 Log.i("Exception", "PhoneStateListener() e = " + e);
    47.             }
    48.         }
    49.     };
    50. }
    Thank-you very very much!
     

    Advertisement

Share This Page

Loading...