Android Open Source - savemypics C Network Change Receiver






From Project

Back to project page savemypics.

License

The source code is released under:

Copyright (c) 2014, KB Sriram All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. R...

If you think the Android project savemypics listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.savemypics.android.receiver;
//  w w w. j  a v a2 s.  c  o m
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import org.savemypics.android.util.CUtils;

public class CNetworkChangeReceiver extends BroadcastReceiver
{
    // This needs to be a quick call
    @Override
    public void onReceive(Context ctx, Intent intent)
    {
        if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals
            (intent.getAction())) {
            NetworkInfo info = (NetworkInfo)
                intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
            if (NetworkInfo.State.CONNECTED.equals(info.getState())) {
                final Handler handler = new Handler();
                final Context appctx = ctx.getApplicationContext();
                handler.postDelayed(new Runnable() {
                        public void run() {
                            requestSync(appctx);
                        }
                    }, NETWORK_DELAY_START_MSEC);
            }
        }
    }

    private final static void requestSync(Context appctx)
    {
        AccountManager mgr = AccountManager.get(appctx);
        requestSyncAccount(mgr, CUtils.BASE_ACCOUNT_TYPE);
    }

    private final static void requestSyncAccount
        (AccountManager amgr, String atype)
    {
        Account[] accounts = amgr.getAccountsByType(atype);
        if (accounts == null) { return; }

        for (int i = 0; i < accounts.length; i++) {
            Account acct = accounts[i];
            // Respect settings.
            if (!ContentResolver.getSyncAutomatically
                (acct, MediaStore.AUTHORITY)) {
                CUtils.LOGD(TAG, "Skip "+acct+" - sync not enabled");
                continue;
            }
            if (ContentResolver.getIsSyncable(acct, MediaStore.AUTHORITY)<= 0) {
                CUtils.LOGD(TAG, "Skip "+acct+" - not synced with mediastore");
                continue;
            }
            ContentResolver.requestSync
                (acct, MediaStore.AUTHORITY, new Bundle());
        }
    }

    // 90 seconds.
    private final static long NETWORK_DELAY_START_MSEC = 90*1000l;
    private final static String TAG =
        CUtils.makeLogTag(CNetworkChangeReceiver.class);
}




Java Source Code List

android.util.Base64.java
org.savemypics.android.activity.AActivity.java
org.savemypics.android.activity.ABaseSettingsActivity.java
org.savemypics.android.activity.CAccountInfoListAdapter.java
org.savemypics.android.activity.CFlickrSettingsActivity.java
org.savemypics.android.activity.CSnapfishSettingsActivity.java
org.savemypics.android.activity.CStartActivity.java
org.savemypics.android.authenticator.AAuthenticatorActivity.java
org.savemypics.android.authenticator.CAuthenticationService.java
org.savemypics.android.authenticator.CAuthenticator.java
org.savemypics.android.authenticator.CFlickrLoginHookActivity.java
org.savemypics.android.authenticator.CFlickrWebActivity.java
org.savemypics.android.authenticator.CSelectProviderActivity.java
org.savemypics.android.authenticator.CSnapfishLoginActivity.java
org.savemypics.android.db.CAccount.java
org.savemypics.android.db.CDb.java
org.savemypics.android.db.CLocalImage.java
org.savemypics.android.db.CMap.java
org.savemypics.android.db.CRemoteImage.java
org.savemypics.android.event.AEvent.java
org.savemypics.android.event.CEventBus.java
org.savemypics.android.event.CExceptionEvent.java
org.savemypics.android.glue.ABaseGlue.java
org.savemypics.android.glue.CFlickrGlue.java
org.savemypics.android.glue.CSnapfishGlue.java
org.savemypics.android.receiver.CNetworkChangeReceiver.java
org.savemypics.android.service.CTaskQueue.java
org.savemypics.android.sync.CMediaUtils.java
org.savemypics.android.sync.CSyncAdapter.java
org.savemypics.android.sync.CSyncService.java
org.savemypics.android.sync.CSyncUtils.java
org.savemypics.android.util.CBitmapUtils.java
org.savemypics.android.util.CFileCache.java
org.savemypics.android.util.CLruCache.java
org.savemypics.android.util.CUtils.java
org.savemypics.android.util.CUtils.java
org.savemypics.android.view.CMaximumWidthLayout.java
org.savemypics.android.view.CModularLayout.java
org.savemypics.android.view.CRefreshButton.java
org.savemypics.android.view.CRoundedBitmapView.java
org.savemypics.android.view.CStatusCounterView.java
org.savemypics.plugin.CIOUtils.java
org.savemypics.plugin.CPlugin.java
org.savemypics.plugin.flickr.CFlickrAlbum.java
org.savemypics.plugin.flickr.CFlickrUtils.java
org.savemypics.plugin.snapfish.CSnapfishAlbum.java
org.savemypics.plugin.snapfish.CSnapfishFeed.java
org.savemypics.plugin.snapfish.CSnapfishUser.java
org.savemypics.plugin.snapfish.CSnapfishUtils.java