Search in sources :

Example 46 with BroadcastReceiver

use of android.content.BroadcastReceiver in project UltimateAndroid by cymcsg.

the class StaggeredGridEmptyViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.staggered_grid_view_activity_sgv_empy_view);
    setTitle("SGV");
    mGridView = (StaggeredGridView) findViewById(R.id.grid_view);
    LayoutInflater layoutInflater = getLayoutInflater();
    View header = layoutInflater.inflate(R.layout.staggered_grid_view_list_item_header_footer, null);
    View footer = layoutInflater.inflate(R.layout.staggered_grid_view_list_item_header_footer, null);
    TextView txtHeaderTitle = (TextView) header.findViewById(R.id.txt_title);
    TextView txtFooterTitle = (TextView) footer.findViewById(R.id.txt_title);
    txtHeaderTitle.setText("THE HEADER!");
    txtFooterTitle.setText("THE FOOTER!");
    mGridView.addHeaderView(header);
    mGridView.addFooterView(footer);
    mGridView.setEmptyView(findViewById(android.R.id.empty));
    mAdapter = new SampleAdapter(this, R.id.txt_line1);
    // do we have saved data?
    if (savedInstanceState != null) {
        mData = savedInstanceState.getStringArrayList(SAVED_DATA_KEY);
        fillAdapter();
    }
    if (mData == null) {
        mData = SampleData.generateSampleData();
    }
    mGridView.setAdapter(mAdapter);
    mGridView.setOnItemClickListener(this);
    fetchDataReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context receiverContext, Intent receiverIntent) {
            fillAdapter();
        }
    };
    LocalBroadcastManager.getInstance(this).registerReceiver(fetchDataReceiver, new IntentFilter(FETCH_DATA_FILTER));
    fetchData();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) AbsListView(android.widget.AbsListView) StaggeredGridView(com.marshalchen.common.uimodule.staggeredgridview.StaggeredGridView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 47 with BroadcastReceiver

use of android.content.BroadcastReceiver in project AntennaPod by AntennaPod.

the class PlaybackServiceFlavorHelper method registerWifiBroadcastReceiver.

void registerWifiBroadcastReceiver() {
    if (wifiBroadcastReceiver != null) {
        return;
    }
    wifiBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
                NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
                boolean isConnected = info.isConnected();
                //apparently this method gets called twice when a change happens, but one run is enough.
                if (isConnected && !wifiConnectivity) {
                    wifiConnectivity = true;
                    castManager.startCastDiscovery();
                    castManager.reconnectSessionIfPossible(RECONNECTION_ATTEMPT_PERIOD_S, NetworkUtils.getWifiSsid());
                } else {
                    wifiConnectivity = isConnected;
                }
            }
        }
    };
    callback.registerReceiver(wifiBroadcastReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) NetworkInfo(android.net.NetworkInfo) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 48 with BroadcastReceiver

use of android.content.BroadcastReceiver in project react-native-push-notification by zo0r.

the class RNPushNotification method registerNotificationsReceiveNotificationActions.

private void registerNotificationsReceiveNotificationActions(ReadableArray actions) {
    IntentFilter intentFilter = new IntentFilter();
    // Add filter for each actions.
    for (int i = 0; i < actions.size(); i++) {
        String action = actions.getString(i);
        intentFilter.addAction(getReactApplicationContext().getPackageName() + "." + action);
    }
    getReactApplicationContext().registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getBundleExtra("notification");
            // Notify the action.
            mJsDelivery.notifyNotificationAction(bundle);
            // Dismiss the notification popup.
            NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
            int notificationID = Integer.parseInt(bundle.getString("id"));
            manager.cancel(notificationID);
        }
    }, intentFilter);
}
Also used : Context(android.content.Context) ReactContext(com.facebook.react.bridge.ReactContext) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) Bundle(android.os.Bundle) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 49 with BroadcastReceiver

use of android.content.BroadcastReceiver in project react-native-push-notification by zo0r.

the class RNPushNotification method registerNotificationsRegistration.

private void registerNotificationsRegistration() {
    IntentFilter intentFilter = new IntentFilter(getReactApplicationContext().getPackageName() + ".RNPushNotificationRegisteredToken");
    getReactApplicationContext().registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String token = intent.getStringExtra("token");
            WritableMap params = Arguments.createMap();
            params.putString("deviceToken", token);
            mJsDelivery.sendEvent("remoteNotificationsRegistered", params);
        }
    }, intentFilter);
}
Also used : Context(android.content.Context) ReactContext(com.facebook.react.bridge.ReactContext) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) IntentFilter(android.content.IntentFilter) WritableMap(com.facebook.react.bridge.WritableMap) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 50 with BroadcastReceiver

use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.

the class BluetoothTestUtils method disable.

/**
     * Disables Bluetooth and checks to make sure that Bluetooth was turned off and that the correct
     * actions were broadcast.
     *
     * @param adapter The BT adapter.
     */
public void disable(BluetoothAdapter adapter) {
    writeOutput("Disabling Bluetooth adapter.");
    assertTrue(adapter.isEnabled());
    int btState = adapter.getState();
    final Semaphore completionSemaphore = new Semaphore(0);
    final BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (!BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
                return;
            }
            final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
            if (state == BluetoothAdapter.STATE_OFF) {
                completionSemaphore.release();
            }
        }
    };
    final IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    mContext.registerReceiver(receiver, filter);
    assertTrue(adapter.disable());
    boolean success = false;
    try {
        success = completionSemaphore.tryAcquire(ENABLE_DISABLE_TIMEOUT, TimeUnit.MILLISECONDS);
        writeOutput(String.format("disable() completed in 0 ms"));
    } catch (final InterruptedException e) {
    // This should never happen but just in case it does, the test will fail anyway.
    }
    mContext.unregisterReceiver(receiver);
    if (!success) {
        fail(String.format("disable() timeout: state=%d (expected %d)", btState, BluetoothAdapter.STATE_OFF));
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Semaphore(java.util.concurrent.Semaphore) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)637 Intent (android.content.Intent)564 Context (android.content.Context)493 IntentFilter (android.content.IntentFilter)441 PendingIntent (android.app.PendingIntent)120 Test (org.junit.Test)109 ArrayList (java.util.ArrayList)34 RemoteException (android.os.RemoteException)29 Bundle (android.os.Bundle)24 IOException (java.io.IOException)23 Point (android.graphics.Point)20 Semaphore (java.util.concurrent.Semaphore)20 View (android.view.View)19 Handler (android.os.Handler)18 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)17 ComponentName (android.content.ComponentName)16 TextView (android.widget.TextView)16 PackageMonitor (com.android.internal.content.PackageMonitor)15 ApplicationInfo (android.content.pm.ApplicationInfo)14 AndroidRuntimeException (android.util.AndroidRuntimeException)14