ACTION_ANSWER没有回复

时间:2010-12-08 06:39:06

标签: android android-manifest

我已经写了一个代码,当有人打电话时回答自动...但是这个代码没有回复......当电话来了......

我的代码......这里......

ReceiveCall.java

包com.devindia.receivecall;

import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony。*; import android.util.Log; import android.widget.TextView;

公共类ReceiveCall扩展了Activity {

TelephonyManager telephonyManager;
MyPhoneStateListener listener;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // Get the UI


    try {
        listener = new MyPhoneStateListener();
        // Get the telephony manager
        telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        Log.d("DEBUG", "telephonyManager....called");

        // Register the listener wit the telephony manager
        telephonyManager.listen(listener,
                PhoneStateListener.LISTEN_CALL_STATE);
        Log.d("DEBUG", "Listener REgister.....");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

class MyPhoneStateListener extends PhoneStateListener {

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        Log.d("DEBUG", "Phone listener....");
        String stateString = "N/A";
        switch (state) {
        case TelephonyManager.CALL_STATE_IDLE:
            stateString = "Idle";
            break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
            stateString = "Off Hook";
            break;
        case TelephonyManager.CALL_STATE_RINGING:
            Log.d("DEBUG","Before Answer...");
            stateString = "Ringing"+ incomingNumber;
            Intent myIntent = new Intent(Intent.ACTION_ANSWER);
             myIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP //
                   | Intent.FLAG_DEBUG_LOG_RESOLUTION //
                   | Intent.FLAG_FROM_BACKGROUND //
                   | Intent.FLAG_ACTIVITY_NEW_TASK).addCategory
    (Intent.CATEGORY_DEFAULT);
             startActivity(myIntent); 
            //startActivity((new Intent(Intent.ACTION_ANSWER)));
            Log.d("DEBUG","After Answer...");           
            break;
        }

    }
}

}

的AndroidManifest.xml

                                                                                  

</application>
<use-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-sdk android:minSdkVersion="3" />

1 个答案:

答案 0 :(得分:1)

看看这个link