Example usage for android.support.v4.content LocalBroadcastManager getInstance

List of usage examples for android.support.v4.content LocalBroadcastManager getInstance

Introduction

In this page you can find the example usage for android.support.v4.content LocalBroadcastManager getInstance.

Prototype

public static LocalBroadcastManager getInstance(Context context) 

Source Link

Usage

From source file:com.andresrcb.gcmtest.LoggingService.java

private void doClear() {
    // Delete the log files from the device
    Log.i(LOG_TAG, "Deleting " + LOG_FILE);
    deleteFile(LOG_FILE);// www.  j ava  2 s .  c  o  m

    // Forward the command to LocalBroadcast subscribers (i.e. UI)
    Intent localIntent = new Intent(ACTION_CLEAR_LOGS);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}

From source file:ack.me.truconnectandroiddemo.TruconnectService.java

@Override
public void onCreate() {
    // The service is being created
    Log.d(TAG, "Creating service");
    Context context = getApplicationContext();

    mTruconnectManager = new TruconnectManager();
    mBroadcastManager = LocalBroadcastManager.getInstance(context);

    initCallbacks();/*from   w w  w .j a  v a 2s.c  o m*/
    initTruconnectManager();
}

From source file:bg.phpgcm2.RegistrationIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    try {//from w w  w . j  ava2  s . co m
        // [START register_for_gcm]
        // Initially this call goes out to the network to retrieve the token, subsequent calls
        // are local.
        // R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
        // See https://developers.google.com/cloud-messaging/android/start for details on this file.
        // [START get_token]
        InstanceID instanceID = InstanceID.getInstance(this);
        Log.i(TAG, "GCM Registration Token getting now ");
        String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

        // [END get_token]
        Log.i(TAG, "GCM Registration Token: " + token);

        sendRegistrationToServer(token);

        // Subscribe to topic channels
        subscribeTopics(token);

        // You should store a boolean that indicates whether the generated token has been
        // sent to your server. If the boolean is false, send the token to your server,
        // otherwise your server should have already received the token.
        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
        // [END register_for_gcm]
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);

}

From source file:co.org.cut.cut_app.gcm.RegistrationIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    try {//from  w w w .j  a v a  2 s.  c  o  m
        // [START register_for_gcm]
        // Initially this call goes out to the network to retrieve the token, subsequent calls
        // are local.
        // R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
        // See https://developers.google.com/cloud-messaging/android/start for details on this file.
        // [START get_token]
        InstanceID instanceID = InstanceID.getInstance(this);
        String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
        // [END get_token]
        Log.i(TAG, "GCM Registration Token: " + token);

        sendRegistrationToServer(token, sharedPreferences);

        // Subscribe to topic channels
        subscribeTopics(token);

        // [END register_for_gcm]
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}

From source file:com.android.madpausa.cardnotificationviewer.MainActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();
    unbindService(nConnection);/*  w ww  . j  a v a2s  . co  m*/
    LocalBroadcastManager.getInstance(this).unregisterReceiver(nReceiver);
}

From source file:ca.farrelltonsolar.classic.DayLogCalendar.java

private void unRegisterReceiver() {
    if (isReceiverRegistered) {
        try {/*from w w  w  . ja va2s  . co m*/
            LocalBroadcastManager.getInstance(DayLogCalendar.this.getActivity())
                    .unregisterReceiver(mReadingsReceiver);
        } catch (IllegalArgumentException e) {
            // Do nothing
        }
        isReceiverRegistered = false;
    }
}

From source file:au.org.ala.fielddata.mobile.ViewSavedRecordsActivity.java

@Override
public void onPause() {
    super.onPause();

    LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(uploadReceiver);
    uploadReceiver = null;
}

From source file:ca.appvelopers.mcgillmobile.ui.BaseActivity.java

@Override
protected void onPause() {
    super.onPause();
    LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
}

From source file:com.amaze.filemanager.services.asynctasks.LoadSearchList.java

@Override
// Once the image is downloaded, associates it to the imageView
protected void onPostExecute(ArrayList<Layoutelements> bitmap) {
    if (isCancelled()) {
        bitmap = null;// ww  w .  j ava2  s .c  o m

    }
    try {
        if (bitmap != null) {
            ((TextView) ma.pathbar.findViewById(R.id.pathname))
                    .setText(ma.utils.getString(ma.getActivity(), R.string.searchresults));
            ma.adapter = new Recycleradapter(ma, bitmap, ma.getActivity());
            try {
                ma.listView.setAdapter(ma.adapter);
                ma.results = true;
                try {
                    Intent i = new Intent("updatepager");
                    LocalBroadcastManager.getInstance(ma.getActivity()).sendBroadcast(i);
                } catch (Exception e) {

                    e.printStackTrace();
                }

            } catch (Exception e) {
            }
            ma.buttons.setVisibility(View.GONE);

        }
    } catch (Exception e) {
    }

}

From source file:com.alphabetbloc.accessmrs.services.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        final SyncResult syncResult) {

    long before = System.currentTimeMillis();
    if (App.DEBUG)
        Log.v(TAG, "Sync Requested... asking user.");
    Thread.currentThread().setName(TAG);

    mSyncManager = new SyncManager(mContext);

    // ask user to sync
    int count = 0;
    while (!SyncManager.sStartSync.get() && !SyncManager.sCancelSync.get() && count < 20) {
        android.os.SystemClock.sleep(1000);
        count++;/*from  w  w w.j a va 2  s .c om*/
        if (App.DEBUG)
            Log.v(TAG, "Waiting for User with count=" + count);
    }

    // sync
    if (!SyncManager.sCancelSync.get()) {
        if (App.DEBUG)
            Log.v(TAG, "Starting an actual sync");
        // Inform Activity
        Intent broadcast = new Intent(SyncManager.SYNC_MESSAGE);
        broadcast.putExtra(SyncManager.START_NEW_SYNC, true);
        LocalBroadcastManager.getInstance(mContext).sendBroadcast(broadcast);

        // Start the Sync
        performSync(syncResult);
    } else {
        if (App.DEBUG)
            Log.v(TAG, "User cancelled the sync");
    }

    SyncManager.sEndSync.set(true);
    SyncManager.sStartSync.set(false);
    SyncManager.sCancelSync.set(false);

    if (App.DEBUG)
        Log.v(TAG, "sync is now ending");
    if (App.DEBUG)
        Log.v("SYNC BENCHMARK",
                "Total Sync Time: \n" + sTimeLog.format(new Date(System.currentTimeMillis() - before)));
}