Android IntentFilter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android IntentFilter class.

This code example shows how to use the following methods:addDataScheme, getDataScheme
 
@RunWith(TestRunners.WithDefaults.class) 
public class IntentFilterTest { 
    @Test 
    public void addDataScheme_shouldAddTheDataScheme() throws Exception { 
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addDataScheme("http");
        intentFilter.addDataScheme("ftp");
 
        assertThat(intentFilter.getDataScheme(0)).isEqualTo("http");
        assertThat(intentFilter.getDataScheme(1)).isEqualTo("ftp");
    } 
     
    @Test 
    public void addDataAuthority_shouldAddTheDataAuthority() throws Exception { 
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addDataAuthority("test.com", "8080");
        intentFilter.addDataAuthority("example.com", "42");
 
        assertThat(intentFilter.getDataAuthority(0).getHost()).isEqualTo("test.com");
9
CodeRank
This code example shows how to use the following methods:addCategory
  } 
 
  @Test 
  public void testGetPreferredActivities() throws Exception { 
    // Setup an intentfilter and add to packagemanager 
    IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);
    final String packageName = "com.example.dummy";
    ComponentName name = new ComponentName(packageName, "LauncherActivity");
    rpm.addPreferredActivity(filter, 0, null, name);
 
    // Test match 
    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(filter);
 
    List<ComponentName> activities = new ArrayList<ComponentName>();
    rpm.getPreferredActivities(filters, activities, null);
 
