당신은 다음과 같이 진행해야한다 :
당신이 이 AbstractThreadedSyncAdapter를 확장해야 확장 propeties와 함께 이벤트를 저장하기 위해 사용하는 클래스는 다음 방법 onPerfomSync (...)
를 구현 public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) {
System.out.println("Sync......");
saveEvent();//your saving events method...
}
,
동일한 클래스에 아래의 방법을 추가
static Uri asSyncAdapter(Uri uri, String account, String accountType) {
return uri.buildUpon()
.appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true")
.appendQueryParameter(Calendars.ACCOUNT_NAME, account)
.appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build();
}
은 입술 이하
public class SyncService extends Service {
private static final String TAG = "SyncService";
private static final Object sSyncAdapterLock = new Object();
private static EditEventHelper sSyncAdapter = null;
/**
* Thread-safe constructor, creates static {@link SyncAdapter} instance.
*/
@Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "Service created");
synchronized (sSyncAdapterLock) {
if (sSyncAdapter == null) {
sSyncAdapter = new EditEventHelper(getApplicationContext());
}
}
}
@Override
/**
* Logging-only destructor.
*/
public void onDestroy() {
super.onDestroy();
Log.i(TAG, "Service destroyed");
}
/**
* Return Binder handle for IPC communication with {@link SyncAdapter}.
*
* <p>New sync requests will be sent directly to the SyncAdapter using this channel.
*
* @param intent Calling intent
* @return Binder handle for {@link SyncAdapter}
*/
@Override
public IBinder onBind(Intent intent) {
return sSyncAdapter.getSyncAdapterBinder();
}
같은 서비스 클래스}
확장 클래스를 생성 경로 작성 XML 파일 syncadpater.xml 내용 :
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="com.android.calendar"
android:accountType="com.android.google"
android:userVisible="true"
android:supportsUploading="false"
android:allowParallelSyncs="false"
android:isAlwaysSyncable="false"
/>
하면 이벤트에 Extendedproperties을 추가하는 데 사용하기위한 코드가 될 것이다 다음 의 AndroidManifest.xml 파일에서
ContentValues customerContentValues_1 = new ContentValues();
customerContentValues_1.put(ExtendedProperties.EVENT_ID, model.mId);
customerContentValues_1.put(ExtendedProperties.NAME, "name");
customerContentValues_1.put(ExtendedProperties.VALUE, value);
activity.getContentResolver().insert(asSyncAdapter(ExtendedProperties.CONTENT_URI, mOwnerAccount, ACCOUNT_TYPE), customerContentValues_1);
이 권한을 추가 :
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<!-- Required to enable our SyncAdapter after it's created. -->
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<!-- Required because we're manually creating a new account. -->
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
그런 선언 syncadapter.xml 파일과 연결된 매니페스트 파일에 생성 한 서비스 :
<service
android:name="com.android.calendar.iselection.event.SyncService"
android:exported="true" >
<!--
This intent filter is required. It allows the system to launch our sync service
as needed.
-->
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<!-- This points to a required XML file which describes our SyncAdapter. -->
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
</service>
행운을 빌어 요!