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:org.wso2.iot.agent.events.listeners.ApplicationStateListener.java

@Override
public void startListening() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
    intentFilter.addDataScheme("package");
    EventRegistry.context.registerReceiver(this, intentFilter);
}

From source file:org.videolan.vlc.gui.DirectoryViewFragment.java

@Override
public void onStart() {
    super.onStart();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_REMOVED);
    filter.addAction(Intent.ACTION_MEDIA_EJECT);
    filter.addDataScheme("file");
    getActivity().registerReceiver(messageReceiver, filter);
}

From source file:org.videolan.vlc.gui.AudioPlayerContainerActivity.java

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

    //Handle external storage state
    IntentFilter storageFilter = new IntentFilter();
    storageFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    storageFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    storageFilter.addDataScheme("file");
    registerReceiver(storageReceiver, storageFilter);

    /* Prepare the progressBar */
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_SHOW_PLAYER);
    registerReceiver(messageReceiver, filter);
    mClient.connect();/*from  w  w  w . ja v  a 2s .  c  o  m*/
}

From source file:eu.faircode.netguard.SinkholeService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG, "Create");

    HandlerThread thread = new HandlerThread(getString(R.string.app_name));
    thread.start();/*  w  w w . j  av a2  s. c  o m*/

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);

    // Listen for interactive state changes
    IntentFilter ifInteractive = new IntentFilter();
    ifInteractive.addAction(Intent.ACTION_SCREEN_ON);
    ifInteractive.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(interactiveStateReceiver, ifInteractive);

    // Listen for connectivity updates
    IntentFilter ifConnectivity = new IntentFilter();
    ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectivityChangedReceiver, ifConnectivity);

    // Listen for added applications
    IntentFilter ifPackage = new IntentFilter();
    ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED);
    ifPackage.addDataScheme("package");
    registerReceiver(packageAddedReceiver, ifPackage);
}

From source file:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java

/**
 * Register an SMS Data (Binary) Receiver
 *//*from   w w  w . j a  v  a2 s  .  com*/
private void registerSmsReceiver() {
    smsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Debug.i("Received Binary SMS");

            Bundle bundle = intent.getExtras();
            SmsMessage[] msgs = null;

            if (null != bundle) {
                // In telecommunications the term (PDU) means protocol data
                // unit.
                // There are two ways of sending and receiving SMS messages:
                // by text mode and by PDU (protocol description unit) mode.
                // The PDU string contains not only the message, but also a
                // lot of meta-information about the sender, his SMS service
                // center, the time stamp etc
                // It is all in the form of hexa-decimal octets or decimal
                // semi-octets.
                Object[] pdus = (Object[]) bundle.get("pdus");
                msgs = new SmsMessage[pdus.length];

                for (int i = 0; i < msgs.length; i++) {
                    // Create the Message
                    msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                    // Get Message Parameters
                    SmsObject receivedSms = new SmsObject();
                    receivedSms.setTelephoneNumber(msgs[i].getOriginatingAddress());
                    receivedSms.setMessageTimestamp(msgs[i].getTimestampMillis());
                    receivedSms.setMessageData(Base64.encodeToString(msgs[i].getUserData(), Base64.CRLF));

                    Debug.d("Received SMS and it's content hash is: " + BinaryHelpers
                            .toHexadecimealString(Hashing.getMD5Hash(msgs[i].getUserData()).toByteArray()));

                    // Store the SmsObject to the db
                    dao.storeSms(receivedSms);
                }
            }

            // This will stop the Broadcast and not allow the message to
            // be interpreted by the default Android app or other apps
            abortBroadcast();
        }
    };

    // Set up the Receiver Parameters
    IntentFilter mIntentFilter = new IntentFilter();
    mIntentFilter.setPriority(999);
    mIntentFilter.addAction("android.intent.action.DATA_SMS_RECEIVED");
    mIntentFilter.addDataScheme("sms");
    // Set the Port that is listening to
    mIntentFilter.addDataAuthority("*", "2013");
    // mIntentFilter.addDataType(type)
    registerReceiver(smsReceiver, mIntentFilter);
    Debug.d("Set up BinarySMS receiver.");
}

From source file:Main.java

private static final boolean initIntentFilterFromXml(IntentFilter inf, XmlPullParser xpp) {
    try {/*from   w  w  w  . ja v a 2  s . c  om*/
        int outerDepth = xpp.getDepth();
        int type;
        final String NAME = "name";
        while ((type = xpp.next()) != XmlPullParser.END_DOCUMENT
                && (type != XmlPullParser.END_TAG || xpp.getDepth() > outerDepth)) {
            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT)
                continue;
            String tag = xpp.getName();
            if (tag.equals("action")) {
                String name = xpp.getAttributeValue(null, NAME);
                if (name != null)
                    inf.addAction(name);
            } else if (tag.equals("category")) {
                String name = xpp.getAttributeValue(null, NAME);
                if (name != null)
                    inf.addCategory(name);
            } else if (tag.equals("data")) {
                int na = xpp.getAttributeCount();
                for (int i = 0; i < na; i++) {
                    String port = null;
                    String an = xpp.getAttributeName(i);
                    String av = xpp.getAttributeValue(i);
                    if ("mimeType".equals(an)) {
                        try {
                            inf.addDataType(av);
                        } catch (MalformedMimeTypeException e) {
                        }
                    } else if ("scheme".equals(an)) {
                        inf.addDataScheme(av);
                    } else if ("host".equals(an)) {
                        inf.addDataAuthority(av, port);
                    } else if ("port".equals(an)) {
                        port = av;
                    } else if ("path".equals(an)) {
                        inf.addDataPath(av, PatternMatcher.PATTERN_LITERAL);
                    } else if ("pathPrefix".equals(an)) {
                        inf.addDataPath(av, PatternMatcher.PATTERN_PREFIX);
                    } else if ("pathPattern".equals(an)) {
                        inf.addDataPath(av, PatternMatcher.PATTERN_SIMPLE_GLOB);
                    }
                }
            }
        }
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:com.polyvi.xface.extension.XAppExt.java

private void registerInstallerReceiver(final XCallbackContext callbackCtx) {
    if (null == mInstallerReceiver) {
        mInstallerReceiver = new BroadcastReceiver() {
            @Override//from   www. j  ava 2s  .c o  m
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")
                        && (uninstallPackageName.equals(intent.getDataString().substring(8)))) {
                    XExtensionResult result = new XExtensionResult(XExtensionResult.Status.OK);
                    callbackCtx.sendExtensionResult(result);
                }
                if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
                    XExtensionResult result = new XExtensionResult(XExtensionResult.Status.OK);
                    callbackCtx.sendExtensionResult(result);
                }
            }
        };
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addDataScheme("package");
        getContext().registerReceiver(mInstallerReceiver, filter);
    }
}

From source file:com.lullabot.android.apps.iosched.ui.SessionDetailFragment.java

@Override
public void onResume() {
    super.onResume();

    // Start listening for time updates to adjust "now" bar. TIME_TICK is
    // triggered once per minute, which is how we move the bar over time.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    filter.addDataScheme("package");
    getActivity().registerReceiver(mPackageChangesReceiver, filter);
}

From source file:com.example.android.threadsample.DisplayActivity.java

@Override
public void onCreate(Bundle stateBundle) {
    // Sets fullscreen-related flags for the display
    getWindow().setFlags(//from  w  w w  .j  a  v a2  s  .  com
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR,
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);

    // Calls the super method (required)
    super.onCreate(stateBundle);

    // Inflates the main View, which will be the host View for the fragments
    mMainView = getLayoutInflater().inflate(R.layout.fragmenthost, null);

    // Sets the content view for the Activity
    setContentView(mMainView);

    /*
     * Creates an intent filter for DownloadStateReceiver that intercepts broadcast Intents
     */

    // The filter's action is BROADCAST_ACTION
    IntentFilter statusIntentFilter = new IntentFilter(Constants.BROADCAST_ACTION);

    // Sets the filter's category to DEFAULT
    statusIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);

    // Instantiates a new DownloadStateReceiver
    mDownloadStateReceiver = new DownloadStateReceiver();

    // Registers the DownloadStateReceiver and its intent filters
    LocalBroadcastManager.getInstance(this).registerReceiver(mDownloadStateReceiver, statusIntentFilter);

    /*
     * Creates intent filters for the FragmentDisplayer
     */

    // One filter is for the action ACTION_VIEW_IMAGE
    IntentFilter displayerIntentFilter = new IntentFilter(Constants.ACTION_VIEW_IMAGE);

    // Adds a data filter for the HTTP scheme
    displayerIntentFilter.addDataScheme("http");

    // Registers the receiver
    LocalBroadcastManager.getInstance(this).registerReceiver(mFragmentDisplayer, displayerIntentFilter);

    // Creates a second filter for ACTION_ZOOM_IMAGE
    displayerIntentFilter = new IntentFilter(Constants.ACTION_ZOOM_IMAGE);

    // Registers the receiver
    LocalBroadcastManager.getInstance(this).registerReceiver(mFragmentDisplayer, displayerIntentFilter);

    // Gets an instance of the support library FragmentManager
    FragmentManager localFragmentManager = getSupportFragmentManager();

    /*
     * Detects if side-by-side display should be enabled. It's only available on xlarge and
     * sw600dp devices (for example, tablets). The setting in res/values/ is "false", but this
     * is overridden in values-xlarge and values-sw600dp.
     */
    mSideBySide = getResources().getBoolean(R.bool.sideBySide);

    /*
     * Detects if hiding navigation controls should be enabled. On xlarge andsw600dp, it should
     * be false, to avoid having the user enter an additional tap.
     */
    mHideNavigation = getResources().getBoolean(R.bool.hideNavigation);

    /*
     * Adds the back stack change listener defined in this Activity as the listener for the
     * FragmentManager. See the method onBackStackChanged().
     */
    localFragmentManager.addOnBackStackChangedListener(this);

    // If the incoming state of the Activity is null, sets the initial view to be thumbnails
    if (null == stateBundle) {

        // Starts a Fragment transaction to track the stack
        FragmentTransaction localFragmentTransaction = localFragmentManager.beginTransaction();

        // Adds the PhotoThumbnailFragment to the host View
        localFragmentTransaction.add(R.id.fragmentHost, new PhotoThumbnailFragment(),
                Constants.THUMBNAIL_FRAGMENT_TAG);

        // Commits this transaction to display the Fragment
        localFragmentTransaction.commit();

        // The incoming state of the Activity isn't null.
    } else {

        // Gets the previous state of the fullscreen indicator
        mFullScreen = stateBundle.getBoolean(Constants.EXTENDED_FULLSCREEN);

        // Sets the fullscreen flag to its previous state
        setFullScreen(mFullScreen);

        // Gets the previous backstack entry count.
        mPreviousStackCount = localFragmentManager.getBackStackEntryCount();
    }
}

