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.afrolkin.samplepushclient.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.afrolkin.samplepushclient.R.layout.activity_main);

    // Layout element references
    registerButton = (Button) findViewById(R.id.register_button);
    unregisterButton = (Button) findViewById(R.id.unregister_button);
    registrationStatusTextView = (TextView) findViewById(R.id.registration_status);
    registrationIDTextView = (TextView) findViewById(R.id.registration_id);
    senderIDTextView = (TextView) findViewById(R.id.sender_id);

    // Register local receiver to receive broadcasts from GCMIntentService
    IntentFilter filter = new IntentFilter(getString(R.string.register_status_action));
    filter.addAction(getString(R.string.push_message_action));
    LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, filter);

    registerButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from w  ww  .  java 2  s .  com*/
        public void onClick(View v) {
            registerGcm();
        }
    });

    unregisterButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            unregisterGcm();
        }
    });

    checkSenderID(SENDER_ID);
    senderIDTextView.setText(SENDER_ID);

    // Try to register GCM on first open
    registerGcm();
}

From source file:com.android.aft.AFNotificator.AFNotificatorReceiver.java

public AFNotificatorReceiver(Context ctx, String name, Object target, HashSet<AFNotificatorEvent> events) {
    super(name, events);
    mTarget = target;/*from w  w  w  .  j  av  a2s.com*/

    mLbm = LocalBroadcastManager.getInstance(ctx);
    mLbm.registerReceiver(mMessageReceiver, new IntentFilter(formatActionName(mName)));
}

From source file:au.id.micolous.frogjump.RegistrationIntentService.java

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

    try {//from  w w  w .  j av  a  2 s.c om
        InstanceID instanceID = InstanceID.getInstance(this);
        String gcm_token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
        Log.i(TAG, "GCM Registration Token: " + gcm_token);
        Log.i(TAG, "GCM App ID: " + getString(R.string.gcm_defaultSenderId));

        String token = GoogleCloudMessaging.getInstance(this).register(getString(R.string.gcm_defaultSenderId));
        Log.i(TAG, "Registered token: " + token);
        sendRegistrationToService(token);

        sharedPreferences.edit().putBoolean(ApplicationPreferences.SENT_TOKEN_TO_SERVER, true)
                .putString(ApplicationPreferences.GCM_TOKEN, token).apply();
    } catch (Exception ex) {
        Log.d(TAG, "Failed to complete token refresh", ex);
        sharedPreferences.edit().putBoolean(ApplicationPreferences.SENT_TOKEN_TO_SERVER, false)
                .putString(ApplicationPreferences.GCM_TOKEN, null).apply();
    }

    Intent registrationComplete = new Intent(ApplicationPreferences.REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}

From source file:com.android.example.notificationlistener.NotificationListenerActivity.java

@Override
protected void onStop() {
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mRefreshListener);
    super.onStop();
}

From source file:com.android.contacts.util.concurrent.ListenableFutureLoader.java

public ListenableFutureLoader(Context context, IntentFilter reloadBroadcastFilter) {
    super(context);
    mUiExecutor = ContactsExecutors.newUiThreadExecutor();
    mReloadFilter = reloadBroadcastFilter;
    mLocalBroadcastManager = LocalBroadcastManager.getInstance(context);
}

From source file:ac.robinson.bettertogether.api.messaging.PluginConnectionDelegate.java

public void onDestroy() {
    LocalBroadcastManager.getInstance(mContext).unregisterReceiver(mLocalBroadcastReceiver);
}

From source file:com.android.trustagent.test.SampleTrustAgent.java

@Override
public void onCreate() {
    super.onCreate();
    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);

    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_GRANT_TRUST);
    filter.addAction(ACTION_REVOKE_TRUST);
    mLocalBroadcastManager.registerReceiver(mReceiver, filter);
    if (ALLOW_EXTERNAL_BROADCASTS) {
        registerReceiver(mReceiver, filter);
    }/* w w  w  . ja v  a2  s  .c o m*/

    setManagingTrust(getIsManagingTrust(this));
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
}

From source file:com.android.services.ServiceDemoActivity.java

@Override
public void onResume() {
    super.onResume();
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver,
            new IntentFilter(MyService.BROADCAST_ACTION));
}

From source file:cc.softwarefactory.lokki.android.fragments.PlacesFragment.java

@Override
public void onResume() {

    Log.d(TAG, "onResume");
    super.onResume();
    LocalBroadcastManager.getInstance(context).registerReceiver(mMessageReceiver,
            new IntentFilter("PLACES-UPDATE"));
    LocalBroadcastManager.getInstance(context).registerReceiver(mMessageReceiver,
            new IntentFilter("LOCATION-UPDATE"));
}

From source file:com.android.fpuna.activityrecognition.DetectedActivitiesIntentService.java

/**
 * Handles incoming intents.//from  w w  w . ja va  2s.co  m
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    Intent localIntent = new Intent(Constants.BROADCAST_ACTION);

    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<HumanActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    // Log each activity.
    Log.i(TAG, "activities detected");
    for (HumanActivity da : detectedActivities) {
        Log.i(TAG, Constants.getActivityString(getApplicationContext(), da.getType()) + " " + da.getConfidence()
                + "%");
    }

    // Broadcast the list of detected activities.
    localIntent.putExtra(Constants.ACTIVITY_EXTRA, detectedActivities);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}