Re initate Sync adapter in android

岁酱吖の 提交于 2019-12-25 02:57:34

问题


I'm able to successfully create Sync adapter in my phone, but i'm not able to handle a particular scenario.

My task sync app, requires the tasks permission to fetch tasks or it applicable for getting permission for any service from Google server. this scenario occurs for the first time, if the user moves to Google account without launching the application.

1) Go to Settings --> Accounts and sync --> Choose a Google account,

2) there the tasks sync content provider will be present.

3) Once i press on Sync, since for the first time the sync provider do not have access to Tasks or any Google services etc.. accounts it raises userRecoverableException

4) With help of Notification provider i will raise a push notification in my catch block.

Here how i'm doing, e is the userRecoverableException intent.

PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
                        mContext, constants.REQUEST_AUTHORIZATION, e.getIntent(),
                        PendingIntent.FLAG_UPDATE_CURRENT
                        | PendingIntent.FLAG_ONE_SHOT); 

4) once user click on notification it will open a authentication window, user approves permission for your app to fetch calender, contacts, task etc service.

5) Now how to re initiate the sync once user completes the authentication part?. Also i notice some app shows a red color exclamatory icon next to sync icon, saying "sync is experiencing problems it will be back shortly". Once they get permission automatically they will resume and sync.

Here how to get notification to restart sync or resume as soon as user authenticate the permission


回答1:


Here is the solution,

we need to use the syncResult.stats.numAuthExceptions to tell about exception, it throws message automatically. syncResult.delayUntil will wait and restart sync after elapsing time

How to show sync failed message



来源:https://stackoverflow.com/questions/24448584/re-initate-sync-adapter-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!