From source file:net.micode.fileexplorer.FileViewActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mActivity = getActivity();//from   w  w w. jav a2s  .c o  m
    // getWindow().setFormat(android.graphics.PixelFormat.RGBA_8888);
    mRootView = inflater.inflate(R.layout.file_explorer_list, container, false);
    ActivitiesManager.getInstance().registerActivity(ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity);

    mFileCagetoryHelper = new FileCategoryHelper(mActivity);
    mFileViewInteractionHub = new FileViewInteractionHub(this);
    Intent intent = mActivity.getIntent();
    String action = intent.getAction();
    if (!TextUtils.isEmpty(action)
            && (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT))) {
        mFileViewInteractionHub.setMode(Mode.Pick);

        boolean pickFolder = intent.getBooleanExtra(PICK_FOLDER, false);
        if (!pickFolder) {
            String[] exts = intent.getStringArrayExtra(EXT_FILTER_KEY);
            if (exts != null) {
                mFileCagetoryHelper.setCustomCategory(exts);
            }
        } else {
            mFileCagetoryHelper.setCustomCategory(new String[] {} /*folder only*/);
            mRootView.findViewById(R.id.pick_operation_bar).setVisibility(View.VISIBLE);

            mRootView.findViewById(R.id.button_pick_confirm).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    try {
                        Intent intent = Intent.parseUri(mFileViewInteractionHub.getCurrentPath(), 0);
                        mActivity.setResult(Activity.RESULT_OK, intent);
                        mActivity.finish();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            });

            mRootView.findViewById(R.id.button_pick_cancel).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mActivity.finish();
                }
            });
        }
    } else {
        mFileViewInteractionHub.setMode(Mode.View);
    }

    mFileListView = (ListView) mRootView.findViewById(R.id.file_path_list);
    mFileIconHelper = new FileIconHelper(mActivity);
    mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList,
            mFileViewInteractionHub, mFileIconHelper);

    boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD,
            !FileExplorerPreferenceActivity.isReadRoot(mActivity));
    Log.i(LOG_TAG, "baseSd = " + baseSd);

    String rootDir = intent.getStringExtra(ROOT_DIRECTORY);
    if (!TextUtils.isEmpty(rootDir)) {
        if (baseSd && this.sdDir.startsWith(rootDir)) {
            rootDir = this.sdDir;
        }
    } else {
        rootDir = baseSd ? this.sdDir : GlobalConsts.ROOT_PATH;
    }
    mFileViewInteractionHub.setRootPath(rootDir);

    String currentDir = FileExplorerPreferenceActivity.getPrimaryFolder(mActivity);
    Uri uri = intent.getData();
    if (uri != null) {
        if (baseSd && this.sdDir.startsWith(uri.getPath())) {
            currentDir = this.sdDir;
        } else {
            currentDir = uri.getPath();
        }
    }
    mFileViewInteractionHub.setCurrentPath(currentDir);
    Log.i(LOG_TAG, "CurrentDir = " + currentDir);

    mBackspaceExit = (uri != null) && (TextUtils.isEmpty(action)
            || (!action.equals(Intent.ACTION_PICK) && !action.equals(Intent.ACTION_GET_CONTENT)));

    mFileListView.setAdapter(mAdapter);
    mFileViewInteractionHub.refreshFileList();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    intentFilter.addDataScheme("file");
    mActivity.registerReceiver(mReceiver, intentFilter);

    updateUI();
    setHasOptionsMenu(true);
    return mRootView;
}