Context registerReceiver - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Context registerReceiver method.

This code example shows how to use the following methods:registerReceiver, addAction
    protected void onAttachedToWindow() { 
        super.onAttachedToWindow(); 
 
        if (!mAttached) {
            mAttached = true;
            IntentFilter filter = new IntentFilter();
 
            filter.addAction(Intent.ACTION_TIME_TICK);
            filter.addAction(Intent.ACTION_TIME_CHANGED);
            filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
            filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
 
            getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
        } 
 
        // NOTE: It's safe to do these after registering the receiver since the receiver always runs 
        // in the main thread, therefore the receiver can't run before this method returns. 
 
        // The time zone may have changed while the receiver wasn't registered, so update the Time 
        mCalendar = Calendar.getInstance(TimeZone.getDefault());
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerReceiver, addAction
	 *  
	 * @param mContext 
	 */ 
	public static void registerNetworkStateReceiver(Context mContext)
	{ 
		IntentFilter filter = new IntentFilter();
		filter.addAction(TA_ANDROID_NET_CHANGE_ACTION);
		filter.addAction(ANDROID_NET_CHANGE_ACTION);
		mContext.getApplicationContext()
				.registerReceiver(getReceiver(), filter);
	} 
 
	/** 
	 * 检查网络状态 
	 *  
	 * @param mContext 
	 */ 
	public static void checkNetworkState(Context mContext)
	{ 
		Intent intent = new Intent();
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerReceiver, addAction, addDataScheme
 
        public PackageIntentReceiver(AppListLoader loader) {
            mLoader = loader;
            IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
            filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
            filter.addDataScheme("package");
            mLoader.getContext().registerReceiver(this, filter);
            // Register for events related to sdcard installation. 
            IntentFilter sdFilter = new IntentFilter();
            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
            mLoader.getContext().registerReceiver(this, sdFilter);
        } 
 
        @Override public void onReceive(Context context, Intent intent) {
            // Tell the loader about the change. 
            mLoader.onContentChanged();
        } 
    } 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerReceiver, addAction
    protected void onAttachedToWindow() { 
        super.onAttachedToWindow(); 
 
        if (!mAttached) {
            mAttached = true;
            IntentFilter filter = new IntentFilter();
 
            filter.addAction(Intent.ACTION_TIME_TICK);
            filter.addAction(Intent.ACTION_TIME_CHANGED);
            filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
            filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
 
            getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
        } 
 
        // NOTE: It's safe to do these after registering the receiver since the receiver always runs 
        // in the main thread, therefore the receiver can't run before this method returns. 
 
        // The time zone may have changed while the receiver wasn't registered, so update the Time 
        mCalendar = Calendar.getInstance(TimeZone.getDefault());
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerReceiver
     *  
     * @param context 
     *            the context used to retrieve the app context 
     */ 
    public void listenForConnectivityChanges(Context context) {
        context.getApplicationContext().registerReceiver(
                new ConnectionChangedBroadcastReceiver(this),
                new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    } 
 
    public void setGzipEncodingEnabled(boolean enabled) {
        if (enabled) {
            httpClient.addRequestInterceptor(new GzipHttpRequestInterceptor());
            httpClient.addResponseInterceptor(new GzipHttpResponseInterceptor());
        } else { 
            httpClient.removeRequestInterceptorByClass(GzipHttpRequestInterceptor.class);
            httpClient.removeResponseInterceptorByClass(GzipHttpResponseInterceptor.class);
        } 
    } 
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerReceiver, addAction, addDataScheme
    public static class PackageIntentReceiver extends BroadcastReceiver {
        final AppListLoader mLoader;
 
        public PackageIntentReceiver(AppListLoader loader) {
            mLoader = loader;
            IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
            filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
            filter.addDataScheme("package");
            mLoader.getContext().registerReceiver(this, filter);
            // Register for events related to sdcard installation. 
            IntentFilter sdFilter = new IntentFilter();
            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
            mLoader.getContext().registerReceiver(this, sdFilter);
        } 
 
        @Override public void onReceive(Context context, Intent intent) {
            // Tell the loader about the change. 
            mLoader.onContentChanged();
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerReceiver, addAction
 
        setSummaryToName(); 
    } 
 
    public void resume() { 
        IntentFilter filter = new IntentFilter();
        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        filter.addAction(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);
        getContext().registerReceiver(mReceiver, filter);
 
        // Make sure the OK button is disabled (if necessary) after rotation 
        EditText et = getEditText();
        et.setFilters(new InputFilter[] {new LengthFilter(BLUETOOTH_NAME_MAX_LENGTH)});
        if (et != null) {
            et.addTextChangedListener(this);
            Dialog d = getDialog();
            if (d instanceof AlertDialog) {
                Button b = ((AlertDialog) d).getButton(AlertDialog.BUTTON_POSITIVE);
                b.setEnabled(et.getText().length() > 0);
            } 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerReceiver
  private Bundle results=null;
   
  protected void setUp() throws Exception { 
    super.setUp(); 
     
    getContext().registerReceiver(onBroadcast, new IntentFilter(ACTION));
  } 
   
  protected void tearDown() { 
    getContext().unregisterReceiver(onBroadcast);
  } 
   
  protected Bundle execServiceTest(Bundle input) {
    Intent i=new Intent(getInterpreterName());
     
    i.putExtra(InterpreterService.BUNDLE, input);
    i.putExtra(InterpreterService.BROADCAST_ACTION, ACTION);
     
    getContext().startService(i);
     
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getSystemService, registerReceiver
     * {@inheritDoc} 
     */ 
    @Override 
    public void setUp() throws Exception { 
        mContext = getInstrumentation().getContext();
        mDownloadManager = (DownloadManager)mContext.getSystemService(Context.DOWNLOAD_SERVICE);
        mReceiver = registerNewMultipleDownloadsReceiver();
    } 
 
    /** 
     * Helper to verify the size of a file. 
     * 
     * @param pfd The input file to compare the size of 
     * @param size The expected size of the file 
     */ 
    protected void verifyFileSize(ParcelFileDescriptor pfd, long size) {
        assertEquals(pfd.getStatSize(), size);
    } 
 
    /** 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:registerReceiver
    public boolean getNotifySignalStrength() { 
        return ((mWants & NOTIF_SIGNAL) != 0);
    } 
 
    public void registerIntent() { 
        mContext.registerReceiver(this, mFilter);
    } 
 
    public void unregisterIntent() { 
        mContext.unregisterReceiver(this);
    } 
 
    @Override 
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
 
        try { 
            if (TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED.equals(action)) {
                mSignalStrength = SignalStrength.newFromBundle(intent.getExtras());
 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Context registerReceiver Questions & Answers:

registerReceiver Method Overview
Register a BroadcastReceiver to be run in the main activity thread.
See Code Examples for other Android Context Methods: