Example usage for android.content IntentFilter addDataScheme

List of usage examples for android.content IntentFilter addDataScheme

Introduction

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

Prototype

public final void addDataScheme(String scheme) 

Source Link

Document

Add a new Intent data scheme to match against.

Usage

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

@Override
public void onResume() {
    super.onResume();
    if (materialDialog != null && !materialDialog.isShowing()) {
        materialDialog.show();/*from   w  w  w. java  2  s  .co  m*/
        materialDialog = null;
    }

    IntentFilter newFilter = new IntentFilter();
    newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    newFilter.addDataScheme(ContentResolver.SCHEME_FILE);
    registerReceiver(mainActivityHelper.mNotificationReceiver, newFilter);
    registerReceiver(receiver2, new IntentFilter(TAG_INTENT_FILTER_GENERAL));
    if (getSupportFragmentManager().findFragmentById(R.id.content_frame).getClass().getName()
            .contains("TabFragment")) {

        floatingActionButton.setVisibility(View.VISIBLE);
        floatingActionButton.showMenuButton(false);
    } else {

        floatingActionButton.setVisibility(View.INVISIBLE);
        floatingActionButton.hideMenuButton(false);
    }

    if (SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // Registering intent filter for OTG
        IntentFilter otgFilter = new IntentFilter();
        otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
        otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
        registerReceiver(mOtgReceiver, otgFilter);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // let's register encryption service to know when we've decrypted
        Intent encryptIntent = new Intent(this, EncryptService.class);
        bindService(encryptIntent, mEncryptServiceConnection, 0);

        if (!isEncryptOpen && encryptBaseFile != null) {
            // we've opened the file and are ready to delete it
            // don't move this to ondestroy as we'll be getting destroyed and starting
            // an async task just before it is not a good idea
            ArrayList<BaseFile> baseFiles = new ArrayList<>();
            baseFiles.add(encryptBaseFile);
            new DeleteTask(getContentResolver(), this).execute(baseFiles);
        }
    }
}

From source file:com.av.remusic.service.MediaService.java

public void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            @Override/*from   w ww.  j  a  v a 2  s  .c  o m*/
            public void onReceive(final Context context, final Intent intent) {
                final String action = intent.getAction();
                if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                    saveQueue(true);
                    mQueueIsSaveable = false;
                    closeExternalStorageFiles(intent.getData().getPath());
                } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                    mMediaMountedCount++;
                    mCardId = getCardId();
                    reloadQueueAfterPermissionCheck();
                    mQueueIsSaveable = true;
                    notifyChange(QUEUE_CHANGED);
                    notifyChange(META_CHANGED);
                }
            }
        };
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_EJECT);
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addDataScheme("file");
        registerReceiver(mUnmountReceiver, filter);
    }
}

From source file:org.pocketworkstation.pckeyboard.LatinIME.java

