public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
// when Idle i.e no call
if (lastCallState == TelephonyManager.CALL_STATE_OFFHOOK
|| lastCallState == TelephonyManager.CALL_STATE_RINGING) {
lastCallState = TelephonyManager.CALL_STATE_IDLE;
CallsMainFragment.first=true;
Intent intent = context.getPackageManager()
.getLaunchIntentForPackage("com.tabactionbar");
Bundle b=new Bundle();
b.putString("TAB", "2");
intent.putExtras(b);
intent.putExtra("key", "2");
context.startActivity(intent);
}
lastCallState = TelephonyManager.CALL_STATE_IDLE;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
lastCallState = TelephonyManager.CALL_STATE_OFFHOOK;
break;
case TelephonyManager.CALL_STATE_RINGING:
lastCallState = TelephonyManager.CALL_STATE_RINGING;
break;
default:
break;
}
}
那是CustomPhone状态侦听器,在调用之后需要在com.tabactionbar中启动我的活动,这是一个主要的活动,但是
Intent intent=new Intent(getApplicationContex(),MainActivity.class);
那样打电话我真不知道为什么?任何解决方案?
这是我想要的额外内容
try {
Bundle bundle=getIntent().getExtras();
if (bundle.isEmpty()){
Log.e("Bundle", "eMPTY");
}
else {
Log.e("Bundle", bundle.getInt("TAB")+" ... ");
selectedTab=getIntent().getExtras().getInt("TAB");
Log.e("Eroor", " don`t contains key");
}
} catch (Exception e1) {
// TODO Auto-generated catch block
Log.e(e1.getLocalizedMessage()+""+e1.toString(), "Eroor intent");
}
try {
getActionBar().setSelectedNavigationItem(selectedTab);
} catch (Exception e) {
Log.e(e.getLocalizedMessage()+"", "Error tab 2");
// TODO: handle exception
}
捕获NullPointerException,因为我的包是空的,但为什么?