List of usage examples for android.content ContentResolver addPeriodicSync
public static void addPeriodicSync(Account account, String authority, Bundle extras, long pollFrequency)
From source file:org.enbyted.android.zseinfo.view.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); InfoApp.setActivity(this); final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager with the sections adapter. pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); pager.setAdapter(pagerAdapter);// w w w . j av a 2 s . c o m pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); InfoApp.getContext().notifyUiChanged(); } }); addSection(new TimetableSection()); addSection(new ReplacementsSection()); addSection(new LuckySection()); //Synchronise stuff account = createSyncAccount(this); ContentResolver.addPeriodicSync(account, AUTHORITY, new Bundle(), 180); // ContentResolver.setMasterSyncAutomatically(true); // Configuration.getInstance().init(); }
From source file:com.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java
/** * Schedules periodic execution of the sync adapter. *//* w w w. j a v a 2s .c om*/ public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { // Get account and authority. Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); // Set inexact timer for the periodic sync for KitKat and above. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { SyncRequest request = new SyncRequest.Builder().syncPeriodic(syncInterval, flexTime) .setSyncAdapter(account, authority).setExtras(new Bundle()).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
From source file:com.nextgis.woody.activity.MainActivity.java
@Override public void onAddAccount(Account account, String token, boolean accountAdded) { Log.d(Constants.WTAG, "No account. " + Constants.ACCOUNT_NAME + " created. Run first step."); if (accountAdded) { // TODO: final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final MainApplication app = (MainApplication) getApplication(); app.setUserData(account.name, Constants.KEY_IS_AUTHORIZED, token); //set sync with server ContentResolver.setSyncAutomatically(account, app.getAuthority(), true); ContentResolver.addPeriodicSync(account, app.getAuthority(), Bundle.EMPTY, com.nextgis.maplib.util.Constants.DEFAULT_SYNC_PERIOD); // goto step 2 refreshActivityView();/*from w ww .jav a 2 s. c o m*/ } else Toast.makeText(this, R.string.error_init, Toast.LENGTH_SHORT).show(); }
From source file:ie.clashoftheash.timetabler.ui.SettingsActivity.java
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(prefKeyProgrammeCode) || key.equals(prefKeyYear)) { // Update account String programme = sharedPreferences.getString(prefKeyProgrammeCode, AccountUtils.getProgrammeCode(this)); String year = sharedPreferences.getString(prefKeyYear, AccountUtils.getYear(this)); new AccountUtils(this).updateAccount(programme, year); } else if (key.equals(prefKeyFreq)) { long pollFrequency = getSyncFreqPref(); Account acc = AccountUtils.getAccount(this); String authority = Timetable.AUTHORITY; if (pollFrequency > 0) { ContentResolver.setSyncAutomatically(acc, authority, true); ContentResolver.addPeriodicSync(acc, authority, new Bundle(), pollFrequency); } else {/*from w w w . java 2 s . c om*/ ContentResolver.setSyncAutomatically(acc, authority, false); ContentResolver.removePeriodicSync(acc, authority, new Bundle()); } } }
From source file:com.manning.androidhacks.hack023.authenticator.AuthenticatorActivity.java
private void finishLogin() { final Account account = new Account(mUsername, PARAM_ACCOUNT_TYPE); if (mRequestNewAccount) { mAccountManager.addAccountExplicitly(account, mPassword, null); Bundle bundle = new Bundle(); ContentResolver.addPeriodicSync(account, TodoContentProvider.AUTHORITY, bundle, 300); } else {//from ww w .jav a2 s . c o m mAccountManager.setPassword(account, mPassword); } final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, PARAM_ACCOUNT_TYPE); if (mAuthTokenType != null && mAuthTokenType.equals(PARAM_AUTHTOKEN_TYPE)) { intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthToken); } setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }
From source file:com.jefftharris.passwdsafe.sync.gdrive.GDriveProvider.java
@Override public void updateSyncFreq(Account acct, int freq) { if (acct != null) { ContentResolver.removePeriodicSync(acct, PasswdSafeContract.AUTHORITY, new Bundle()); ContentResolver.setSyncAutomatically(acct, PasswdSafeContract.AUTHORITY, false); if (freq > 0) { ContentResolver.setSyncAutomatically(acct, PasswdSafeContract.AUTHORITY, true); ContentResolver.addPeriodicSync(acct, PasswdSafeContract.AUTHORITY, new Bundle(), freq); }//from ww w . j a va 2 s.com } }
From source file:com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java
/** * Set up the sync to run at periodic intervals. * * @param context//from w w w . j av a2 s . c om * current application environment context * @param syncInterval * how often to sync in seconds * @param flexTime * how many seconds can it run before syncInterval (inexact timer for versions greater * than KITKAT */ public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // we can enable inexact timers in our periodic sync SyncRequest request = new SyncRequest.Builder().syncPeriodic(syncInterval, flexTime) .setSyncAdapter(account, authority).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
From source file:org.andstatus.app.account.AccountData.java
private void setSyncFrequencySeconds(Account androidAccount, long syncFrequencySeconds) { // See//from www.j av a 2 s. c o m // http://developer.android.com/reference/android/content/ContentResolver.html#addPeriodicSync(android.accounts.Account, java.lang.String, android.os.Bundle, long) // and // http://stackoverflow.com/questions/11090604/android-syncadapter-automatically-initialize-syncing ContentResolver.removePeriodicSync(androidAccount, MyProvider.AUTHORITY, new Bundle()); if (syncFrequencySeconds > 0) { ContentResolver.addPeriodicSync(androidAccount, MyProvider.AUTHORITY, new Bundle(), syncFrequencySeconds); } }
From source file:com.granita.contacticloudsync.syncadapter.AccountSettings.java
public void setSyncInterval(String authority, long seconds) { if (seconds == SYNC_INTERVAL_MANUALLY) { ContentResolver.setSyncAutomatically(account, authority, false); } else {// w w w. j a v a2s. c om ContentResolver.setSyncAutomatically(account, authority, true); ContentResolver.addPeriodicSync(account, authority, new Bundle(), seconds); } }
From source file:com.busticket.amedora.busticketsrl.TicketingHomeActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_ticket_home); myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar);/*from w w w . j av a 2 s .co m*/ //synchTrips(); assert getSupportActionBar() != null; getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); spBoard = (Spinner) findViewById(R.id.spBoard); spBuses = (Spinner) findViewById(R.id.spBusNo); spTrips = (Spinner) findViewById(R.id.spTripType); spHighlight = (Spinner) findViewById(R.id.spHighlight); mAccount = CreateSyncAccount(this); mQueue = Volley.newRequestQueue(getApplicationContext()); rQSyncTicket = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketSynch = Volley.newRequestQueue(getApplicationContext()); rQSyncBalance = Volley.newRequestQueue(getApplicationContext()); rqTrip = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketing = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketingSynch = Volley.newRequestQueue(getApplicationContext()); //Key methods needed to be sent to server on activity created syncTicketing(); syncTickets(); apps = db.getApp(Installation.appId(getApplicationContext())); EMAIL = apps.getRoute_name(); NAME = "CODE: " + apps.getAgent_code().toUpperCase() + " Trip: " + apps.getTripCount(); // Get the content resolver for your app mResolver = getContentResolver(); /* * Turn on periodic syncing */ mTitle = mDrawerTitle = getTitle(); ContentResolver.addPeriodicSync(CreateSyncAccount(this), AUTHORITY, Bundle.EMPTY, SYNC_INTERVAL); String[] tdata = populateTerminals(); String[] bdata = populateBuses(); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spBoard.setAdapter(adapter);/**/ ArrayAdapter Hadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata); Hadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spHighlight.setAdapter(Hadapter); ArrayAdapter gadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, bdata); gadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spBuses.setAdapter(gadapter); ArrayAdapter<CharSequence> tadapter = ArrayAdapter.createFromResource(this, R.array.tripTypes, android.R.layout.simple_spinner_item); tadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); /*ArrayAdapter badapter =new ArrayAdapter(this,android.R.layout.simple_spinner_item,bdata); badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);*/ spTrips.setAdapter(tadapter); spBuses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); bus = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spBoard.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); board = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spHighlight.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); highlight = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spTrips.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); trip = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); btnGenerate = (Button) findViewById(R.id.btnGenerate); btnGenerate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // get a new activity to show invoice preview sendData(); } }); mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size mAdapter = new DrawerAdapter(TITLES, ICONS, NAME, EMAIL, PROFILE); // Creating the Adapter of MyAdapter class(which we are going to see in a bit) // And passing the titles,icons,header view name, header view email, // and header view profile picture // Setting the adapter to RecyclerView //mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext()); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setAdapter(mAdapter); Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout); // Drawer object Assigned to the view mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is // open I am not going to put anything here) invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); // Code here will execute once drawer is closed invalidateOptionsMenu(); } }; // Drawer Toggle Object Made Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State final GestureDetector mGestureDetector = new GestureDetector(TicketingHomeActivity.this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY()); if (child != null && mGestureDetector.onTouchEvent(motionEvent)) { Drawer.closeDrawers(); if (recyclerView.getChildPosition(child) == 1) { } else if (recyclerView.getChildPosition(child) == 2) { Intent intent = new Intent(TicketingHomeActivity.this, AccountActivity.class); startActivity(intent); } else if (recyclerView.getChildPosition(child) == 3) { Intent intent = new Intent(TicketingHomeActivity.this, TicketListActivity.class); startActivity(intent); } else if (recyclerView.getChildPosition(child) == 4) { syncTicketingSynchronize(); syncTicketsSynchronize(); synchAccount(); insertBuses(); //insertTerminals(); //syncTickets(); //dialog = ProgressDialog.show(TicketingHomeActivity.this, "", "Synchronizing App Data. Please wait...", true); /*new Thread(new Runnable() { @Override public void run() { Looper.prepare(); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() {*/ // insertTerminals(); // insertBuses(); //getTickets(); //Toast.makeText(TicketingHomeActivity.this, "Looper startes ", Toast.LENGTH_SHORT).show(); /*handler.removeCallbacks(this); Looper.myLooper().quit(); } }, 30000); Looper.loop(); } }).start();*/ } else if (recyclerView.getChildPosition(child) == 5) { if (apps.getLicenceNo() != null) { Intent intent = new Intent(TicketingHomeActivity.this, TripHomeActivity.class); startActivity(intent); } else { //Intent intent = new Intent(TicketingHomeActivity.this,TestPrintActivity.class); //startActivity(intent); Toast.makeText(TicketingHomeActivity.this, "Application is in default mode you cannot use this menu", Toast.LENGTH_SHORT) .show(); } } else if (recyclerView.getChildPosition(child) == 6) { Intent intent = new Intent(TicketingHomeActivity.this, LogoutActivity.class); startActivity(intent); // Toast.makeText(TicketingHomeActivity.this, "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT).show(); } return true; } return false; } @Override public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { } }); List<Ticket> issuedTickets = db.getIssuedTickets(); Log.e("SYNC LOG", issuedTickets.toString()); }