2015-08-16 109 views
1

我真的很困惑這個。我認爲這個問題源於圖書館應用程序的合併。Android同步適配器的兩個庫只有一個叫

我有兩個同步適配器,來自兩個不同的庫。我一直在玩代碼,我基本上可以讓第一個或第二個同步適配器工作。

第一種情況,所有模板文件命名相同,libOne的同步適配器啓動。我將android:resource =「@ xml/filenamehere」中引用的XML文件重命名爲 ,以使其是唯一的,而不是默認值。結果,libTwo的同步是否被激活?這很奇怪。

我的解決方案是在實際應用程序中製作第三個同步適配器,並在一個文件中處理這兩個適配器,但我討厭不理解爲什麼發生了什麼。注意我將軟件包名稱更改爲libOne libTwo。

這些圖書館來自同一所大學,是同一作者同一個項目的一部分。唯一的區別是路徑名稱,適配器名稱,權限和帳戶類型。因此,它們是文字複製和粘貼鏡像。我試圖讓所有這些項目都一樣,沒有變化。只有那些改變了我無法控制的東西就是重命名這些文件。還嘗試更改允許並行標誌。我猜測操作系統不喜歡啓動我的雙適配器。

我正在查看logcat,但大多數情況下我有一個通知,我創建的服務令人討厭,因爲它們與應用程序不同,所以出現在logcat中。

如何啓動服務

if(!isMyServiceRunning(libOne.data_sync.SyncService.class, context)){ 
     android.util.Log.d(TAG, "Starting service confirmTrips...."); 
     Intent intent = new Intent(context, libOne.SyncService.class); 
     context.startService(intent); 
    } 

    if(!isMyServiceRunning(libTwo.smap.SyncService.class, context)){ 
     android.util.Log.d(TAG, "Starting service sendTripData...."); 
     Intent intent = new Intent(context, libTwo.smap.SyncService.class); 
     context.startService(intent); 
    } 


    ContentResolver.setIsSyncable(mAccount, LIBTWO_AUTHORITY, 1); 
    ContentResolver.setSyncAutomatically(mAccount, LIBTWO_AUTHORITY, true); 
    ContentResolver.addPeriodicSync(mAccount, LIBTWO_AUTHORITY, new Bundle(), SYNC_INTERVAL); 
    ContentResolver.setIsSyncable(mAccount, LIBONE_AUTHORITY, 1); 
    ContentResolver.setSyncAutomatically(mAccount, LIBONE_AUTHORITY, true); 
    ContentResolver.addPeriodicSync(mAccount, LIBONE_AUTHORITY, new Bundle(), SYNC_INTERVAL); 

文件的服務

<service 
      android:name="libone.data_sync.SyncService" 
      android:exported="true" 
      android:process=":sync" > 
      <intent-filter> 
       <action android:name="android.content.SyncAdapter" /> 
      </intent-filter> 

      <meta-data 
       android:name="android.content.SyncAdapter" 
       android:resource="@xml/libOnesyncadapter" /> 
     </service> 

     <provider 
      android:name="libone.data_sync.StubContentProvider" 
      android:authorities="libone.provider" 
      android:exported="false" 
      android:syncable="true" /> 
<?xml version="1.0" encoding="utf-8"?> 
<account-authenticator 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:accountType="accounttypeone.org" 
     android:icon="@drawable/ic_launcher" 
     android:smallIcon="@drawable/ic_launcher" 
     android:label="@string/app_name"/> 
<?xml version="1.0" encoding="utf-8"?> 
// adapter 
<sync-adapter 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:contentAuthority="libone.provider" 
     android:accountType="liboneaccounttype" 
     android:userVisible="false" 
     android:supportsUploading="true" 
     android:allowParallelSyncs="false" 
     android:isAlwaysSyncable="true"/> 

////LIBTwo 

     <service 
       android:name="libtwo.smap.SyncService" 
       android:exported="true" 
       android:process=":sync"> 
      <intent-filter> 
       <action android:name="android.content.SyncAdapter"/> 
      </intent-filter> 
      <meta-data android:name="android.content.SyncAdapter" 
        android:resource="@xml/libTwosyncadapter" /> 
     </service> 
     <provider 
      android:name="libtwo.smap.StubContentProvider" 
      android:authorities="libtwo.provider" 
      android:exported="false" 
      android:syncable="true"/> 

<?xml version="1.0" encoding="utf-8"?> 
<account-authenticator 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:accountType="accounttypetwo.org" 
     android:icon="@drawable/ic_launcher" 
     android:smallIcon="@drawable/ic_launcher" 
     android:label="@string/app_name"/> 
<?xml version="1.0" encoding="utf-8"?> 
<sync-adapter 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:contentAuthority="libtwo.provider" 
     android:accountType="libtwo.org" 
     android:userVisible="false" 
     android:supportsUploading="true" 
     android:allowParallelSyncs="false" 
     android:isAlwaysSyncable="true"/> 

logcat的

08-16 14:37:48.458  1535-956/? D/[WINGTIP_NOTI]ParseAlgorithm﹕ piece=Syncing libTwoAdapter Aug 16, 2015 2:37:48 PM id:16908415 name:text 
08-16 14:37:48.458  1535-956/? D/[WINGTIP_NOTI]ParseAlgorithm﹕ body is : Syncing libTwoAdapter Aug 16, 2015 2:37:48 PM 
08-16 14:37:48.458  1535-956/? D/[WINGTIP_NOTI]ParseAlgorithm﹕ line 2 = Syncing libTwoAdapter CFC Aug 16, 2015 2:37:48 PM 
08-16 14:37:48.458  1535-956/? D/[WINGTIP_NOTI]WingtipNotificationListenerService﹕ line 1 = Study, line2 = Syncing libTwoAdapter Aug 16, 2015 2:37:48 PM 
08-16 14:37:48.488 1535-1535/? I/[WINGTIP_NOTI]NotificationAdapter﹕ NOTIFICAITON onReceived 
08-16 14:37:48.498 1535-1535/? I/[WINGTIP_NOTI]NotificationAdapter﹕ ServicePackages.ACTION_NOTIFICATION_RECEIVED 
08-16 14:37:48.498 1535-1535/? I/[WINGTIP_NOTI]NotificationAdapter﹕ index : 10202 packageName : time : 1439757468418 title : Study textMessage : Syncing libTwoAdapter Aug 16, 2015 2:37:48 PM 
    addressText : isVibrate : false 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ transfer() 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ ================================================================= 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ Message ID :    10202 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ Package Name :   
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ Sender :     Study 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ Address : 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ Title : 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ Body :     Syncing libTwoAdapter Aug 16, 2015 2:37:48 PM 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ Message Time :   1439757468418 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ isVibrate :    false 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ ================================================================= 
08-16 14:37:48.498 1535-1535/? V/[WINGTIP_NOTI]NotificationAdapter﹕ Disable Notification generalNotification packageNamae : 
+0

我認爲問題與accountType有關。在製作第三個服務時,我無法運行它,直到符合我的圖書館帳戶類型。 – StarWind0

回答

0

我有ACCOUNTTYPE設定爲X的第一庫和第二accountType Y.這與我在嘗試獲取或創建e時遇到安全異常時的噩夢相符xplicitly一個帳戶。我只能從其中一個庫中生成帳戶,錯誤會說我打了一個不匹配的ID。

我更大的問題是,當我嘗試使其全部統一時,我沒有在其中一個字段中更改帳戶類型。