java制作android 日歷代碼分享
更新時間:2015年03月19日 15:34:17 投稿:hebedich
本文給大家分享的是一段使用java制作Android日歷的代碼,非常簡單實(shí)用,實(shí)現(xiàn)了讀取日歷事件、插入事件、編輯日歷事件、查看日歷等功能,有需要的小伙伴參考下
代碼很簡單,就不多廢話了
復(fù)制代碼 代碼如下:
//讀取日歷事件
public static void getCalendarInfo(Activity activity,String tag){
String[] projection = new String[]{CalendarContract.Events._ID,CalendarContract.Events.TITLE};
ContentResolver cr = activity.getContentResolver();
Cursor cursor = cr.query(CalendarContract.Events.CONTENT_URI, projection, null, null, null);
int idIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events._ID);
Log.d(tag, cursor.getCount()+"");
int titleIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events.TITLE);
while (cursor.moveToNext()) {
String id = cursor.getString(idIndex);
String title = cursor.getString(titleIndex);
Log.d(tag, id+":"+title);
}
cursor.close();
}
//插入事件
public static void addCalendarEvent(Activity activity,String tag){
Intent intent = new Intent(Intent.ACTION_INSERT,CalendarContract.Events.CONTENT_URI);
Log.d(tag, CalendarContract.Events.CONTENT_URI.toString());
intent.putExtra(CalendarContract.Events.TITLE, "Launch");
intent.putExtra(CalendarContract.Events.DESCRIPTION, "Launch,Android app");
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, "baidu.com");
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calendar.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
activity.startActivity(intent);
}
//編輯日歷事件
public static void editCalendarEvent(Activity activity,String tag){
long rowId = 1;
Uri editUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI,rowId);
Log.d(tag, CalendarContract.Events.CONTENT_URI.toString());
Intent intent = new Intent(Intent.ACTION_EDIT,editUri);
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, "NJ");
Calendar calendar = Calendar.getInstance();
calendar.set(2015, 2, 17, 12, 1, 1);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calendar.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
activity.startActivity(intent);
}
//查看日歷
public static void viewCalendar(Activity activity,String tag){
Calendar calendar = Calendar.getInstance();
calendar.set(2015, 2, 17, 12, 1, 1);
Uri uri = Uri.parse("content://com.android.calendar/time/"+calendar.getTimeInMillis());
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
activity.startActivity(intent);
}
以上就是本文給大家分享的全部代碼了,希望對大家學(xué)習(xí)java能夠有所幫助。
您可能感興趣的文章:
- 日歷顯示讀出輸入的年月的java代碼
- Java中的Calendar日歷API用法完全解析
- Java實(shí)現(xiàn)的日歷功能完整示例
- Java實(shí)現(xiàn)簡單日歷小程序 Java圖形界面小日歷開發(fā)
- java實(shí)現(xiàn)日歷(某年的日歷,某月的日歷)用戶完全自定義
- 學(xué)習(xí)Java中的日期和時間處理及Java日歷小程序的編寫
- JavaWeb項(xiàng)目FullCalendar日歷插件使用的示例代碼
- Java Calendar日歷與Date日期的相互轉(zhuǎn)換詳解
- Java實(shí)現(xiàn)按年月打印日歷功能【基于Calendar】
- Java實(shí)現(xiàn)窗體程序顯示日歷
相關(guān)文章
Java網(wǎng)絡(luò)編程之基于TCP協(xié)議
本文主要將Java基于TCP的網(wǎng)絡(luò)編程主要分解成5個功能:功能分解1:單向通信功能分解,2:雙向通信功能分解,3:對象流傳送功能分解,4:加入完整的處理異常方式功能分解,5:多線程接收用戶請求,需要的朋友可以參考下2021-05-05Java中的HashSet、LinkedHashSet集合解析
這篇文章主要介紹了Java中的HashSet、LinkedHashSet集合解析,與HashSet不同的是,LinkedHashSet在內(nèi)部使用了一個雙向鏈表來維護(hù)元素的順序,因此它可以保持元素的插入順序,這使得LinkedHashSet在需要保持元素順序的場景下非常有用,需要的朋友可以參考下2023-11-11MyBatis-Plus攔截器實(shí)現(xiàn)數(shù)據(jù)權(quán)限控制的示例
本文主要介紹了MyBatis-Plus攔截器實(shí)現(xiàn)數(shù)據(jù)權(quán)限控制的示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02Spring中的NamespaceHandler接口及相關(guān)軟件包說明
這篇文章主要介紹了Spring中的NamespaceHandler接口及相關(guān)軟件包說明,NamespaceHandler 接口,DefaultBeanDefinitionDocumentReader 使用該接口來處理在spring xml 配置文件中自定義的命名空間,需要的朋友可以參考下2023-12-12Java設(shè)計模式之單態(tài)模式(Singleton模式)介紹
這篇文章主要介紹了Java設(shè)計模式之單態(tài)模式(Singleton模式)介紹,本文講解了如何使用單例模式、使用單例模式注意事項(xiàng)等內(nèi)容,需要的朋友可以參考下2015-03-03