Example usage for android.content IntentFilter addAction

List of usage examples for android.content IntentFilter addAction

Introduction

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

Prototype

public final void addAction(String action) 

Source Link

Document

Add a new Intent action to match against.

Usage

From source file:com.mobicage.rpc.http.HttpCommunicator.java

public HttpCommunicator(final MainService mainService, final Context context,
        final DatabaseManager databaseManager, final Credentials credentials,
        final ConfigurationProvider cfgProvider, final SafeRunnable onStartStashingHandler,
        final SafeRunnable onStopStashingHandler, final SDCardLogger sdcardLogger,
        final boolean wifiOnlySettingEnabled) {
    T.UI();//w  ww .ja v a2 s .c  o m

    mMainService = mainService;
    mCfgProvider = cfgProvider;
    mFinishedLock = new Object();
    mStateMachineLock = new Object();
    mStartStashingHandler = onStartStashingHandler;
    mStopStashingHandler = onStopStashingHandler;
    mWifiOnlyEnabled = wifiOnlySettingEnabled;

    mSDCardLogger = sdcardLogger;

    mAlarmManager = (AlarmManager) mMainService.getSystemService(Context.ALARM_SERVICE);

    // Create network thread for actual network communication
    mNetworkWorkerThread = new HandlerThread("rogerthat_net_worker");
    mNetworkWorkerThread.start();
    final Looper looper = mNetworkWorkerThread.getLooper();
    mNetworkHandler = new Handler(looper);
    mNetworkHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            debugLog("HTTP network thread id is " + android.os.Process.myTid());
        }
    });

    final CountDownLatch latch = new CountDownLatch(1);
    mMainService.postAtFrontOfBIZZHandler(new SafeRunnable() {
        @Override
        public void safeRun() {
            T.BIZZ();
            // For simplicity, I want to construct backlog on HTTP thread
            // This way backlog is 100% on HTTP thread
            mBacklog = new HttpBacklog(context, databaseManager);
            latch.countDown();
        }
    });
    try {
        latch.await();
    } catch (InterruptedException e) {
        bugLog(e);
    }

    mBase64Username = Base64.encodeBytes(credentials.getUsername().getBytes(), Base64.DONT_BREAK_LINES);
    mBase64Password = Base64.encodeBytes(credentials.getPassword().getBytes(), Base64.DONT_BREAK_LINES);

    mMainService.addHighPriorityIntent(HttpCommunicator.INTENT_HTTP_START_OUTGOING_CALLS);

    if (CloudConstants.USE_GCM_KICK_CHANNEL) {
        final IntentFilter filter = new IntentFilter();
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        filter.addAction(INTENT_SHOULD_RETRY_COMMUNICATION);
        mMainService.registerReceiver(mBroadcastReceiver, filter);
    }
}

From source file:com.connectsdk.discovery.DiscoveryManager.java

private void registerBroadcastReceiver() {
    if (isBroadcastReceiverRegistered == false) {
        isBroadcastReceiverRegistered = true;

        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
        context.registerReceiver(receiver, intentFilter);
    }//from   ww w.  j  a  va2 s.  co  m
}

From source file:com.ieeton.user.activity.MainActivity.java

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

    //?//from   w  ww  . jav a2 s .c o  m
    //      UmengUpdateAgent.update(this);

    setContentView(R.layout.activity_main);
    initView();

    //Ieeton
    IntentFilter intentfilter = new IntentFilter();
    intentfilter.addAction(Constants.NEED_RELOGIN_ACTION);
    intentfilter.addAction(Constants.LOGIN_ACTION);
    mIeetonReceiver = new IeetonReceiver();
    registerReceiver(mIeetonReceiver, intentfilter);

    inviteMessgeDao = new InviteMessgeDao(this);
    userDao = new UserDao(this);
    // fragment
    int index = getIntent().getIntExtra(INPUT_INDEX, INPUT_HOME);
    Utils.logd("oncreate index:" + index);
    //
    if (Utils.getMyType(this) == 5) {
        index = INPUT_HOME;
    }
    showDefaultTab(index);

    // ?BroadcastReceiver
    msgReceiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    intentFilter.setPriority(3);
    registerReceiver(msgReceiver, intentFilter);

    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(3);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // ?BroadcastReceiver
    //      IntentFilter offlineMessageIntentFilter = new IntentFilter(EMChatManager.getInstance()
    //            .getOfflineMessageBroadcastAction());
    //      registerReceiver(offlineMessageReceiver, offlineMessageIntentFilter);

    // setContactListener???
    EMContactManager.getInstance().setContactListener(new MyContactListener());
    // ??listener
    EMChatManager.getInstance().addConnectionListener(new MyConnectionListener());
    // ?listener
    EMGroupManager.getInstance().addGroupChangeListener(new MyGroupChangeListener());
    // sdkUI ??receiverlistener, ??broadcast
    EMChat.getInstance().setAppInited();
}

From source file:edu.stanford.mobisocial.dungbeetle.NearbyActivity.java

