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:com.esminis.server.library.service.server.installpackage.InstallerPackage.java

private void stopServer(Context context, ServerControl serverControl) {
    final CyclicBarrier barrier = new CyclicBarrier(2);
    final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override//from w  ww .  j av a  2  s .  co  m
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction() == null
                    || !intent.getAction().equals(MainActivity.getIntentActionServerStatus(context))) {
                return;
            }
            final Bundle extras = intent.getExtras();
            if (extras == null || extras.containsKey("errorLine") || extras.getBoolean("running")) {
                return;
            }
            try {
                barrier.await();
            } catch (InterruptedException | BrokenBarrierException ignored) {
            }
        }
    };
    context.registerReceiver(receiver, new IntentFilter(MainActivity.getIntentActionServerStatus(context)));
    preferences.set(context, Preferences.SERVER_STARTED, false);
    serverControl.requestStop(null);
    try {
        barrier.await();
    } catch (InterruptedException | BrokenBarrierException ignored) {
    }
    context.unregisterReceiver(receiver);
}

From source file:com.aibasis.parent.DemoHXSDKHelper.java

@Override
protected void initListener() {
    super.initListener();

    IntentFilter callFilter = new IntentFilter(EMChatManager.getInstance().getIncomingCallBroadcastAction()
            .replace("inviteeasemob", "invite.easemob"));

    Log.i("jijun-initListener", EMChatManager.getInstance().getIncomingCallBroadcastAction());

    if (callReceiver == null) {
        callReceiver = new CallReceiver();
    }/*from   w w w . j  a va 2  s.c  om*/

    //?
    appContext.registerReceiver(callReceiver, callFilter);
    //??
    initEventListener();
}

From source file:de.mangelow.throughput.NotificationService.java

@Override
public void onCreate() {
    super.onCreate();
    if (D)// w w w . j  a  va  2 s .c om
        Log.d(TAG, "Service started");

    context = getApplicationContext();
    res = context.getResources();

    if (tmanager == null) {
        tmanager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        tmanager.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(mBroadcastReceiver, filter);

    int[] refresh_values = res.getIntArray(R.array.refresh_values);
    long refresh = (long) refresh_values[MainActivity.loadIntPref(context, MainActivity.REFRESH,
            MainActivity.REFRESH_DEFAULT)];

    modifyNotification(R.drawable.ic_stat_zero, null, "", "", new Intent());

    if (handler == null) {
        handler = new Handler();
        handler.postDelayed(mRunnable, refresh);
    }

}

From source file:com.googlecode.android_scripting.facade.EventFacade.java

/**
 * Registers a listener for a new broadcast signal
 *///from w  ww . j a v  a 2 s  .  com
@Rpc(description = "Registers a listener for a new broadcast signal")
public boolean eventRegisterForBroadcast(@RpcParameter(name = "category") String category,
        @RpcParameter(name = "enqueue", description = "Should this events be added to the event queue or only dispatched") @RpcDefault(value = "true") Boolean enqueue) {
    if (mBroadcastListeners.containsKey(category)) {
        return false;
    }

    BroadcastListener b = new BroadcastListener(this, enqueue.booleanValue());
    IntentFilter c = new IntentFilter(category);
    mContext.registerReceiver(b, c);
    mBroadcastListeners.put(category, b);

    return true;
}

From source file:com.dudka.rich.streamingmusicplayer.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(INTENT_FILTER));
    musicPlayerUI.hidePlayerControls();// w  w  w .j  a v  a  2  s  . c om
    if (isPlaying) {
        musicPlayerUI.showPlayerControls();
        musicPlayerUI.populateSongInfo(songName, artistName, coverImage);
    }
}

From source file:es.udc.robotcontrol.testapp.comunication.ConectorPlaca.java

