0
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 因为我的包是空的,但为什么呢?

4

0 回答 0