2016-05-21 8 views
1

イベントは、api 22まで適切にカレンダーに追加されています。複数のイベントをアンドロイドのマシュマロカレンダーに追加するには?

私はMarshmallowの実行時アクセス許可も実装しています。私のアプリケーションの電話設定では、Calenderの許可が許可されています。

まだ電話のカレンダーやアプリにもエラーや警告を表示するものはありません。

下記は私の方法で電話によるカレンダーにイベントをプログラマチックに追加する方法です。

private void addEventToCalender(Activity ourActivity, String title, String desc, String place, int status, long startDate, long endDte, boolean needReminder, boolean needMailService) { 
     try { 
      String eventUriString = "content://com.android.calendar/events"; 
      ContentValues eventValues = new ContentValues(); 
      eventValues.put("calendar_id", 1); // id, We need to choose from   // our mobile for primary its 1 
      eventValues.put("title", "My Title"); 
      eventValues.put("description","My Description"); 
      eventValues.put("eventLocation", "Noida,UP "; 

      eventValues.put("dtstart", startDate); 
      eventValues.put("dtend", endDte); 
      eventValues.put("allDay", 1); // 1 for whole day 
      //eventValues.put("rrule", "FREQ=YEARLY"); 

      // values.put("allDay", 1); //If it is bithday alarm or such 
      // kind (which should remind me for whole day) 0 for false, 1 
      // for true 
      eventValues.put("eventStatus", 1); // This information is 
      // sufficient for most 
      // entries tentative (0), 
      // confirmed (1) or canceled 
      // (2): 
      eventValues.put("eventTimezone", "UTC/GMT " + Constants.tzone); 
      eventValues.put("hasAlarm", 1); // 0 for false, 1 for true 
      Uri eventUri = this.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), eventValues); 
      long eventID = Long.parseLong(eventUri.getLastPathSegment()); 
      Log.i("eventID", eventID + ""); 
      showSnackBar("Event added to calender successfuly."); 
     } catch (Exception ex) { 
      Log.e("error", "Error in adding event on calendar" + ex.getMessage()); 
      showSnackBar("Ünable to add event to calender!"); 
     } 

    } 
+0

は何の問題もない、問題は、Googleカレンダーアプリの最新アップデートとあったので、最新のアップデートをアンインストールした後、私は今、マシュマロの上に複数のイベントを追加することができています。 –

答えて

0

内側のフラグメントを使用したいことがあります。最初の使用で

FragmentCompat.requestPermissions(permissionsList, RequestCode) 

注:

ActivityCompat.requestPermissions(Activity, permissionsList, RequestCode); 

をapp.gradleにFragmentCompatクラスのため、このライブラリを追加フラグメントインサイド

super.requestPermissions(new String[]{Manifest.permission.WRITE_CALENDAR}, MY_PERMISSIONS_REQUEST_WRITE_CALENDAR); 

、あなたが呼び出す必要があります。上記のコード

compile 'com.android.support:support-v13:version_of_library' 
関連する問題