我开发了一个应用程序,通过使用以下内容访问日历事件,调用日志和收件箱消息:
cursor = this.contentResolver.query(CallLog.Calls.CONTENT_URI, projection, selection, null, order);
该应用程序在Galaxy SII中完美运行但是当我在XPeria U中安装它时它无法工作,可能是因为该手机以不同的方式管理日历,电话和消息。
如果我必须为世界上的每部手机开发应用程序,这不是一件好事。我尝试了一些像CalendarContract.Events
这样的Android类,但它的API级别太难了,我不希望这样,因为它在大多数手机中都不起作用。有没有一种很好的标准方法可以在大量设备上运行?
谢谢!
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;
}
}
答案 0 :(得分:1)
查看日历提供程序(http://developer.android.com/guide/topics/providers/calendar-provider.html)和联系人提供程序(http://developer.android.com/guide/topics/providers/contacts-provider.html)。
答案 1 :(得分:0)
您可以从此查询中获取日历事件
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");