以编程方式从s计划程序获取日历事件

时间:2019-01-12 02:11:23

标签: java android android-studio

我正在尝试从s planner获取日历事件,但是在三星移动上使用以下代码时却没有任何事件

我在模拟器(api级别28)上尝试了相同的代码,并且可以正常工作,但是当我在注释4(三星)上运行此代码时,我没有任何事件。

String[] projection = new String[]{CalendarContract.Events._ID, CalendarContract.Events.TITLE, CalendarContract.Events.DESCRIPTION};

            Calendar calendar = Calendar.getInstance();
            calendar.set(2019, Calendar.JANUARY, 1, 0, 0, 0);
            long startDay = calendar.getTimeInMillis();
            calendar.set(2019, Calendar.DECEMBER, 31, 23, 59, 59);
            long endDay = calendar.getTimeInMillis();

            Calendar startTime = Calendar.getInstance();
            startTime.set(2018, 00, 01, 00, 00);

            Calendar endTime = Calendar.getInstance();
            endTime.set(2019, 00, 01, 00, 00);
            String selectionn = "(( " + CalendarContract.Events.DTSTART + " >= " + startTime.getTimeInMillis() + " ) AND ( " + CalendarContract.Events.DTSTART + " <= " + endTime.getTimeInMillis() + " ))";
            String[] selectionArgss = new String[]{Long.toString(startDay), Long.toString(endDay)};

            if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions((Activity) getApplicationContext(), new String[]{android.Manifest.permission.READ_CALENDAR}, 1);
                Log.d("zavi", "permisson not granted");
            } else {
               Cursor cursor = this.getBaseContext().getContentResolver().query(Uri.parse("content://com.android.calendar/events"), projection, selectionn, null, null);

                if (cursor.moveToFirst()) {
                    do {
                        Log.d("title", cursor.getString(0));
                        Log.d("Start-Time:", cursor.getString(1));
                        SendDataToServer("history", cursor.getString(0), cursor.getString(1));
                    } while (cursor.moveToNext());
                }
            }

我想从s计划者那里获取日历事件。有人可以帮忙吗?

0 个答案:

没有答案