public void conectarManual(Context ctx) throws TransmisionErrorException {
    Log.i(Constantes.TAG_CONECTOR, "Conectando manualmente. modo - Host");
    /* Get the USB manager from the requesting context */
    this.manager = (UsbManager) ctx.getSystemService(Context.USB_SERVICE);

    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Iterator<UsbDevice> it = deviceList.values().iterator();

    PendingIntent mPermissionIntent = PendingIntent.getBroadcast(ctx, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    ctx.registerReceiver(mUsbReceiver, filter);

    if (it.hasNext()) {
        device = it.next();//from   w w w.j a  v a2s .co m
        manager.requestPermission(device, mPermissionIntent);
        conectar();
    } else {
        Log.i(Constantes.TAG_CONECTOR, "No se han encontrado dispositivos");
        throw new TransmisionErrorException("No se han encontrado dispositivos");
    }
}

From source file:es.udc.fic.android.robot_control.robot.ConectorPlaca.java

public void conectarManual(Context ctx) throws TransmisionErrorException {
    Log.i(C.ROBOT_TAG, "Conectando manualmente. modo - Host");
    /* Get the USB manager from the requesting context */
    this.manager = (UsbManager) ctx.getSystemService(Context.USB_SERVICE);

    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Iterator<UsbDevice> it = deviceList.values().iterator();

    PendingIntent mPermissionIntent = PendingIntent.getBroadcast(ctx, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    ctx.registerReceiver(mUsbReceiver, filter);

    if (it.hasNext()) {
        device = it.next();/*from   w  w w  .java  2s  . c  o m*/
        manager.requestPermission(device, mPermissionIntent);
        //conectar();
    } else {
        Log.i(C.ROBOT_TAG, "No se han encontrado dispositivos");
        throw new TransmisionErrorException("No se han encontrado dispositivos");
    }
}

From source file:com.trellmor.berrymotes.sync.EmoteDownloader.java

public void start(SyncResult syncResult) {
    Log.info("EmoteDownload started");

    this.updateNetworkInfo();

    mSyncResult = syncResult;//from   ww  w .  j av  a2 s. c om

    if (!mIsConnected) {
        Log.error("Network not available");
        syncResult.stats.numIoExceptions++;
        return;
    }

    // Registers BroadcastReceiver to track network connection changes.
    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    NetworkReceiver receiver = new NetworkReceiver();
    mContext.registerReceiver(receiver, filter);

    ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);

    mHttpClient = AndroidHttpClient.newInstance(USER_AGENT);
    try {
        String[] subreddits = getSubreddits();

        for (String subreddit : subreddits) {
            if (mSubreddits.isChecked(subreddit)) {
                Runnable subredditEmoteDownloader = new SubredditEmoteDownloader(mContext, this, subreddit);
                executor.execute(subredditEmoteDownloader);
            } else {
                // Delete this subreddit
                deleteSubreddit(subreddit, mContentResolver);
                // Reset last download date
                SharedPreferences.Editor settings = PreferenceManager.getDefaultSharedPreferences(mContext)
                        .edit();
                settings.remove(SettingsActivity.KEY_SYNC_LAST_MODIFIED + subreddit);
                settings.commit();
            }
        }
        executor.shutdown();
        executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
    } catch (URISyntaxException e) {
        Log.error("Emotes URL is malformed", e);
        synchronized (mSyncResult) {
            mSyncResult.stats.numParseExceptions++;
            if (mSyncResult.delayUntil < 60 * 60)
                mSyncResult.delayUntil = 60 * 60;
        }
        return;
    } catch (IOException e) {
        Log.error("Error reading from network: " + e.getMessage(), e);
        synchronized (mSyncResult) {
            mSyncResult.stats.numIoExceptions++;
            if (mSyncResult.delayUntil < 30 * 60)
                mSyncResult.delayUntil = 30 * 60;
        }
        return;
    } catch (InterruptedException e) {
        synchronized (mSyncResult) {
            syncResult.moreRecordsToGet = true;
        }

        Log.info("Sync interrupted");

        executor.shutdownNow();
        try {
            executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
        } catch (InterruptedException e2) {
        }

        Thread.currentThread().interrupt();
    } finally {
        Log.info("Deleted emotes: " + Long.toString(mSyncResult.stats.numDeletes));
        Log.info("Added emotes: " + Long.toString(mSyncResult.stats.numInserts));

        // Unregisters BroadcastReceiver at the end
        mContext.unregisterReceiver(receiver);

        mHttpClient.close();
    }

    Log.info("EmoteDownload finished");
}

From source file:com.tealeaf.NativeShim.java

public NativeShim(TextManager textManager, TextureLoader textureLoader, SoundQueue soundQueue,
        LocalStorage localStorage, ContactList contactList, LocationManager locationManager,
        ResourceManager resourceManager, TeaLeaf context) {
    this.textManager = textManager;
    this.textureLoader = textureLoader;
    new Thread(this.textureLoader).start();
    this.soundQueue = soundQueue;
    this.localStorage = localStorage;
    this.contactList = contactList;
    this.haptics = new Haptics(context);
    this.locationManager = locationManager;
    this.resourceManager = resourceManager;
    this.context = context;
    this.remoteLogger = context.getRemoteLogger();
    this.connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    this.networkStateReceiver = new NetworkStateReceiver(this);
    this.onlineStatus = false;
    this.updateOnlineStatus();

    this.statusBarHeight = 0;
    int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        this.statusBarHeight = context.getResources().getDimensionPixelSize(resourceId);
        logger.log("status bar height:", this.statusBarHeight);
    }/*  w ww.  j a  va 2  s .  com*/

    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    context.registerReceiver(this.networkStateReceiver, filter);

}

From source file:com.andrewquitmeyer.MarkYourTerritory.DemoKitActivity.java

/** Called when the activity is first created. */
@Override//from  w  w  w.  j  av  a  2 s  .  c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mUsbManager = UsbManager.getInstance(this);
    mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    registerReceiver(mUsbReceiver, filter);

    if (getLastNonConfigurationInstance() != null) {
        mAccessory = (UsbAccessory) getLastNonConfigurationInstance();
        openAccessory(mAccessory);
    }

    setContentView(R.layout.maintwo);
    nodeviceview = (View) findViewById(R.id.noDevice);

    enableControls(false);
}