Note that there are some explanatory texts on larger screens.

plurals
  1. POLog call information whenever there is a phone call
    primarykey
    data
    text
    <p>I have written the android application and I want the application to send the call information whenever there is an incoming call and it ends. This way I would be sending all calls to the server irrespective of size of the call log.</p> <p>Here is the code </p> <pre><code>public class PhoneInfo extends BroadcastReceiver { private int incoming_call = 0; private Cursor c; Context context; public void onReceive(Context con, Intent intent) { c = con.getContentResolver().query( android.provider.CallLog.Calls.CONTENT_URI, null, null, null, android.provider.CallLog.Calls.DATE + " DESC"); context = con; IncomingCallListener phoneListener = new IncomingCallListener(); TelephonyManager telephony = (TelephonyManager) con .getSystemService(Context.TELEPHONY_SERVICE); telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE); } } public class IncomingCallListener extends PhoneStateListener { public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: if (incoming_call == 1) { CollectSendCallInfo(); incoming_call = 0; } break; case TelephonyManager.CALL_STATE_OFFHOOK: break; case TelephonyManager.CALL_STATE_RINGING: incoming_call = 1; break; } } private void CollectSendCallInfo() { int numberColumn = c .getColumnIndex(android.provider.CallLog.Calls.NUMBER); int dateColumn = c.getColumnIndex(android.provider.CallLog.Calls.DATE); int typeColumn = c.getColumnIndex(android.provider.CallLog.Calls.TYPE); int durationColumn = c .getColumnIndex(android.provider.CallLog.Calls.DURATION); ArrayList&lt;String&gt; callList = new ArrayList&lt;String&gt;(); try { boolean moveToFirst = c.moveToFirst(); } catch (Exception e) { ; // could not move to the first row. return; } int row_count = c.getCount(); int loop_index = 0; int is_latest_call_read = 0; String callerPhonenumber = c.getString(numberColumn); int callDate = c.getInt(dateColumn); int callType = c.getInt(typeColumn); int duration = c.getInt(durationColumn); while ((loop_index &lt; row_count) &amp;&amp; (is_latest_call_read != 1)) { switch (callType) { case android.provider.CallLog.Calls.INCOMING_TYPE: is_latest_call_read = 1; break; case android.provider.CallLog.Calls.MISSED_TYPE: break; case android.provider.CallLog.Calls.OUTGOING_TYPE: break; } loop_index++; c.moveToNext(); } SendCallInfo(callerPhonenumber, Integer.toString(duration), Integer.toString(callDate)); } private void SendCallInfo(String callerPhonenumber, String callDuration, String callDate) { JSONObject j = new JSONObject(); try { j.put("Caller", callerPhonenumber); j.put("Duration", callDuration); j.put("CallDate", callDate); } catch (JSONException e) { Toast.makeText(context, "Json object failure!", Toast.LENGTH_LONG) .show(); } String url = "http://xxxxxx.xxx.xx/xxxx/xxx.php"; Map&lt;String, String&gt; kvPairs = new HashMap&lt;String, String&gt;(); kvPairs.put("phonecall", j.toString()); HttpResponse re; try { re = doPost(url, kvPairs); String temp; try { temp = EntityUtils.toString(re.getEntity()); if (temp.compareTo("SUCCESS") == 0) { ; } else ; } catch (ParseException e1) { Toast.makeText(context, "Parse Exception in response!", Toast.LENGTH_LONG).show(); e1.printStackTrace(); } catch (IOException e1) { Toast.makeText(context, "Io exception in response!", Toast.LENGTH_LONG).show(); e1.printStackTrace(); } } catch (ClientProtocolException e1) { Toast.makeText(context, "Client Protocol Exception!", Toast.LENGTH_LONG).show(); e1.printStackTrace(); } catch (IOException e1) { Toast.makeText(context, "Client Protocol Io exception!", Toast.LENGTH_LONG).show(); e1.printStackTrace(); } } } </code></pre> <p>and here is the manifest file</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.Friend" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.SET_DEBUG_APP"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.RECEIVE_SMS"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.READ_SMS"&gt;&lt;/uses-permission&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".Friend" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".LoginInfo" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;service android:exported="true" android:enabled="true" android:name=".GeoUpdateService"&gt; &lt;/service&gt; &lt;receiver android:name=".SmsInfo"&gt; &lt;intent-filter&gt; &lt;action android:name="android.provider.Telephony.SMS_RECEIVED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;receiver android:name=".PhoneInfo"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.PHONE_STATE"&gt;&lt;/action&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>The application just crashes when there is an incoming call. I have been able to log the information about incoming SMS, but this call info logging is failing.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload