Example usage for android.content IntentFilter IntentFilter

List of usage examples for android.content IntentFilter IntentFilter

Introduction

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

Prototype

public IntentFilter(Parcel source) 

Source Link

Usage

From source file:io.clh.lrt.androidservice.TraceListenerService.java

@Override
public void onCreate() {
    Log.i(TAG, "onCreate()");
    // Start up the thread running the service. Note that we create a
    // separate thread because the service normally runs in the process's
    // main thread, which we don't want to block. We also make it
    // background priority so CPU-intensive work will not disrupt our UI.
    HandlerThread thread = new HandlerThread("ServiceStartArguments");
    thread.start();/*www  .  j  a  v  a2 s  .co  m*/

    // Get the HandlerThread's Looper and use it for our Handler
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);

    restClient = new DefaultHttpClient();

    //network on main thread H@XXX
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    // Register the LRT receiver
    IntentFilter filter = new IntentFilter(ACTION_LRT_START);
    registerReceiver(mLrtReceiver, filter);
    filter = new IntentFilter(ACTION_LRT_TRACE);
    registerReceiver(mLrtReceiver, filter);
    filter = new IntentFilter(ACTION_LRT_STOP);
    registerReceiver(mLrtReceiver, filter);

    setNotification("LRT Tracing Service Running", true);

    infiLoop();
}

From source file:com.felkertech.n.tv.fragments.LeanbackFragment.java

@Override
public void onStart() {
    super.onStart();
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(broadcastReceiver,
            new IntentFilter(GoogleDriveBroadcastReceiver.ACTION_STATUS_CHANGED));
}

From source file:android.net.http.cts.ApacheHttpClientTest.java

private void disconnectWifiToConnectToMobile() throws InterruptedException {
    if (mHasWifi && mWifiManager.isWifiEnabled()) {
        ConnectivityActionReceiver connectMobileReceiver = new ConnectivityActionReceiver(
                ConnectivityManager.TYPE_MOBILE, State.CONNECTED);
        ConnectivityActionReceiver disconnectWifiReceiver = new ConnectivityActionReceiver(
                ConnectivityManager.TYPE_WIFI, State.DISCONNECTED);
        IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
        mContext.registerReceiver(connectMobileReceiver, filter);
        mContext.registerReceiver(disconnectWifiReceiver, filter);

        assertTrue(mWifiManager.setWifiEnabled(false));
        assertTrue(disconnectWifiReceiver.waitForStateChange());
        assertTrue(connectMobileReceiver.waitForStateChange());

        mContext.unregisterReceiver(connectMobileReceiver);
        mContext.unregisterReceiver(disconnectWifiReceiver);
    }//from w w  w .  ja v a 2  s . c o m
}

From source file:org.openbmap.activities.DialogPreferenceCatalogs.java

/**
 * Initialises download manager for GINGERBREAD and newer
 *///from w w w  .j  a  va2 s  .  c  om
@SuppressLint("NewApi")
private void initDownloadManager() {
    mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);

    mReceiver = new BroadcastReceiver() {
        @SuppressLint("NewApi")
        @Override
        public void onReceive(final Context context, final Intent intent) {
            final String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                final DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(downloadId);
                final Cursor c = mDownloadManager.query(query);
                if (c.moveToFirst()) {
                    final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                        // we're not checking download id here, that is done in handleDownloads
                        final String uriString = c
                                .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                        handleDownloads(uriString);
                    } else {
                        final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
                        Log.e(TAG, "Download failed: " + reason);
                    }
                }
            }
        }
    };

    getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:org.kde.necessitas.ministro.MinistroActivity.java

private void checkNetworkAndDownload(final boolean update) {
    if (isOnline(this))
        new CheckLibraries().execute(update);
    else {/*from w ww  .j  a v  a2  s  . co m*/
        AlertDialog.Builder builder = new AlertDialog.Builder(MinistroActivity.this);
        builder.setMessage(getResources().getString(R.string.ministro_network_access_msg));
        builder.setCancelable(true);
        builder.setNeutralButton(getResources().getString(R.string.settings_msg),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        final ProgressDialog m_dialog = ProgressDialog.show(MinistroActivity.this, null,
                                getResources().getString(R.string.wait_for_network_connection_msg), true, true,
                                new DialogInterface.OnCancelListener() {
                                    public void onCancel(DialogInterface dialog) {
                                        finishMe();
                                    }
                                });
                        getApplication().registerReceiver(new BroadcastReceiver() {
                            @Override
                            public void onReceive(Context context, Intent intent) {
                                if (isOnline(MinistroActivity.this)) {
                                    try {
                                        getApplication().unregisterReceiver(this);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    runOnUiThread(new Runnable() {
                                        public void run() {
                                            m_dialog.dismiss();
                                            new CheckLibraries().execute(update);
                                        }
                                    });
                                }
                            }
                        }, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
                        try {
                            startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                        } catch (Exception e) {
                            e.printStackTrace();
                            try {
                                startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                            } catch (Exception e1) {

                                e1.printStackTrace();
                            }
                        }
                        dialog.dismiss();
                    }
                });
        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                finishMe();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:com.megster.cordova.BluetoothPlugin.java

/**
 * Register receiver as soon as we have the context
 *///from w w  w . j  av  a 2  s.c  o  m
@Override
public void setContext(CordovaInterface ctx) {
    super.setContext(ctx);

    // Register for necessary bluetooth events
    ctx.getActivity().registerReceiver(m_bpBroadcastReceiver,
            new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED));
    ctx.getActivity().registerReceiver(m_bpBroadcastReceiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
    ctx.getActivity().registerReceiver(m_bpBroadcastReceiver, new IntentFilter(BluetoothPlugin.ACTION_UUID));
    //ctx.registerReceiver(m_bpBroadcastReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
}

From source file:com.nokia.example.capturetheflag.Controller.java

@Override
public void onResume() {
    super.onResume();
    Log.d(TAG, "Registering broadcast receiver");

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mPushHandler,
            new IntentFilter(NotificationsManagerFactory.PUSH_MESSAGE_ACTION));
    mClient.setConnectionIdle(false);//from w  w  w  .  j  a  va2s.  c  o m
    mLocationManager.start();
}

From source file:org.openbmap.activities.DialogPreferenceMaps.java

/**
 * Initialises download manager for GINGERBREAD and newer
 *//*from w w w . ja  v a 2 s . co  m*/
@SuppressLint("NewApi")
private void initDownloadManager() {

    mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);

    mReceiver = new BroadcastReceiver() {
        @SuppressLint("NewApi")
        @Override
        public void onReceive(final Context context, final Intent intent) {
            final String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                final DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(downloadId);
                final Cursor c = mDownloadManager.query(query);
                if (c.moveToFirst()) {
                    final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                        // we're not checking download id here, that is done in handleDownloads
                        final String uriString = c
                                .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                        handleDownloads(uriString);
                    } else {
                        final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
                        Log.e(TAG, "Download failed: " + reason);
                    }
                }
            }
        }
    };

    getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:com.marianhello.bgloc.LocationService.java

@Override
public void onCreate() {
    super.onCreate();
    log = LoggerManager.getLogger(LocationService.class);
    log.info("Creating LocationService");

    // An Android handler thread internally operates on a looper.
    handlerThread = new HandlerThread("LocationService.HandlerThread");
    handlerThread.start();/*w w w  .j  ava2s  .  c  om*/
    // An Android service handler is a handler running on a specific background thread.
    serviceHandler = new ServiceHandler(handlerThread.getLooper());

    dao = (DAOFactory.createLocationDAO(this));
    syncAccount = AccountHelper.CreateSyncAccount(this,
            AuthenticatorService.getAccount(getStringResource(Config.ACCOUNT_TYPE_RESOURCE)));

    registerReceiver(connectivityChangeReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}

From source file:com.example.bluetooth_faster_connection.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (D)//from  w  ww. j av a2  s  . c o  m
        Log.e(TAG, "+++ ON CREATE +++");

    // Set up the window layout
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

    // Set up the custom title
    mTitle = (TextView) findViewById(R.id.title_left_text);
    mTitle.setText(R.string.app_name);
    mTitle = (TextView) findViewById(R.id.title_right_text);
    mInfo = (TextView) findViewById(R.id.myText);

    Button mButton = (Button) findViewById(R.id.myButton);
    mButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            openOptionsMenu();
        }
    });

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    // register for background service broadcast.
    IntentFilter ifilt = new IntentFilter(DeviceDicoverService.DEVICE_CONNECTION_ADDRESS);
    ifilt.addAction(DeviceDicoverService.DEVICE_CONNECTION_INFO);
    registerReceiver(mReceiver, ifilt);

    // just for test purpose, should be deleted if not in test procedure.
    Intent service = new Intent(this, DeviceDicoverService.class);
    startService(service);

    wifii = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo wInfo = wifii.getConnectionInfo();
}