Show calendar in month mode using intention

I am working on widgets that, among other things, open a regular Android calendar using intentions for some user actions. I am currently working on ICS, so I don’t know much about older versions of the API. I can open the day view with the following code:

Intent intent2 = new Intent(); intent2.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.AllInOneActivity")); intent2.setAction("android.intent.action.MAIN"); intent2.addCategory("android.intent.category.LAUNCHER"); intent2.setFlags(0x10200000); intent2.putExtra("beginTime", dateStartMillis); intent2.putExtra("VIEW", "DAY"); context.startActivit(intent2); 

However, I cannot find a way to open it in month mode. According to GrepCode for AllInOneActivity, in its onCreate method onCreate it calls Utils.getViewTypeFromIntentAndSharedPref(this); to determine which view to display. Here is the method:

  public static int getViewTypeFromIntentAndSharedPref(Activity activity) { Intent intent = activity.getIntent(); Bundle extras = intent.getExtras(); SharedPreferences prefs = GeneralPreferences.getSharedPreferences(activity); if (TextUtils.equals(intent.getAction(), Intent.ACTION_EDIT)) { return ViewType.EDIT; } if (extras != null) { if (extras.getBoolean(INTENT_KEY_DETAIL_VIEW, false)) { // This is the "detail" view which is either agenda or day view return prefs.getInt(GeneralPreferences.KEY_DETAILED_VIEW, GeneralPreferences.DEFAULT_DETAILED_VIEW); } else if (INTENT_VALUE_VIEW_TYPE_DAY.equals(extras.getString(INTENT_KEY_VIEW_TYPE))) { // Not sure who uses this. This logic came from LaunchActivity return ViewType.DAY; } } // Default to the last view return prefs.getInt( GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW); } 

I do not see in this method (or anywhere else in this case) the ability to set the view in MonthView. Is there any trick I can use, or should I just accept that this is not possible?

+4
source share
1 answer

From here: Google Android Developer Documentation

The calendar provider offers two different ways to use the VIEW intent:

To open a calendar for a specific date. View event. The following is an example showing how to open a calendar for a specific date:

 // A date-time specified in milliseconds since the epoch. long startMillis; ... Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); builder.appendPath("time"); ContentUris.appendId(builder, startMillis); Intent intent = new Intent(Intent.ACTION_VIEW) .setData(builder.build()); startActivity(intent); 

Here is an example that shows how to open an event for viewing:

 long eventID = 208; ... Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID); Intent intent = new Intent(Intent.ACTION_VIEW) .setData(uri); startActivity(intent); 

It also means that there is no official way to determine which view is shown. Your code only works in this calendar application in ICS and most likely does not work with most other applications.

0
source

Source: https://habr.com/ru/post/1479565/


All Articles