private void findBluetooth() {
    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        Intent bt = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(bt, RESULT_BT_ENABLE);
        return;/*  w  w w.j  a v a  2 s  .  c om*/
    }

    // Create a BroadcastReceiver for ACTION_FOUND
    final IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);

    final BroadcastReceiver receiver = new BroadcastReceiver() {
        public void onReceive(final Context context, final Intent intent) {
            String action = intent.getAction();
            // When discovery finds a device
            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                new Thread() {
                    public void run() {
                        BluetoothBeacon.OnDiscovered discovered = new BluetoothBeacon.OnDiscovered() {
                            @Override
                            public void onDiscovered(final byte[] data) {
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            JSONObject obj = new JSONObject(new String(data));
                                            mNearbyList.add(
                                                    new NearbyItem(NearbyItem.Type.FEED, obj.getString("name"),
                                                            Uri.parse(obj.getString("dynuri")), null));
                                            mAdapter.notifyDataSetChanged();
                                        } catch (JSONException e) {
                                            Log.e(TAG, "Error getting group info over bluetooth", e);
                                        }
                                    }
                                });
                            }
                        };
                        // Get the BluetoothDevice object from the Intent
                        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                        BluetoothBeacon.discover(NearbyActivity.this, device, discovered);
                    };
                }.start();
            }
            if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
                unregisterReceiver(this);
            }
        }
    };

    registerReceiver(receiver, filter); // Don't forget to unregister during
                                        // onDestroy
    BluetoothAdapter.getDefaultAdapter().startDiscovery();
    Toast.makeText(this, "Scanning Bluetooth...", 500).show();
}

From source file:com.bushstar.htmlcoin_android_wallet.service.BlockchainServiceImpl.java

@Override
public void onCreate() {
    serviceCreatedAt = System.currentTimeMillis();
    log.debug(".onCreate()");

    super.onCreate();

    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    final String lockName = getPackageName() + " blockchain sync";

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    application = (WalletApplication) getApplication();
    config = application.getConfiguration();
    final Wallet wallet = application.getWallet();

    bestChainHeightEver = config.getBestChainHeightEver();

    peerConnectivityListener = new PeerConnectivityListener();

    sendBroadcastPeerState(0);//  w  w  w.j  a  v a 2s.co m

    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
    registerReceiver(connectivityReceiver, intentFilter);

    blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME);
    final boolean blockChainFileExists = blockChainFile.exists();

    if (!blockChainFileExists) {
        log.info("blockchain does not exist, resetting wallet");

        wallet.clearTransactions(0);
        wallet.setLastBlockSeenHeight(-1); // magic value
        wallet.setLastBlockSeenHash(null);
    }

    try {
        blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile);
        blockStore.getChainHead(); // detect corruptions as early as possible
    } catch (final BlockStoreException x) {
        blockChainFile.delete();

        final String msg = "blockstore cannot be created";
        log.error(msg, x);
        throw new Error(msg, x);
    }

    log.info("using " + blockStore.getClass().getName());

    validHashStoreFile = new File(getDir("validhashes", Context.MODE_PRIVATE), Constants.VALID_HASHES_FILENAME);

    try {
        validHashStore = new ValidHashStore(validHashStoreFile);
    } catch (IOException x) {
        validHashStoreFile.delete();
        final String msg = "validhashstore cannot be created";
        log.error(msg, x);
        throw new Error(msg, x);
    }

    try {
        blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore, validHashStore);
    } catch (final BlockStoreException x) {
        throw new Error("blockchain cannot be created", x);
    }

    application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD);

    registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

    maybeRotateKeys();
}

From source file:com.halseyburgund.rwframework.core.RWService.java

/**
 * Adds to the specified IntentFilter the actions for the SUCCESS,
 * FAILURE, and QUEUED intent broadcasts for the server calls with the
 * given operationNames.//  w ww . ja va 2 s  . c o  m
 * 
 * @param filter IntentFilter to add actions to
 * @param operationNames to create action filters for
 * @return updated IntentFilter
 */
public static IntentFilter addOperationsToIntentFilter(IntentFilter filter, String... operationNames) {
    for (String opName : operationNames) {
        filter.addAction(RW.BROADCAST_PREFIX + opName + RW.BROADCAST_FAILURE_POSTFIX);
        filter.addAction(RW.BROADCAST_PREFIX + opName + RW.BROADCAST_SUCCESS_POSTFIX);
        filter.addAction(RW.BROADCAST_PREFIX + opName + RW.BROADCAST_QUEUED_POSTFIX);
    }

    return filter;
}

From source file:com.blu3f1re.reddwallet.service.BlockchainServiceImpl.java