@Override
public void onCreate() {
    Log.i("PCKeyboard", "onCreate(), os.version=" + System.getProperty("os.version"));
    KeyboardSwitcher.init(this);
    super.onCreate();
    sInstance = this;
    // setStatusIcon(R.drawable.ime_qwerty);
    mResources = getResources();//from w  ww  .j a  v a 2 s  .co  m
    final Configuration conf = mResources.getConfiguration();
    mOrientation = conf.orientation;
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mLanguageSwitcher = new LanguageSwitcher(this);
    mLanguageSwitcher.loadLocales(prefs);
    mKeyboardSwitcher = KeyboardSwitcher.getInstance();
    mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher);
    mSystemLocale = conf.locale.toString();
    mLanguageSwitcher.setSystemLocale(conf.locale);
    String inputLanguage = mLanguageSwitcher.getInputLanguage();
    if (inputLanguage == null) {
        inputLanguage = conf.locale.toString();
    }
    Resources res = getResources();
    mReCorrectionEnabled = prefs.getBoolean(PREF_RECORRECTION_ENABLED,
            res.getBoolean(R.bool.default_recorrection_enabled));
    mConnectbotTabHack = prefs.getBoolean(PREF_CONNECTBOT_TAB_HACK,
            res.getBoolean(R.bool.default_connectbot_tab_hack));
    mFullscreenOverride = prefs.getBoolean(PREF_FULLSCREEN_OVERRIDE,
            res.getBoolean(R.bool.default_fullscreen_override));
    mForceKeyboardOn = prefs.getBoolean(PREF_FORCE_KEYBOARD_ON,
            res.getBoolean(R.bool.default_force_keyboard_on));
    mKeyboardNotification = prefs.getBoolean(PREF_KEYBOARD_NOTIFICATION,
            res.getBoolean(R.bool.default_keyboard_notification));
    mSuggestionsInLandscape = prefs.getBoolean(PREF_SUGGESTIONS_IN_LANDSCAPE,
            res.getBoolean(R.bool.default_suggestions_in_landscape));
    mHeightPortrait = getHeight(prefs, PREF_HEIGHT_PORTRAIT, res.getString(R.string.default_height_portrait));
    mHeightLandscape = getHeight(prefs, PREF_HEIGHT_LANDSCAPE,
            res.getString(R.string.default_height_landscape));
    LatinIME.sKeyboardSettings.hintMode = Integer
            .parseInt(prefs.getString(PREF_HINT_MODE, res.getString(R.string.default_hint_mode)));
    LatinIME.sKeyboardSettings.longpressTimeout = getPrefInt(prefs, PREF_LONGPRESS_TIMEOUT,
            res.getString(R.string.default_long_press_duration));
    LatinIME.sKeyboardSettings.renderMode = getPrefInt(prefs, PREF_RENDER_MODE,
            res.getString(R.string.default_render_mode));
    mSwipeUpAction = prefs.getString(PREF_SWIPE_UP, res.getString(R.string.default_swipe_up));
    mSwipeDownAction = prefs.getString(PREF_SWIPE_DOWN, res.getString(R.string.default_swipe_down));
    mSwipeLeftAction = prefs.getString(PREF_SWIPE_LEFT, res.getString(R.string.default_swipe_left));
    mSwipeRightAction = prefs.getString(PREF_SWIPE_RIGHT, res.getString(R.string.default_swipe_right));
    mVolUpAction = prefs.getString(PREF_VOL_UP, res.getString(R.string.default_vol_up));
    mVolDownAction = prefs.getString(PREF_VOL_DOWN, res.getString(R.string.default_vol_down));
    sKeyboardSettings.initPrefs(prefs, res);

    mVoiceRecognitionTrigger = new VoiceRecognitionTrigger(this);

    updateKeyboardOptions();

    PluginManager.getPluginDictionaries(getApplicationContext());
    mPluginManager = new PluginManager(this);
    final IntentFilter pFilter = new IntentFilter();
    pFilter.addDataScheme("package");
    pFilter.addAction("android.intent.action.PACKAGE_ADDED");
    pFilter.addAction("android.intent.action.PACKAGE_REPLACED");
    pFilter.addAction("android.intent.action.PACKAGE_REMOVED");
    registerReceiver(mPluginManager, pFilter);

    LatinIMEUtil.GCUtils.getInstance().reset();
    boolean tryGC = true;
    for (int i = 0; i < LatinIMEUtil.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
        try {
            initSuggest(inputLanguage);
            tryGC = false;
        } catch (OutOfMemoryError e) {
            tryGC = LatinIMEUtil.GCUtils.getInstance().tryGCOrWait(inputLanguage, e);
        }
    }

    mOrientation = conf.orientation;

    // register to receive ringer mode changes for silent mode
    IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
    registerReceiver(mReceiver, filter);
    prefs.registerOnSharedPreferenceChangeListener(this);
    setNotification(mKeyboardNotification);
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

