您现在的位置是:首页 > 文章详情

Android--日历事件获取

日期:2018-07-23点击:334
版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/81187327
import android.annotation.SuppressLint; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.telephony.TelephonyManager; import com.vm.shadowsocks.utils.ReadInfo; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.text.SimpleDateFormat; import java.util.Date; /** * 日历 */ public class calendar { private static String CALENDER_URL = "content://com.android.calendar/calendars"; private static String CALENDER_EVENT_URL = "content://com.android.calendar/events"; private static String CALENDER_REMINDER_URL = "content://com.android.calendar/reminders"; private static TelephonyManager mTm; private static JSONArray getcalendar(Context context){ String startTime = ""; String endTime = ""; String eventTitle = ""; String description = ""; String location = ""; JSONArray arr=new JSONArray(); Cursor eventCursor = context.getContentResolver().query(Uri.parse(CALENDER_EVENT_URL), null, null, null, null); while (eventCursor.moveToNext()){ JSONObject json=new JSONObject(); eventTitle = eventCursor.getString(eventCursor.getColumnIndex("title")); description = eventCursor.getString(eventCursor.getColumnIndex("description")); location = eventCursor.getString(eventCursor.getColumnIndex("eventLocation")); startTime = timeStamp2Date(Long.parseLong(eventCursor.getString(eventCursor.getColumnIndex("dtstart")))); endTime = timeStamp2Date(Long.parseLong(eventCursor.getString(eventCursor.getColumnIndex("dtend")))); try { json.put("eventTitle",eventTitle); json.put("description",description); json.put("location",location); json.put("startTime",startTime); json.put("endTime",endTime); } catch (JSONException e) { e.printStackTrace(); } arr.put(json); } return arr; } /** * 时间戳转换为字符串 * @param time:时间戳 * @return */ private static String timeStamp2Date(long time) { String format = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(new Date(time)); } } 

 

原文链接:https://yq.aliyun.com/articles/631435
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章