    assertThat(activities.size()).isEqualTo(1);
    assertThat(activities.get(0).getPackageName()).isEqualTo(packageName);
8
CodeRank
This code example shows how to use the following methods:addAction
				.getSystemService(Context.ALARM_SERVICE);
	} 
 
	@Override 
	public void onInitialized() { 
		IntentFilter filter = new IntentFilter();
		filter.addAction(Intent.ACTION_SCREEN_ON);
		filter.addAction(Intent.ACTION_SCREEN_OFF);
		Application.getInstance().registerReceiver(screenReceiver, filter);
	} 
 
	@Override 
	public void onClose() { 
		alarmManager.cancel(goAwayPendingIntent);
		alarmManager.cancel(goXaPendingIntent);
		Application.getInstance().unregisterReceiver(screenReceiver);
	} 
 
	private long getTime(int milliSeconds) {
		Calendar calendar = Calendar.getInstance();
8
CodeRank
This code example shows how to use the following methods:registerReceiver, addAction
    protected void onAttachedToWindow() { 
        super.onAttachedToWindow(); 
 
        if (!mAttached) {
            mAttached = true;
            IntentFilter filter = new IntentFilter();
 
            filter.addAction(Intent.ACTION_TIME_TICK);
            filter.addAction(Intent.ACTION_TIME_CHANGED);
            filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
            filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
 
            getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
        } 
 
        // NOTE: It's safe to do these after registering the receiver since the receiver always runs 
        // in the main thread, therefore the receiver can't run before this method returns. 
 
        // The time zone may have changed while the receiver wasn't registered, so update the Time 
        mCalendar = Calendar.getInstance(TimeZone.getDefault());
8
CodeRank
This code example shows how to use the following methods:addAction, registerReceiver
        super.onResume(); 
        if (mOkButton == null) {
            mOkButton = mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            mOkButton.setEnabled(mDeviceNameEdited);    // Ok button enabled after user edits
        } 
        IntentFilter filter = new IntentFilter();
        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        filter.addAction(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);
        getActivity().registerReceiver(mReceiver, filter);
    } 
 
    @Override 
    public void onPause() { 
        super.onPause(); 
        getActivity().unregisterReceiver(mReceiver);
    } 
 
    void updateDeviceName() { 
        if (mLocalAdapter != null && mLocalAdapter.isEnabled()) {
            mDeviceNameUpdated = true;
8
CodeRank
This code example shows how to use the following methods:addCategory
    } 
 
    @Test 
    public void testGetPreferredActivities() throws Exception { 
        // Setup an intentfilter and add to packagemanager 
        IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
        filter.addCategory(Intent.CATEGORY_HOME);
        final String packageName = "com.example.dummy";
        ComponentName name = new ComponentName(packageName, "LauncherActivity");
        rpm.addPreferredActivity(filter, 0, null, name);
 
        // Test match 
        List<IntentFilter> filters = new ArrayList<IntentFilter>();
        filters.add(filter);
 
        List<ComponentName> activities = new ArrayList<ComponentName>();
        rpm.getPreferredActivities(filters, activities, null);
 
        assertThat(activities.size()).isEqualTo(1);
        assertThat(activities.get(0).getPackageName()).isEqualTo(packageName);
8
CodeRank
This code example shows how to use the following methods:addAction, addDataScheme, registerReceiver
    public void onResume() { 
        super.onResume(); 
        updateList(); 
 
        // listen for package changes 
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
        filter.addDataScheme("package");
        getActivity().registerReceiver(mPackageReceiver, filter);
 
        mCR.registerContentObserver(ENABLED_NOTIFICATION_LISTENERS_URI, false, mSettingsObserver);
    } 
 
    @Override 
    public void onPause() { 
        super.onPause(); 
 
8
CodeRank
This code example shows how to use the following methods:addAction
		return state;
	} 
 
	@Override 
	public void onInitialized() { 
		IntentFilter filter = new IntentFilter();
		filter.addAction(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		Application.getInstance() 
				.registerReceiver(connectivityReceiver, filter);
		onWakeLockSettingsChanged(); 
		onWifiLockSettingsChanged(); 
	} 
 
	@Override 
	public void onClose() { 
		Application.getInstance().unregisterReceiver(connectivityReceiver);
	} 
 
	public void onNetworkChange(NetworkInfo networkInfo) {
8
CodeRank
This code example shows how to use the following methods:
public class ShadowMapActivity extends ShadowActivity { 
    private ConnectivityBroadcastReceiver connectivityBroadcastReceiver = new ConnectivityBroadcastReceiver(); 
 
    @Implementation 
    public void onResume() { 
        registerReceiver(connectivityBroadcastReceiver, new IntentFilter()); 
    } 
 
    @Implementation 
    public void onPause() { 
        unregisterReceiver(connectivityBroadcastReceiver); 
    } 
 
    @Implementation 
    public boolean isRouteDisplayed() { 
        return false; 
    } 
 
    private static class ConnectivityBroadcastReceiver extends BroadcastReceiver { 
        @Override public void onReceive(Context context, Intent intent) { 
7
CodeRank
This code example shows how to use the following methods:registerReceiver, addAction, addDataScheme
 
        public PackageIntentReceiver(AppListLoader loader) {
            mLoader = loader;
            IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
            filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
            filter.addDataScheme("package");
            mLoader.getContext().registerReceiver(this, filter);
            // Register for events related to sdcard installation. 
            IntentFilter sdFilter = new IntentFilter();
            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
            mLoader.getContext().registerReceiver(this, sdFilter);
        } 
 
        @Override public void onReceive(Context context, Intent intent) {
            // Tell the loader about the change. 
            mLoader.onContentChanged();
        } 
    } 
7
CodeRank

Related Android IntentFilter Questions & Answers:

Other Android IntentFilter Examples

1:	IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
2:	
3:	/ Intent is sticky so using null as receiver works fine
-
1:	IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
2:	
3:	/ Intent is sticky so using null as receiver works fine

Read More

64:			lblMessage = (TextView) findViewById(R.id.lblMessage);
65:			
66:			registerReceiver(mHandleMessageReceiver, new IntentFilter(
67:					DISPLAY_MESSAGE_ACTION));
68:

Read More

See Code Examples for Android IntentFilter Methods: