-1
我是Android新手,需要阅读手机的通话状态。我收到错误,当应用程序运行(停止):ANdroid开发 - 手机的通话状态
package com.example.droid1;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.TextView;
import android.widget.Toast;
public class DroidActivity extends Activity {
private TextView text0;
private TelephonyManager telephoneM;
private PhoneStateListener listner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_droid);
text0 = (TextView) findViewById(R.id.textout);
telephoneM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
listner = new PhoneStateListener()
{
public void onCallStateChanged(int state, String incomingnumber) {
String stateS = "N/A";
switch(state) {
case TelephonyManager.CALL_STATE_IDLE:
stateS = "Oscioso";
Toast.makeText(DroidActivity.this, ""+stateS,Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
stateS = "Sonando";
Toast.makeText(DroidActivity.this, ""+stateS,Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
stateS = "Ocupado";
Toast.makeText(DroidActivity.this, ""+stateS,Toast.LENGTH_SHORT).show();
break;
}
text0.append (String.format("\nonCallStateChanged: %s",stateS));
}
};
telephoneM.listen(listner, PhoneStateListener.LISTEN_CALL_STATE);
}
}
我没有在Eclipse中的任何错误信息,应用程序无需安装虚拟设备上的问题,但是,当它运行我的错误消息“不幸的是Droid1已停止“ 任何意见将不胜感激。 Thx
尝试显示您的logcat。 – R4j 2012-08-08 02:37:25