the if statement in the function getCallDetailsAgil() is not working. the statement is in the switch case where it is checking if the call type is MISSED
Can anyone please help me out? startdate and enddate are publiic date objects. i am just trying to ocunt all missed calls between thos two dates.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_incoming);
Intent i = getIntent();
//
}
private int getCallDetailsAgil() {
StringBuffer sb = new StringBuffer();
Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null, null, null, null);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int count=0;
while (managedCursor.moveToNext()) {
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
Date dc = new Date(Long.valueOf(callDate));
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.INCOMING_TYPE:
System.out.println("---------" + startdate.toString());
System.out.println(dc.toString());
System.out.println("---------" + enddate.toString());
System.out.println(dc.before(startdate)+" "+dc.before(enddate));
if (dc.before(startdate) && dc.before(enddate))
count++;
break;
}
}
return count;
}
Related
I have a recording call app in which i would like to track the call duration in realtime , i have looked up some codes online but none of them does what i want , i'm here seeking help from those who are expert in this , any way to do that please , Thank you .
Basically when the call is answered , track call timing 0 1 2 3 and so on .
Tried this code but only gets the final duration
private void getCallDetails() {
StringBuffer sb = new StringBuffer();
Uri contacts = CallLog.Calls.CONTENT_URI;
Cursor managedCursor = this.getContentResolver().query(contacts, null, null, null, null);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
sb.append("Call Details :");
while (managedCursor.moveToNext()) {
HashMap rowDataCall = new HashMap<String, String>();
String phNumber = managedCursor.getString(number);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
String callDayTime = new Date(Long.valueOf(callDate)).toString();
// long timestamp = convertDateToTimestamp(callDayTime);
String callDuration = managedCursor.getString(duration);
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
Log.d("TAG","Call Duration" + callDuration);
}
managedCursor.close();
System.out.println(sb);
}
I want to add call logs in List
my code working fine but it's showing only one call log,
any solution for it,
I am beginner please check my code image and help me.
[1]: https://i.stack.imgur.com/joGU1.png
//Recycler Function
recyclerView_cl = view.findViewById(R.id.receyclerView_cl);
LinearLayoutManager LayoutManager = new LinearLayoutManager(view.getContext());
LayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView_cl.setLayoutManager(LayoutManager);
Cursor managedCursor = getActivity().managedQuery(CallLog.Calls.CONTENT_URI, null,
null, null, null);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
while (managedCursor.move(3)) {
List<CallModelClass> modelClassList = new ArrayList<>();
CallAdapter adapter = new CallAdapter(modelClassList);
modelClassList.add(new CallModelClass("name from", "call type", "sasa"));
recyclerView_cl.setAdapter(adapter);
adapter.notifyDataSetChanged();
String phNumber = managedCursor.getString(number);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
Date callDayTime = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString(duration);
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
modelClassList.add(new CallModelClass(phNumber,dir,callDate));
}
managedCursor.close();
Move these two lines out of your while loop(put theme above the loop call):
List<CallModelClass> modelClassList = new ArrayList<>();
CallAdapter adapter = new CallAdapter(modelClassList);
And also, call this: adapter.notifyDataSetChanged(); after your while loop end.
I want to get the call log history by today, yesterday, last seven days and last 30days along with that i want to show the total duration of incoming and outgoing calls of that particular number.
I tried with various type but none of them working. What should i do to get the output ?.I have no idea how to use the query to get the call log from specific date. Help me Thanks
public class CallLogActivity extends Activity {
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call_log);
textView = (TextView) findViewById(R.id.textCallBetween);
textView.setVisibility(View.GONE);
// listcallLog = (ListView) findViewById(R.id.calllogItems);
getCalldetails();
}
public void getCalldetails() {
StringBuffer stringBuffer = new StringBuffer();
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
Calendar calender = Calendar.getInstance();
calender.set(2016, calender.NOVEMBER, 18);
String fromDate = String.valueOf(calender.getTime());
calender.set(2016, Calendar.NOVEMBER, 20);
String toDate = String.valueOf(calender.getTimeInMillis());
String[] whereValue = {fromDate,toDate};
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, android.provider.CallLog.Calls.DATE + " BETWEEN ? AND ?", whereValue, strOrder);
// Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null, android.provider.CallLog.Calls.DATE, new String[]{" BETWEEN ? AND ?"}, strOrder);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
stringBuffer.append("Call Log :");
while (managedCursor.moveToNext())
{
String phoneNumber = managedCursor.getString(number);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
SimpleDateFormat formatter = new SimpleDateFormat(
"dd-MMM-yyyy HH:mm");
String dateString = formatter.format(new Date(Long
.parseLong(callDate)));
// Date callDayTime = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString(duration);
String dir = null;
int dirCode = Integer.parseInt(callType);
switch (dirCode)
{
case CallLog.Calls.OUTGOING_TYPE :
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED CALL";
break;
}
stringBuffer.append("\nPhone Number:--- " + phoneNumber + "\nCall Type:--- "
+ dir + "\nCall Date:---"
+ dateString + "\nCall Duration:---" + callDuration);
stringBuffer.append("\n--------------------------");
}
textView.setText(stringBuffer);
textView.setVisibility(View.VISIBLE);
}`
}
The below code is the solution for getting call log data between two dates.
public class CallLogActivity extends Activity {
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call_log);
textView = (TextView) findViewById(R.id.textCallBetween);
textView.setVisibility(View.GONE);
// listcallLog = (ListView) findViewById(R.id.calllogItems);
getCalldetails();
}
public void getCalldetails() {
StringBuffer stringBuffer = new StringBuffer();
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
Calendar calender = Calendar.getInstance();
calender.set(2016, calender.NOVEMBER, 18);
String fromDate = String.valueOf(calender.getTimeInMillis());
calender.set(2016, calender.NOVEMBER, 20);
String toDate = String.valueOf(calender.getTimeInMillis());
String[] whereValue = {fromDate,toDate};
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, android.provider.CallLog.Calls.DATE + " BETWEEN ? AND ?", whereValue, strOrder);
// Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null, android.provider.CallLog.Calls.DATE, new String[]{" BETWEEN ? AND ?"}, strOrder);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
stringBuffer.append("Call Log :");
while (managedCursor.moveToNext())
{
String phoneNumber = managedCursor.getString(number);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
SimpleDateFormat formatter = new SimpleDateFormat(
"dd-MMM-yyyy HH:mm");
String dateString = formatter.format(new Date(Long
.parseLong(callDate)));
// Date callDayTime = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString(duration);
String dir = null;
int dirCode = Integer.parseInt(callType);
switch (dirCode)
{
case CallLog.Calls.OUTGOING_TYPE :
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED CALL";
break;
}
stringBuffer.append("\nPhone Number:--- " + phoneNumber + "\nCall Type:--- "
+ dir + "\nCall Date:---"
+ dateString + "\nCall Duration:---" + callDuration);
stringBuffer.append("\n--------------------------");
}
textView.setText(stringBuffer);
textView.setVisibility(View.VISIBLE);
}
}
go step by step . first get all call log history this way.
Uri allCalls = Uri.parse("content://call_log/calls");
Cursor c = managedQuery(allCalls, null, null, null, null);
String num= c.getString(c.getColumnIndex(CallLog.Calls.NUMBER));// for number
String name= c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME));// for name
String duration = c.getString(c.getColumnIndex(CallLog.Calls.DURATION));// for duration
int type = Integer.parseInt(c.getString(c.getColumnIndex(CallLog.Calls.TYPE)));// for call type, Incoming or out going.
I have a problem with my TotalCalendar class. In this class I'm adding every events ( for example: 20 events ) to my own calendar. I should add this events to Google Calendar, but stil it's adding to device calendar. How can I change it? When I put single event to calendar, I can choose kind of calendar, but in this situation, I can't.
public class TotalCalendar {
Context mContext;
Intent mIntent;
public TotalCalendar(Context context) {
this.mContext = context;
}
public boolean insert(String dzien, String miesiac, String lokacja, String tytul, String opis, String godziny) {
int year = Calendar.getInstance().get(Calendar.YEAR);
Calendar beginTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
int currentMonth = Calendar.getInstance().get(Calendar.MONTH);
if((Miesiac(miesiac) == 0) && (currentMonth == 11) )
{
year++;
}
int hh1 = 0;
int mm1 = 0;
int hh2 = 0;
int mm2 = 0;
if(isNumeric(getHH1(godziny)) && isNumeric(getMM2(godziny)))
{
Log.d("debug","numeric");
hh1 = Integer.valueOf(getHH1(godziny)).intValue();
mm1 = Integer.valueOf(getMM1(godziny)).intValue();
hh2 = Integer.valueOf(getHH2(godziny)).intValue();
mm2 = Integer.valueOf(getMM2(godziny)).intValue();
}
else
{
hh1 = 0;
mm1 = 0;
hh2 = 0;
mm2 = 0;
}
beginTime.set(year, Miesiac(miesiac), Integer.valueOf(dzien).intValue(), hh1, mm1);
endTime.set(year, Miesiac(miesiac), Integer.valueOf(dzien).intValue(), hh2, mm2);
Log.d("debug", "Begin time: " + Miesiac(miesiac) + " " + Integer.valueOf(dzien));
long startMillis = beginTime.getTimeInMillis();
long endMillis = endTime.getTimeInMillis();
ContentResolver cr = mContext.getContentResolver();
ContentValues values = new ContentValues();
TimeZone tz = TimeZone.getDefault();
values.put(CalendarContract.Events.DTSTART, startMillis);
values.put(CalendarContract.Events.DTEND, endMillis);
values.put(CalendarContract.Events.TITLE,tytul);
values.put(CalendarContract.Events.DESCRIPTION,opis);
values.put(CalendarContract.Events.CALENDAR_ID,1);
values.put(CalendarContract.Events.EVENT_TIMEZONE,tz.getID());
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI,values);
Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, startMillis);
this.mIntent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(mIntent);
return true;
}
I'm working on an Android app. I need to get call log to get info about outcoming calls. I´m using this one (from some topic here):
private void getCallDetails() {
StringBuffer sb = new StringBuffer();
Cursor managedCursor = managedQuery( CallLog.Calls.CONTENT_URI,null, null,null, null);
int number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER );
int type = managedCursor.getColumnIndex( CallLog.Calls.TYPE );
int date = managedCursor.getColumnIndex( CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex( CallLog.Calls.DURATION);
sb.append( "Call Details :");
while ( managedCursor.moveToNext() ) {
String phNumber = managedCursor.getString( number );
String callType = managedCursor.getString( type );
String callDate = managedCursor.getString( date );
Date callDayTime = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString( duration );
String dir = null;
int dircode = Integer.parseInt( callType );
switch( dircode ) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
sb.append( "\nPhone Number:--- "+phNumber +" \nCall Type:--- "+dir+" \nCall Date:--- "+callDayTime+" \nCall duration in sec :--- "+callDuration );
sb.append("\n----------------------------------");
}
managedCursor.close();
call.setText(sb);
}
I can use this newer code too:
Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI,null, null,null, null);
but in both examples my app crashes on phone even on emulator. I tried to fix that only think I find out is that this query line is the problem but only with CallLog.
When I use similar code with sms for example everythink is working fine.
public StringBuffer getOutgoingSMSContent() {
ContentResolver contentResolver = getContentResolver();
Uri uri = Uri.parse("content://sms/sent/");
StringBuffer messagedata = new StringBuffer();
int count = 0;
Cursor cursor = contentResolver.query(uri, null, null, null, null);
if (cursor.getCount() != 0) {
if (cursor.moveToFirst()) {
do {
messagedata.append("Outgoing message count: " + (count + 1)
+ "\n");
for (int m = 0; m < cursor.getColumnCount(); m++) {
if (cursor.getColumnName(m).equalsIgnoreCase("address")
|| cursor.getColumnName(m).equalsIgnoreCase(
"date")
|| cursor.getColumnName(m).equalsIgnoreCase(
"body")
|| cursor.getColumnName(m).equalsIgnoreCase(
"type")) {
messagedata.append(cursor.getColumnName(m) + " : "
+ cursor.getString(m));
messagedata.append("\n");
}
}
messagedata.append("\n");
count++;
} while (cursor.moveToNext());
}
}
cursor.close();
cursor = null;
return messagedata;
}
Any idea?