4

私はウィジェットに取り組んでいます。これは、ユーザーのアクションによって、インテントを使用して通常の Android カレンダーを開くものです。私は現在 ICS に取り組んでいるので、古いバージョンの API にはあまり関心がありません。次のコードで日ビューを開くことができます。

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);

ただし、月表示で開く方法が見つからないようです。AllInOneActivityの GrepCode によると、そのonCreateメソッドで呼び出しUtils.getViewTypeFromIntentAndSharedPref(this);て、表示するビューを決定します。その方法は次のとおりです。

 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);
 }

ビューを MonthView に設定する方法は、このメソッド (または他の場所) にはありません。私が使用できるある種のトリックはありますか、それともこれが不可能であることを受け入れる必要がありますか?

4

1 に答える 1

0

ここから: Android Developer Calendar Provider Docs

カレンダー プロバイダーは、VIEW インテントを使用する 2 つの異なる方法を提供します。

特定の日付のカレンダーを開く。イベントを表示するには。次の例は、カレンダーを開いて特定の日付にする方法を示しています。

// 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);

以下は、イベントを開いて表示する方法を示す例です。

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

これは、どのビューが表示されているかを判断する公式の方法がないことも意味します。コードは ICS の特定のカレンダー アプリでのみ機能し、他のほとんどのアプリではおそらく機能しません。

于 2016-03-02T14:01:33.233 に答える