Thursday 31 May 2018

Incoming call listener sleeps after couple of hours

since couple of weeks facing issue with telephony manager api in Android, having listener for incoming call based on listener starting Recording and on end call stopping recording (The process working smoth)

ISSUE
What i am facing issue is that in some mobiles its working all the time, in some of mobile Broadcast listener of telephony manager stops working after few hour, after few research i found solution that use wake-lock for preventing the cpu to sleeps, tried this also but all is vain same issue.

   @Override
public void onReceive(Context context, Intent intent) {
//We listen to two intents.  The new outgoing call only tells us of an 
 //outgoing  call.  We use it to get the number.
    roPlantPrefs = RoPlantPrefs.getInstance(context);
    databaseHelper = new DatabaseHelper(context);
     //lastState = roPlantPrefs.getLastState();

    if (roPlantPrefs.getLogin()) {


        if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
            savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
        } else {

            roPlantPrefs = RoPlantPrefs.getInstance(context);
 //            if (!roPlantPrefs.getIsOnCall()) {

            String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
            String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

            int state = 0;
            if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                state = TelephonyManager.CALL_STATE_IDLE;
            } else if (stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                state = TelephonyManager.CALL_STATE_OFFHOOK;
            } else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                state = TelephonyManager.CALL_STATE_RINGING;
            }


            onCallStateChanged(context, state, number);
        }
    }


   //        }
}      

Also used timer and alarm manger but its work maximum 2 to 3 hours than listener stop working, Any help could be appreciated.



from Incoming call listener sleeps after couple of hours

1 comment:

  1. https://www.wizweb.in

    Wizweb Technology is a leading software development company custom website design, software development, SMS Provider, Bulk sms, transactional sms, promotional sms, mobile app development, Hosting Solution, seo(search engine optimization) and Digital marketing etc.

    ReplyDelete