如何以编程方式整合在我们的应用程序的Andr​​oid的默认应用程序

如何以编程方式整合在我们的应用程序的Andr​​oid的默认应用程序

问题描述:

有没有可能在我们的应用程序编程集成默认的应用程序(例如日历)的Andr​​oid。 任何人都可以解释我的详细信息......

Is it possible to integrate the default app(like Calendar) of Android in our app programatically . Can anyone explain me in details....

这是我使用的两个类是: MainActivity.java

The two classes that I am using are: MainActivity.java

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Example.readCalendar(this);
    }
}

和另一个类的 Example.java

public class Example {

    public static void readCalendar(Context context) {

        ContentResolver contentResolver = context.getContentResolver();

        // Fetch a list of all calendars synced with the device, their display names and whether the
        // user has them selected for display.

        final Cursor cursor = contentResolver.query(Uri.parse("content://calendar/calendars"),
                (new String[] { "_id", "displayName", "selected" }), null, null, null);
        // For a full list of available columns see http://tinyurl.com/yfbg76w

        HashSet<String> calendarIds = new HashSet<String>();

        while (cursor.moveToNext()) {

            final String _id = cursor.getString(0);
            final String displayName = cursor.getString(1);
            final Boolean selected = !cursor.getString(2).equals("0");

            System.out.println("Id: " + _id + " Display Name: " + displayName + " Selected: " + selected);
            calendarIds.add(_id);
        }

        // For each calendar, display all the events from the previous week to the end of next week.        
        for (String id : calendarIds) {
            Uri.Builder builder = Uri.parse("content://calendar/instances/when").buildUpon();
            long now = new Date().getTime();
            ContentUris.appendId(builder, now - DateUtils.WEEK_IN_MILLIS);
            ContentUris.appendId(builder, now + DateUtils.WEEK_IN_MILLIS);

            Cursor eventCursor = contentResolver.query(builder.build(),
                    new String[] { "title", "begin", "end", "allDay"}, "Calendars._id=" + id,
                    null, "startDay ASC, startMinute ASC"); 
            // For a full list of available columns see http://tinyurl.com/yfbg76w

            while (eventCursor.moveToNext()) {
                final String title = eventCursor.getString(0);
                final Date begin = new Date(eventCursor.getLong(1));
                final Date end = new Date(eventCursor.getLong(2));
                final Boolean allDay = !eventCursor.getString(3).equals("0");

                System.out.println("Title: " + title + " Begin: " + begin + " End: " + end +
                        " All Day: " + allDay);
            }
        }
    }


}

我已经加入了READ_CALENDAR权限也。

I have added the READ_CALENDAR permission also.

这些文章可能会帮助你。

These articles might help you.

  1. 了Android日历
  2. 访问内部日历数据库中的谷歌Android应用
  3. 日历API(android.provider.Calendar)
  1. Working with the Android Calendar
  2. Accessing the internal calendar database inside Google Android applications
  3. Calendar API (android.provider.Calendar)

例如:

static String contentProvider;
static Uri remindersUri;
static Uri eventsUri;
static Uri calendars;

if(Build.VERSION.RELEASE.contains("2.2″))
    contentProvider = "com.android.calendar";
else
    contentProvider = "calendar";

remindersUri = Uri.parse(String.format("content://%s/reminders",contentProvider));
eventsUri = Uri.parse(String.format("content://%s/events",contentProvider));
calendars = Uri.parse(String.format("content://%s/calendars",contentProvider));