@Override
public void onCreate() {
    Log.i("PCKeyboard", "onCreate(), os.version=" + System.getProperty("os.version"));
    TKIMELogger.init(this);
    KeyboardSwitcher.init(this);
    super.onCreate();
    sInstance = this;
    // setStatusIcon(R.drawable.ime_qwerty);
    mResources = getResources();// w w w  .j a  va  2s . c  o  m
    final Configuration conf = mResources.getConfiguration();
    mOrientation = conf.orientation;
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mLanguageSwitcher = new LanguageSwitcher(this);
    mLanguageSwitcher.loadLocales(prefs);
    mKeyboardSwitcher = KeyboardSwitcher.getInstance();
    mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher);
    mSystemLocale = conf.locale.toString();
    mLanguageSwitcher.setSystemLocale(conf.locale);
    String inputLanguage = mLanguageSwitcher.getInputLanguage();
    if (inputLanguage == null) {
        inputLanguage = conf.locale.toString();
    }
    Resources res = getResources();
    mReCorrectionEnabled = prefs.getBoolean(PREF_RECORRECTION_ENABLED,
            res.getBoolean(R.bool.default_recorrection_enabled));
    mConnectbotTabHack = prefs.getBoolean(PREF_CONNECTBOT_TAB_HACK,
            res.getBoolean(R.bool.default_connectbot_tab_hack));
    mFullscreenOverride = prefs.getBoolean(PREF_FULLSCREEN_OVERRIDE,
            res.getBoolean(R.bool.default_fullscreen_override));
    mForceKeyboardOn = prefs.getBoolean(PREF_FORCE_KEYBOARD_ON,
            res.getBoolean(R.bool.default_force_keyboard_on));
    mKeyboardNotification = prefs.getBoolean(PREF_KEYBOARD_NOTIFICATION,
            res.getBoolean(R.bool.default_keyboard_notification));
    mSuggestionsInLandscape = prefs.getBoolean(PREF_SUGGESTIONS_IN_LANDSCAPE,
            res.getBoolean(R.bool.default_suggestions_in_landscape));
    mHeightPortrait = getHeight(prefs, PREF_HEIGHT_PORTRAIT, res.getString(R.string.default_height_portrait));
    mHeightLandscape = getHeight(prefs, PREF_HEIGHT_LANDSCAPE,
            res.getString(R.string.default_height_landscape));
    LatinIME.sKeyboardSettings.hintMode = Integer
            .parseInt(prefs.getString(PREF_HINT_MODE, res.getString(R.string.default_hint_mode)));
    LatinIME.sKeyboardSettings.longpressTimeout = getPrefInt(prefs, PREF_LONGPRESS_TIMEOUT,
            res.getString(R.string.default_long_press_duration));
    LatinIME.sKeyboardSettings.renderMode = getPrefInt(prefs, PREF_RENDER_MODE,
            res.getString(R.string.default_render_mode));
    mSwipeUpAction = prefs.getString(PREF_SWIPE_UP, res.getString(R.string.default_swipe_up));
    mSwipeDownAction = prefs.getString(PREF_SWIPE_DOWN, res.getString(R.string.default_swipe_down));
    mSwipeLeftAction = prefs.getString(PREF_SWIPE_LEFT, res.getString(R.string.default_swipe_left));
    mSwipeRightAction = prefs.getString(PREF_SWIPE_RIGHT, res.getString(R.string.default_swipe_right));
    mVolUpAction = prefs.getString(PREF_VOL_UP, res.getString(R.string.default_vol_up));
    mVolDownAction = prefs.getString(PREF_VOL_DOWN, res.getString(R.string.default_vol_down));
    sKeyboardSettings.initPrefs(prefs, res);

    //        mVoiceRecognitionTrigger = new VoiceRecognitionTrigger(this);

    updateKeyboardOptions();

    PluginManager.getPluginDictionaries(getApplicationContext());
    mPluginManager = new PluginManager(this);
    final IntentFilter pFilter = new IntentFilter();
    pFilter.addDataScheme("package");
    pFilter.addAction("android.intent.action.PACKAGE_ADDED");
    pFilter.addAction("android.intent.action.PACKAGE_REPLACED");
    pFilter.addAction("android.intent.action.PACKAGE_REMOVED");
    registerReceiver(mPluginManager, pFilter);

    TKIMEUtil.GCUtils.getInstance().reset();
    boolean tryGC = true;
    for (int i = 0; i < TKIMEUtil.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
        try {
            initSuggest(inputLanguage);
            tryGC = false;
        } catch (OutOfMemoryError e) {
            tryGC = TKIMEUtil.GCUtils.getInstance().tryGCOrWait(inputLanguage, e);
        }
    }

    mOrientation = conf.orientation;

    // register to receive ringer mode changes for silent mode
    IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
    registerReceiver(mReceiver, filter);
    prefs.registerOnSharedPreferenceChangeListener(this);
    setNotification(mKeyboardNotification);
}

