如何以编程方式整合在我们的应用程序的Android的默认应用程序 [英] how to integrate default app of android in our app programatically
本文介绍了如何以编程方式整合在我们的应用程序的Android的默认应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有可能在我们的应用程序编程集成默认的应用程序(例如日历)的Android。 任何人都可以解释我的详细信息......
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.
- Working with the Android Calendar
- Accessing the internal calendar database inside Google Android applications
- 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));
这篇关于如何以编程方式整合在我们的应用程序的Android的默认应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文