Reputation: 800
I've developed an application that accesses calendar events, call logs and inbox messages by using things like this:
cursor = this.contentResolver.query(CallLog.Calls.CONTENT_URI, projection, selection, null, order);
The app works perfectly in Galaxy SII but when I installed it in XPeria U it don't worked, probably because that phone manages calendars, calls and messages in a different way.
If I have to develop an application to each phone in the world, this is not a good business. I tried some Android classes like CalendarContract.Events
but its API level is too hard and I don't want that because it won't work in most phones. Is there a good standard way to tho this that works on a high number of devices?
Thanks!
package bembibre.coolstar.windowsmobilewidget.backend;
import java.util.ArrayList;
import java.util.List;
import bembibre.coolstar.windowsmobilewidget.apiindependent.ApiIndependentCallLog;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.provider.CallLog;
import android.util.Log;
public class CallsContentResolver {
public static final String[] projection = {
CallLog.Calls.CACHED_NAME,
CallLog.Calls.DATE,
};
public static final String selection = "((" + CallLog.Calls.TYPE + " = " +
CallLog.Calls.MISSED_TYPE + ") AND NOT(" +
ApiIndependentCallLog.instance().CALLS_IS_READ + "))";
private static final int MAX_NUM_CALLS = 3;
private static final String order = CallLog.Calls.DATE + " DESC LIMIT " + MAX_NUM_CALLS;
private ContentResolver contentResolver;
public CallsContentResolver(Context ctx) {
this.contentResolver = ctx.getContentResolver();
}
public void readCursor(List<Call> calls, Cursor cursor){
while (cursor.moveToNext()) {
String cached_name = cursor.getString(cursor.getColumnIndex(
CallLog.Calls.CACHED_NAME)
);
long date = cursor.getLong(cursor.getColumnIndex(
CallLog.Calls.DATE)
);
Call call = new Call(cached_name, date);
calls.add(0, call);
}
}
public List<Call> getMissedCalls(){
List<Call> calls = new ArrayList<Call>();
Cursor cursor = null;
try{
cursor = this.contentResolver.query(CallLog.Calls.CONTENT_URI, projection, selection, null, order);
if(cursor.getCount() > 0) {
this.readCursor(calls, cursor);
}
}
catch(Exception e){
Log.d("EXCEPCIÓN", e.getMessage());
}
finally{
if(cursor != null){
cursor.close();
}
}
return calls;
}
}
Upvotes: 0
Views: 284
Reputation: 317
You can fetch the calender event from this query where
long after = date.getTime();
long current = new Date().getTime();
long millisOfOne = 1000;
long millisOftwoFour = 1000 * 60 * 60 * 24;
long millisOfTodayLast = date.getTime() + millisOftwoFour
- millisOfOne;
Cursor cursor = context.getContentResolver().query(Uri.parse("content://com.android.calendar/events"),new String[] { "calendar_id", "title", "description","dtstart", "dtend", "eventLocation", "_id" },"dtstart >=" + after + " and dtstart<" + millisOfTodayLast,
null, "dtstart ASC");
Upvotes: 0
Reputation: 1049
have a look at Calendar Provider (http://developer.android.com/guide/topics/providers/calendar-provider.html) and Contacts Provider (http://developer.android.com/guide/topics/providers/contacts-provider.html).
Upvotes: 1