Example usage for android.content BroadcastReceiver BroadcastReceiver

List of usage examples for android.content BroadcastReceiver BroadcastReceiver

Introduction

In this page you can find the example usage for android.content BroadcastReceiver BroadcastReceiver.

Prototype

public BroadcastReceiver() 

Source Link

Usage

From source file:com.pileproject.drive.util.broadcast.RxBroadcastReceiver.java

/**
 * Creates {@link Observable} which will produce a stream
 * when the events which are specified by {@link IntentFilter} have been issued.
 *
 * @param context a {@link Context} of the application
 * @param intentFilter an intent filter that will be passed to
 * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)}
 * @return an {@link Observable}//  w  ww  .jav a2  s . co  m
 */
public static Observable<Pair<Context, Intent>> create(final Context context, final IntentFilter intentFilter) {
    return Observable.create(new rx.Observable.OnSubscribe<Pair<Context, Intent>>() {

        @Override
        public void call(final Subscriber<? super Pair<Context, Intent>> subscriber) {
            final BroadcastReceiver receiver = new BroadcastReceiver() {

                @Override
                public void onReceive(Context context, Intent intent) {
                    subscriber.onNext(Pair.create(context, intent));
                }
            };

            context.registerReceiver(receiver, intentFilter);

            subscriber.add(Subscriptions.create(new Action0() {

                @Override
                public void call() {
                    // this line is called when the subscribers un-subscribe this Observable
                    context.unregisterReceiver(receiver);
                }
            }));

        }
    });
}

From source file:com.weidian.blockcanary.StackInfoCatcher.java

public StackInfoCatcher(Context context) {
    this.mContext = context;
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
    mBroadcastReceiver = new BroadcastReceiver() {
        @Override// w  w w. j  a  v a2 s.c  o m
        public void onReceive(Context context, Intent intent) {
            long endTime = intent.getLongExtra(LogPrinter.EXTRA_FINISH_TIME, 0);
            long startTime = intent.getLongExtra(LogPrinter.EXTRA_START_TIME, 0);
            StackTraceInfo info = getInfoByTime(endTime, startTime);
            if (null != info) {
                Log.e(TAG, "find block line");
                //info.mANRError.printStackTrace();
                Log.e(TAG, info.mLog);
            } else {
                Log.e(TAG, "no block line find");
            }
        }
    };
    manager.registerReceiver(mBroadcastReceiver, new IntentFilter(LogPrinter.ACTION_BLOCK));
}

From source file:com.plackemacher.rxreceiver.OnSubscribeLocalBroadcastRegister.java

@Override
public void call(final Subscriber<? super Intent> subscriber) {
    final LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
    final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override/*from w  w  w .  j  ava2  s  .c  o m*/
        public void onReceive(Context context, Intent intent) {
            subscriber.onNext(intent);
        }
    };

    final Subscription subscription = Subscriptions.create(new Action0() {
        @Override
        public void call() {
            localBroadcastManager.unregisterReceiver(broadcastReceiver);
        }
    });

    subscriber.add(subscription);
    localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter);
}

From source file:com.givon.anhao.BaseActivity.java

@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    if (mBroadcastReceiver == null) {
        mBroadcastReceiver = new BroadcastReceiver() {
            @Override/*from  w w  w.  ja v a  2  s  . co m*/
            public void onReceive(Context context, Intent intent) {
                finish();
            }
        };
        IntentFilter filter = new IntentFilter();
        filter.addAction(getApplicationContext().getPackageName() + Constant.ACTION_EXIT_SYSTEM);
        this.registerReceiver(mBroadcastReceiver, filter);
    }
    initLayoutView();
}

From source file:com.Duo.music.player.Services.DashClockExtensionService.java

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

    mApp = (Common) this.getApplicationContext();

    //Register a broadcast listener to listen for track updates.
    receiver = new BroadcastReceiver() {

        @Override/*from w w  w.  j av  a2  s.com*/
        public void onReceive(Context context, Intent intent) {
            updateExtensionData();

        }

    };

    LocalBroadcastManager.getInstance(this).registerReceiver((receiver),
            new IntentFilter("com.jams.music.player.NEW_SONG_UPDATE_UI"));

}

From source file:com.aniruddhc.acemusic.player.Services.DashClockExtensionService.java

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

    mApp = (Common) this.getApplicationContext();

    //Register a broadcast listener to listen for track updates.
    receiver = new BroadcastReceiver() {

        @Override/*from   w ww .  j  a v a2 s.co  m*/
        public void onReceive(Context context, Intent intent) {
            updateExtensionData();

        }

    };

    LocalBroadcastManager.getInstance(this).registerReceiver((receiver),
            new IntentFilter("com.aniruddhc.acemusic.player.NEW_SONG_UPDATE_UI"));

}

From source file:com.example.android.elizachat.MainActivity.java

@Override
protected void onCreate(Bundle saved) {
    super.onCreate(saved);
    setContentView(R.layout.main);// www.  ja v a 2 s  .c  o  m
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            processMessage(intent);
        }
    };
    mHistoryView = (TextView) findViewById(R.id.history);
    startResponderService();
}

From source file:com.example.android.wearable.elizachat.MainActivity.java

@Override
protected void onCreate(Bundle saved) {
    super.onCreate(saved);
    setContentView(R.layout.main);/*from   w ww .  j a va 2  s  .  co  m*/
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            processMessage(intent);
        }
    };
    mHistoryView = (TextView) findViewById(R.id.history);
    startResponderService(ResponderService.ACTION_INCOMING);
}

From source file:com.codelyst.pushnotification.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override/* ww  w. ja va  2  s  .  com*/
        public void onReceive(Context context, Intent intent) {
            mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            String sentToken = sharedPreferences.getString(RegistrationIntentService.GCM_TOKEN, null);
            if (sentToken != null && sentToken.length() > 0) {
                sendTokenToServer(sentToken);
                mInformationTextView.setText(sentToken);

            } else {
                mInformationTextView.setText(getString(R.string.token_error_message));
            }
        }
    };
    mInformationTextView = (TextView) findViewById(R.id.informationTextView);

    if (PlayServiceUtils.checkPlayServices(this)) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
}

From source file:com.nadmm.airports.notams.NotamFragmentBase.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mFilter = new IntentFilter();
    mFilter.addAction(NotamService.ACTION_GET_NOTAM);

    mReceiver = new BroadcastReceiver() {
        @Override//from   w ww  . ja  v  a  2s. c om
        public void onReceive(Context context, Intent intent) {
            handleNotamBroadcast(intent);
        }
    };
}