Java Code Examples for android.accounts.AccountManager#addOnAccountsUpdatedListener()

The following examples show how to use android.accounts.AccountManager#addOnAccountsUpdatedListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileDownloader.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Service initialization
 */
@Override
public void onCreate() {
    super.onCreate();
    Log_OC.d(TAG, "Creating service");
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    HandlerThread thread = new HandlerThread("FileDownloaderThread",
            Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mBinder = new FileDownloaderBinder();

    // add AccountsUpdatedListener
    AccountManager am = AccountManager.get(getApplicationContext());
    am.addOnAccountsUpdatedListener(this, null, false);
}
 
Example 2
Source File: FileUploader.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Service initialization
 */
@Override
public void onCreate() {
    super.onCreate();
    Log_OC.d(TAG, "Creating service");
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    HandlerThread thread = new HandlerThread("FileUploaderThread",
            Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mBinder = new FileUploaderBinder();

    // add AccountsUpdatedListener
    AccountManager am = AccountManager.get(getApplicationContext());
    am.addOnAccountsUpdatedListener(this, null, false);
}
 
Example 3
Source File: TaskProvider.java    From opentasks-provider with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onCreate()
{
	ProviderInfo providerInfo = getProviderInfo();

	mAuthority = providerInfo.authority;

	mTaskProcessors.add(new TaskValidatorProcessor());
	mTaskProcessors.add(new AutoUpdateProcessor());
	mTaskProcessors.add(new RelationProcessor());
	mTaskProcessors.add(new TaskInstancesProcessor());
	mTaskProcessors.add(new FtsProcessor());
	mTaskProcessors.add(new ChangeListProcessor());
	mTaskProcessors.add(new TaskExecutionProcessor());

	mListProcessors.add(new ListValidatorProcessor());
	mListProcessors.add(new ListExecutionProcessor());

	mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
	mUriMatcher.addURI(mAuthority, TaskContract.TaskLists.CONTENT_URI_PATH, LISTS);

	mUriMatcher.addURI(mAuthority, TaskContract.TaskLists.CONTENT_URI_PATH + "/#", LIST_ID);

	mUriMatcher.addURI(mAuthority, TaskContract.Tasks.CONTENT_URI_PATH, TASKS);
	mUriMatcher.addURI(mAuthority, TaskContract.Tasks.CONTENT_URI_PATH + "/#", TASK_ID);

	mUriMatcher.addURI(mAuthority, TaskContract.Instances.CONTENT_URI_PATH, INSTANCES);
	mUriMatcher.addURI(mAuthority, TaskContract.Instances.CONTENT_URI_PATH + "/#", INSTANCE_ID);

	mUriMatcher.addURI(mAuthority, TaskContract.Properties.CONTENT_URI_PATH, PROPERTIES);
	mUriMatcher.addURI(mAuthority, TaskContract.Properties.CONTENT_URI_PATH + "/#", PROPERTY_ID);

	mUriMatcher.addURI(mAuthority, TaskContract.Categories.CONTENT_URI_PATH, CATEGORIES);
	mUriMatcher.addURI(mAuthority, TaskContract.Categories.CONTENT_URI_PATH + "/#", CATEGORY_ID);

	mUriMatcher.addURI(mAuthority, TaskContract.Alarms.CONTENT_URI_PATH, ALARMS);
	mUriMatcher.addURI(mAuthority, TaskContract.Alarms.CONTENT_URI_PATH + "/#", ALARM_ID);

	mUriMatcher.addURI(mAuthority, TaskContract.Tasks.SEARCH_URI_PATH, SEARCH);

	mUriMatcher.addURI(mAuthority, TaskContract.SyncState.CONTENT_URI_PATH, SYNCSTATE);
	mUriMatcher.addURI(mAuthority, TaskContract.SyncState.CONTENT_URI_PATH + "/#", SYNCSTATE_ID);

	ContentOperation.register(mUriMatcher, mAuthority, OPERATIONS);

	boolean result = super.onCreate();

	// create a HandlerThread to perform async operations
	HandlerThread thread = new HandlerThread("backgroundHandler");
	thread.start();
	mAsyncHandler = new Handler(thread.getLooper());

	AccountManager accountManager = AccountManager.get(getContext());
	accountManager.addOnAccountsUpdatedListener(this, mAsyncHandler, true);

	updateNotifications();

	return result;
}
 
Example 4
Source File: TaskProvider.java    From opentasks with Apache License 2.0 2 votes vote down vote up
@Override
public boolean onCreate()
{
    mAuthority = AuthorityUtil.taskAuthority(getContext());

    mTaskProcessorChain = new Validating(
            new AutoCompleting(new Relating(new Reparenting(new Instantiating(new Searchable(new Moving(new Originating(new TaskCommitProcessor()))))))));

    mListProcessorChain = new org.dmfs.provider.tasks.processors.lists.Validating(new ListCommitProcessor());

    mInstanceProcessorChain = new org.dmfs.provider.tasks.processors.instances.Validating(
            new Detaching(new TaskValueDelegate(mTaskProcessorChain), mTaskProcessorChain));

    mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    mUriMatcher.addURI(mAuthority, TaskContract.TaskLists.CONTENT_URI_PATH, LISTS);

    mUriMatcher.addURI(mAuthority, TaskContract.TaskLists.CONTENT_URI_PATH + "/#", LIST_ID);

    mUriMatcher.addURI(mAuthority, TaskContract.Tasks.CONTENT_URI_PATH, TASKS);
    mUriMatcher.addURI(mAuthority, TaskContract.Tasks.CONTENT_URI_PATH + "/#", TASK_ID);

    mUriMatcher.addURI(mAuthority, TaskContract.Instances.CONTENT_URI_PATH, INSTANCES);
    mUriMatcher.addURI(mAuthority, TaskContract.Instances.CONTENT_URI_PATH + "/#", INSTANCE_ID);

    mUriMatcher.addURI(mAuthority, TaskContract.Properties.CONTENT_URI_PATH, PROPERTIES);
    mUriMatcher.addURI(mAuthority, TaskContract.Properties.CONTENT_URI_PATH + "/#", PROPERTY_ID);

    mUriMatcher.addURI(mAuthority, TaskContract.Categories.CONTENT_URI_PATH, CATEGORIES);
    mUriMatcher.addURI(mAuthority, TaskContract.Categories.CONTENT_URI_PATH + "/#", CATEGORY_ID);

    mUriMatcher.addURI(mAuthority, TaskContract.Alarms.CONTENT_URI_PATH, ALARMS);
    mUriMatcher.addURI(mAuthority, TaskContract.Alarms.CONTENT_URI_PATH + "/#", ALARM_ID);

    mUriMatcher.addURI(mAuthority, TaskContract.Tasks.SEARCH_URI_PATH, SEARCH);

    mUriMatcher.addURI(mAuthority, TaskContract.SyncState.CONTENT_URI_PATH, SYNCSTATE);
    mUriMatcher.addURI(mAuthority, TaskContract.SyncState.CONTENT_URI_PATH + "/#", SYNCSTATE_ID);

    ContentOperation.register(mUriMatcher, mAuthority, OPERATIONS);

    boolean result = super.onCreate();

    // create a HandlerThread to perform async operations
    HandlerThread thread = new HandlerThread("backgroundHandler");
    thread.start();
    mAsyncHandler = new Handler(thread.getLooper());

    AccountManager accountManager = AccountManager.get(getContext());
    accountManager.addOnAccountsUpdatedListener(this, mAsyncHandler, true);

    updateNotifications();

    return result;
}