@Override
public void onCreate() {
    serviceCreatedAt = System.currentTimeMillis();
    log.debug(".onCreate()");

    super.onCreate();

    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    final String lockName = getPackageName() + " blockchain sync";

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    application = (WalletApplication) getApplication();
    config = application.getConfiguration();
    final Wallet wallet = application.getWallet();

    bestChainHeightEver = config.getBestChainHeightEver();

    peerConnectivityListener = new PeerConnectivityListener();

    sendBroadcastPeerState(0);//from  w w  w  . j av a 2s .c  o m

    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
    registerReceiver(connectivityReceiver, intentFilter);

    blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME);
    final boolean blockChainFileExists = blockChainFile.exists();

    if (!blockChainFileExists) {
        log.info("blockchain does not exist, resetting wallet");

        wallet.clearTransactions(0);
        wallet.setLastBlockSeenHeight(-1); // magic value
        wallet.setLastBlockSeenHash(null);
    }

    try {
        blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile);
        blockStore.getChainHead(); // detect corruptions as early as possible

        final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime();

        if (!blockChainFileExists && earliestKeyCreationTime > 0) {
            try {
                final InputStream checkpointsInputStream = getAssets().open(Constants.CHECKPOINTS_FILENAME);
                CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore,
                        earliestKeyCreationTime);
            } catch (final IOException x) {
                log.error("problem reading checkpoints, continuing without", x);
            }
        }
    } catch (final BlockStoreException x) {
        blockChainFile.delete();

        final String msg = "blockstore cannot be created";
        log.error(msg, x);
        throw new Error(msg, x);
    }

    log.info("using " + blockStore.getClass().getName());

    try {
        blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore);
    } catch (final BlockStoreException x) {
        throw new Error("blockchain cannot be created", x);
    }

    application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD);

    registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

    maybeRotateKeys();
}

From source file:com.custom.music.MusicBrowserActivity.java

@Override
public void onResume() {
    super.onResume();
    Log.i(TAG, ">>> onResume", Log.APP);
    IntentFilter f = new IntentFilter();
    f.addAction(MediaPlaybackService.META_CHANGED);
    registerReceiver(mTrackListListener, f);
    mTabHost.setCurrentTab(mCurrentTab);
    mActivityManager.dispatchResume();/*  ww w  .j  a  va2s.com*/
    Log.i(TAG, "onResume >>>", Log.APP);
}

From source file:cn.edu.zafu.corepage.base.BaseActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_base);
    Intent mNewIntent = getIntent();//from   w w w . j av  a  2s.  co m
    //?activity
    if (null != savedInstanceState) {
        loadActivitySavedData(savedInstanceState);
        //???
        //?SaveWithActivity
    }
    mHandler = new Handler(getMainLooper());
    //handler
    mCurrentInstance = new WeakReference<BaseActivity>(this);
    //?activity
    mActivities.add(mCurrentInstance);
    //?activityactivity
    printAllActivities();
    //?activity

    init(mNewIntent);
    //?activity
    IntentFilter filter = new IntentFilter();
    filter.addAction(CoreConfig.ACTION_EXIT_APP);
    filter.addCategory(Intent.CATEGORY_DEFAULT);
    CoreConfig.getLocalBroadcastManager().registerReceiver(mExitReceiver, filter);
    //?

    //?
    AnalyticsConfig.enableEncrypt(false);
    MobclickAgent.setDebugMode(true);
    MobclickAgent.openActivityDurationTrack(false);
    MobclickAgent.updateOnlineConfig(this);
}

From source file:com.kncwallet.wallet.service.BlockchainServiceImpl.java

@Override
public void onCreate() {
    serviceCreatedAt = System.currentTimeMillis();
    log.debug(".onCreate()");

    super.onCreate();

    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    final String lockName = getPackageName() + " blockchain sync";

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    application = (WalletApplication) getApplication();
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    final Wallet wallet = application.getWallet();

    bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0);

    peerConnectivityListener = new PeerConnectivityListener();

    sendBroadcastPeerState(0);// w w w .j  a  v a  2s .co m

    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
    registerReceiver(connectivityReceiver, intentFilter);

    blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME);
    final boolean blockChainFileExists = blockChainFile.exists();

    if (!blockChainFileExists) {
        log.info("blockchain does not exist, resetting wallet");

        wallet.clearTransactions(0);
        wallet.setLastBlockSeenHeight(-1); // magic value
        wallet.setLastBlockSeenHash(null);
    }

    try {
        blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile);
        blockStore.getChainHead(); // detect corruptions as early as possible

        final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime();

        if (!blockChainFileExists && earliestKeyCreationTime > 0) {
            try {
                final InputStream checkpointsInputStream = getAssets().open(Constants.CHECKPOINTS_FILENAME);
                CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore,
                        earliestKeyCreationTime);
            } catch (final IOException x) {
                log.error("problem reading checkpoints, continuing without", x);
            }
        }
    } catch (final BlockStoreException x) {
        blockChainFile.delete();

        final String msg = "blockstore cannot be created";
        log.error(msg, x);
        throw new Error(msg, x);
    }

    log.info("using " + blockStore.getClass().getName());

    try {
        blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore);
    } catch (final BlockStoreException x) {
        throw new Error("blockchain cannot be created", x);
    }

    application.getWallet().addEventListener(walletEventListener);

    registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

    maybeRotateKeys();
}