From source file:com.andrew.apollo.MusicPlaybackService.java

/**
 * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. The
 * intent will call closeExternalStorageFiles() if the external media is
 * going to be ejected, so applications can clean up any files they have
 * open./*w w w. j a  va 2  s .  c o m*/
 */
private void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void onReceive(final Context context, final Intent intent) {
                final String action = intent.getAction();
                if (action != null) {
                    if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                        saveQueue(true);
                        mQueueIsSaveable = false;
                        closeExternalStorageFiles();
                    } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                        mMediaMountedCount++;
                        mCardId = getCardId();
                        reloadQueue();
                        mQueueIsSaveable = true;
                        notifyChange(QUEUE_CHANGED);
                        notifyChange(META_CHANGED);
                    }
                }
            }
        };
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_EJECT);
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addDataScheme("file");
        registerReceiver(mUnmountReceiver, filter);
    }
}

From source file:com.cyanogenmod.eleven.MusicPlaybackService.java

/**
 * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. The
 * intent will call closeExternalStorageFiles() if the external media is
 * going to be ejected, so applications can clean up any files they have
 * open./*w w  w .j a va  2  s.co  m*/
 */
public void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void onReceive(final Context context, final Intent intent) {
                final String action = intent.getAction();
                if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                    saveQueue(true);
                    mQueueIsSaveable = false;
                    closeExternalStorageFiles(intent.getData().getPath());
                } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                    mMediaMountedCount++;
                    mCardId = getCardId();
                    reloadQueue();
                    mQueueIsSaveable = true;
                    notifyChange(QUEUE_CHANGED);
                    notifyChange(META_CHANGED);
                }
            }
        };
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_EJECT);
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addDataScheme("file");
        registerReceiver(mUnmountReceiver, filter);
    }
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

public void handleMediaReceiver() {
    storageReceiver = new BroadcastReceiver() {
        @Override/*w w  w.j av  a 2 s .  c om*/
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            String data = intent.getDataString();
            final String path = data.replace("file://", "");
            if (action.equals(Intent.ACTION_MEDIA_MOUNTED))
                handleRefreshMedia(path, true, 10);
            else
                refreshBookmarks();
        }
    };

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    filter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    filter.addAction(Intent.ACTION_MEDIA_EJECT);
    filter.addDataScheme("file");
    registerReceiver(storageReceiver, filter);

    ContentObserver mDbObserver = new ContentObserver(mHandler) {
        @Override
        public void onChange(boolean selfChange) {
            //rebake(false, ImageManager.isMediaScannerScanning(
            //      getContentResolver()));
        }
    };

    getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true,
            mDbObserver);
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

private void registerIntentReceivers() {
    boolean useNotifReceiver = PersonaAlmostNexusSettingsHelper.getNotifReceiver(this);
    if (useNotifReceiver && mCounterReceiver == null) {
        mCounterReceiver = new PersonaCounterReceiver(this);
        mCounterReceiver.setCounterListener(new PersonaCounterReceiver.OnCounterChangedListener() {
            public void onTrigger(String pname, int counter, int color) {
                PersonaLog.d("personalauncher", "updateCountersForPackage called from registerIntentReceivers");
                //updateCountersForPackage(pname, counter, color, 0);
                Bundle b = new Bundle();

                b.putString("package", "com.cognizant.trumobi");
                b.putInt("counter", counter);
                b.putInt("color", R.color.PR_TEXTBOX_FOCUSED_COLOR);
                b.putInt("updateCountFor", 0);
                Message m = new Message();
                m.setData(b);// www.j  a va 2s .  c o  m
                UiHandler.sendMessage(m);
            }
        });
        registerReceiver(mCounterReceiver, mCounterReceiver.getFilter());
    }

    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    registerReceiver(mApplicationsReceiver, filter);
    filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);
    filter = new IntentFilter();
    filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
    filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    registerReceiver(mApplicationsReceiver, filter);

}