Java Code Examples for android.content.IntentFilter#addCategory()

The following examples show how to use android.content.IntentFilter#addCategory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TTIntent.java    From TwistyTimer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Registers a broadcast receiver. The receiver will only be notified of intents that require
 * the category given and only for the actions that are supported for that category. If the
 * receiver is used by a fragment, create an instance of {@link TTFragmentBroadcastReceiver}
 * and register it with the {@link #registerReceiver(TTFragmentBroadcastReceiver)} method
 * instead, as it will be easier to maintain.
 *
 * @param receiver
 *     The broadcast receiver to be registered.
 * @param category
 *     The category for the actions to be received. Must not be {@code null} and must be a
 *     supported category.
 *
 * @throws IllegalArgumentException
 *     If the category is {@code null}, or is not one of the supported categories.
 */
public static void registerReceiver(BroadcastReceiver receiver, String category) {
    final String[] actions = ACTIONS_SUPPORTED_BY_CATEGORY.get(category);

    if (category == null || actions.length == 0) {
        throw new IllegalArgumentException("Category is not supported: " + category);
    }

    final IntentFilter filter = new IntentFilter();

    filter.addCategory(category);

    for (String action : actions) {
        // IntentFilter will only match Intents with one of these actions.
        filter.addAction(action);
    }

    LocalBroadcastManager.getInstance(TwistyTimer.getAppContext())
            .registerReceiver(receiver, filter);
}
 
Example 2
Source File: RobolectricUtils.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures intents with {@link CustomTabsService#ACTION_CUSTOM_TABS_CONNECTION} resolve to a
 * Service with given categories
 */
public static void installCustomTabsService(String providerPackage, List<String> categories) {
    Intent intent = new Intent()
            .setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION)
            .setPackage(providerPackage);

    IntentFilter filter = new IntentFilter();
    for (String category : categories) {
        filter.addCategory(category);
    }
    ResolveInfo resolveInfo = new ResolveInfo();
    resolveInfo.filter = filter;

    ShadowPackageManager manager = Shadows.shadowOf(RuntimeEnvironment.application
            .getPackageManager());
    manager.addResolveInfoForIntent(intent, resolveInfo);
}
 
Example 3
Source File: RNDataWedgeIntentsModule.java    From react-native-datawedge-intents with MIT License 6 votes vote down vote up
@ReactMethod
  public void registerReceiver(String action, String category)
  {
      //  THIS METHOD IS DEPRECATED, use registerBroadcastReceiver
      Log.d(TAG, "Registering an Intent filter for action: " + action);
this.registeredAction = action;
this.registeredCategory = category;
      //  User has specified the intent action and category that DataWedge will be reporting
      try
      {
          this.reactContext.unregisterReceiver(scannedDataBroadcastReceiver);
      }
      catch (IllegalArgumentException e)
      {
          //  Expected behaviour if there was not a previously registered receiver.
      }
      IntentFilter filter = new IntentFilter();
      filter.addAction(action);
      if (category != null && category.length() > 0)
        filter.addCategory(category);
      this.reactContext.registerReceiver(scannedDataBroadcastReceiver, filter);
  }
 
Example 4
Source File: LockActivity.java    From TapUnlock with Apache License 2.0 6 votes vote down vote up
public boolean isMyLauncherDefault() {
    final IntentFilter launcherFilter = new IntentFilter(Intent.ACTION_MAIN);
    launcherFilter.addCategory(Intent.CATEGORY_HOME);

    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(launcherFilter);

    final String myPackageName = getPackageName();
    List<ComponentName> activities = new ArrayList<ComponentName>();

    packageManager.getPreferredActivities(filters, activities, "com.moonpi.tapunlock");

    for (ComponentName activity : activities) {
        if (myPackageName.equals(activity.getPackageName())) {
            return true;
        }
    }

    return false;
}
 
Example 5
Source File: AddCrossProfileIntentFilterFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an intent filter from user input. This intent-filter is used for cross-profile
 * intent.
 *
 * @return a user constructed intent filter.
 */
private IntentFilter getIntentFilter() {
    if (mActions.isEmpty() && mCategories.isEmpty() && mDataSchemes.isEmpty()
            && mDataTypes.isEmpty()) {
        return null;
    }
    IntentFilter intentFilter = new IntentFilter();
    for (String action : mActions) {
        intentFilter.addAction(action);
    }
    for (String category : mCategories) {
        intentFilter.addCategory(category);
    }
    for (String dataScheme : mDataSchemes) {
        intentFilter.addDataScheme(dataScheme);
    }
    for (String dataType : mDataTypes) {
        try {
            intentFilter.addDataType(dataType);
        } catch (MalformedMimeTypeException e) {
            Log.e(TAG, "Malformed mime type: " + e);
            return null;
        }
    }
    return intentFilter;
}
 
Example 6
Source File: BluetoothManager.java    From Linphone4Android with GNU General Public License v3.0 6 votes vote down vote up
public void initBluetooth() {
	if (!ensureInit()) {
		Log.w("[Bluetooth] Manager tried to init bluetooth but LinphoneService not ready yet...");
		return;
	}
	
	IntentFilter filter = new IntentFilter();
	filter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + "." + BluetoothAssignedNumbers.PLANTRONICS);
	filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
	filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
	filter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
	mContext.registerReceiver(this,  filter);
	Log.d("[Bluetooth] Receiver started");
	
	startBluetooth();
}
 
Example 7
Source File: ShareTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testShowBasicShareDialog() {
  final WritableMap content = new WritableNativeMap();
  content.putString("message", "Hello, ReactNative!");
  final WritableMap options = new WritableNativeMap();

  IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CHOOSER);
  intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
  ActivityMonitor monitor = getInstrumentation().addMonitor(intentFilter, null, true);

  getTestModule().showShareDialog(content, options);

  waitForBridgeAndUIIdle();
  getInstrumentation().waitForIdleSync();

  assertEquals(1, monitor.getHits());
  assertEquals(1, mRecordingModule.getOpened());
  assertEquals(0, mRecordingModule.getErrors());

}
 
Example 8
Source File: RobolectricUtils.java    From android-browser-helper with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures intents with {@link CustomTabsService#ACTION_CUSTOM_TABS_CONNECTION} resolve to a
 * Service with given categories
 */
public static void installCustomTabsService(String providerPackage, List<String> categories) {
    Intent intent = new Intent()
            .setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION)
            .setPackage(providerPackage);

    IntentFilter filter = new IntentFilter();
    for (String category : categories) {
        filter.addCategory(category);
    }
    ResolveInfo resolveInfo = new ResolveInfo();
    resolveInfo.filter = filter;

    ShadowPackageManager manager = Shadows.shadowOf(RuntimeEnvironment.application
            .getPackageManager());
    manager.addResolveInfoForIntent(intent, resolveInfo);
}
 
Example 9
Source File: VideoListActivity.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * Register a BroadcastReceiver that receives a result from the
 * UploadVideoService when a video upload completes.
 */
private void registerReceiver() {
    
    // Create an Intent filter that handles Intents from the
    // UploadVideoService.
    IntentFilter intentFilter =
        new IntentFilter(UploadVideoService.ACTION_UPLOAD_SERVICE_RESPONSE);
    intentFilter.addCategory(Intent.CATEGORY_DEFAULT);

    // Register the BroadcastReceiver.
    LocalBroadcastManager.getInstance(this)
           .registerReceiver(mUploadResultReceiver,
                             intentFilter);
}
 
Example 10
Source File: ProviderSetupBaseActivity.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private void setUpProviderAPIResultReceiver() {
    providerAPIResultReceiver = new ProviderAPIResultReceiver(new Handler(), this);
    providerAPIBroadcastReceiver = new ProviderApiSetupBroadcastReceiver(this);

    IntentFilter updateIntentFilter = new IntentFilter(BROADCAST_PROVIDER_API_EVENT);
    updateIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
    LocalBroadcastManager.getInstance(this).registerReceiver(providerAPIBroadcastReceiver, updateIntentFilter);
}
 
Example 11
Source File: CastMediaRouteProvider.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
private void publishRoutes() {
    MediaRouteProviderDescriptor.Builder builder = new MediaRouteProviderDescriptor.Builder();
    for (CastDevice castDevice : this.castDevices.values()) {
        ArrayList<IntentFilter> controlFilters = new ArrayList<IntentFilter>(BASE_CONTROL_FILTERS);
        // Include any app-specific control filters that have been requested.
        // TODO: Do we need to check with the device?
        for (String category : this.customCategories) {
            IntentFilter filter = new IntentFilter();
            filter.addCategory(category);
            controlFilters.add(filter);
        }

        Bundle extras = new Bundle();
        castDevice.putInBundle(extras);
        MediaRouteDescriptor route = new MediaRouteDescriptor.Builder(
            castDevice.getDeviceId(),
            castDevice.getFriendlyName())
            .setDescription(castDevice.getModelName())
            .addControlFilters(controlFilters)
            .setDeviceType(MediaRouter.RouteInfo.DEVICE_TYPE_TV)
            .setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
            .setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED)
            .setVolumeMax(20)
            .setVolume(0)
            .setEnabled(true)
            .setExtras(extras)
            .setConnectionState(MediaRouter.RouteInfo.CONNECTION_STATE_DISCONNECTED)
            .build();
        builder.addRoute(route);
    }
    this.setDescriptor(builder.build());
}
 
Example 12
Source File: VideoListActivity.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * Register a BroadcastReceiver that receives a result from the
 * UploadVideoService when a video upload completes.
 */
private void registerReceiver() {
    
    // Create an Intent filter that handles Intents from the
    // UploadVideoService.
    IntentFilter intentFilter =
        new IntentFilter(UploadVideoService.ACTION_UPLOAD_SERVICE_RESPONSE);
    intentFilter.addCategory(Intent.CATEGORY_DEFAULT);

    // Register the BroadcastReceiver.
    LocalBroadcastManager.getInstance(this)
           .registerReceiver(mUploadResultReceiver,
                             intentFilter);
}
 
Example 13
Source File: SampleTest.java    From androidtestdebug with MIT License 5 votes vote down vote up
public void test点击链接() {
	final Instrumentation inst = getInstrumentation();
	IntentFilter intentFilter = new IntentFilter(Intent.ACTION_VIEW);
	intentFilter.addDataScheme("http");
	intentFilter.addCategory(Intent.CATEGORY_BROWSABLE);
	View link = this.getActivity().findViewById(R.id.link);
	ActivityMonitor monitor = inst.addMonitor(
			intentFilter, null, false);
	assertEquals(0, monitor.getHits());
	TouchUtils.clickView(this, link);
	monitor.waitForActivityWithTimeout(5000);
	assertEquals(1, monitor.getHits());
	inst.removeMonitor(monitor);
}
 
Example 14
Source File: BeaconControl.java    From BeaconControl_Android_SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void registerActionReceiver() {
    IntentFilter filter = new IntentFilter(ActionReceiver.PROCESS_RESPONSE);
    filter.addCategory(Intent.CATEGORY_DEFAULT);

    actionReceiver = new ActionReceiver();
    context.registerReceiver(actionReceiver, filter);
}
 
Example 15
Source File: BeaconControl.java    From BeaconControl_Android_SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void registerBeaconProximityChangeReceiver() {
    IntentFilter filter = new IntentFilter(BeaconProximityChangeReceiver.PROCESS_RESPONSE);
    filter.addCategory(Intent.CATEGORY_DEFAULT);

    beaconProximityChangeReceiver = new BeaconProximityChangeReceiver();
    context.registerReceiver(beaconProximityChangeReceiver, filter);
}
 
Example 16
Source File: UCNetAnalysisManager.java    From netanalysis-sdk-android with Apache License 2.0 5 votes vote down vote up
private void startMonitorNetStatus() {
    if (mNetStatusReceiver != null)
        return;
    
    mNetStatusReceiver = new UNetStatusReceiver();
    IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
    mContext.registerReceiver(mNetStatusReceiver, intentFilter);
    mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
 
Example 17
Source File: AppCatalogService.java    From product-emm with Apache License 2.0 5 votes vote down vote up
/**
 * Executes device management operations on the device.
 *
 * @param code - Operation object.
 */
public void doTask(String code) {
    switch (code) {
        case Constants.Operation.GET_APP_DOWNLOAD_PROGRESS:
            String downloadingApp = Preference.getString(context, context.getResources().getString(
                    R.string.current_downloading_app));
            JSONObject result = new JSONObject();
            ApplicationManager applicationManager = new ApplicationManager(context);
            if(applicationManager.isPackageInstalled(Constants.AGENT_PACKAGE_NAME)) {
                IntentFilter filter = new IntentFilter(Constants.AGENT_APP_ACTION_RESPONSE);
                filter.addCategory(Intent.CATEGORY_DEFAULT);
                AgentServiceResponseReceiver receiver = new AgentServiceResponseReceiver();
                registerReceiver(receiver, filter);
                CommonUtils.callAgentApp(context, Constants.Operation.GET_APP_DOWNLOAD_PROGRESS, null, null);
            } else {
                try {
                    result.put(INTENT_KEY_APP, downloadingApp);
                    result.put(INTENT_KEY_PROGRESS, Preference.getString(context, context.getResources().
                            getString(R.string.app_download_progress)));
                } catch (JSONException e) {
                    Log.e(TAG, "Result object creation failed" + e);
                    sendBroadcast(Constants.Status.INTERNAL_SERVER_ERROR, null);
                }
                sendBroadcast(Constants.Status.SUCCESSFUL, result.toString());
            }

            break;
        default:
            Log.e(TAG, "Invalid operation code received");
            break;
    }
}
 
Example 18
Source File: BroadcastQueryClient.java    From OpenYOLO-Android with Apache License 2.0 4 votes vote down vote up
IntentFilter getResponseFilter() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(QueryUtil.createResponseAction(mDataType, mQueryId));
    filter.addCategory(QueryUtil.BBQ_CATEGORY);
    return filter;
}
 
Example 19
Source File: LockedActivity.java    From cosu with Apache License 2.0 4 votes vote down vote up
private void setDefaultCosuPolicies(boolean active){
    // set user restrictions
    setUserRestriction(UserManager.DISALLOW_SAFE_BOOT, active);
    setUserRestriction(UserManager.DISALLOW_FACTORY_RESET, active);
    setUserRestriction(UserManager.DISALLOW_ADD_USER, active);
    setUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA, active);
    setUserRestriction(UserManager.DISALLOW_ADJUST_VOLUME, active);

    // disable keyguard and status bar
    mDevicePolicyManager.setKeyguardDisabled(mAdminComponentName, active);
    mDevicePolicyManager.setStatusBarDisabled(mAdminComponentName, active);

    // enable STAY_ON_WHILE_PLUGGED_IN
    enableStayOnWhilePluggedIn(active);

    // set system update policy
    if (active){
        mDevicePolicyManager.setSystemUpdatePolicy(mAdminComponentName,
                SystemUpdatePolicy.createWindowedInstallPolicy(60, 120));
    } else {
        mDevicePolicyManager.setSystemUpdatePolicy(mAdminComponentName,
                null);
    }

    // set this Activity as a lock task package

    mDevicePolicyManager.setLockTaskPackages(mAdminComponentName,
            active ? new String[]{getPackageName()} : new String[]{});

    IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MAIN);
    intentFilter.addCategory(Intent.CATEGORY_HOME);
    intentFilter.addCategory(Intent.CATEGORY_DEFAULT);

    if (active) {
        // set Cosu activity as home intent receiver so that it is started
        // on reboot
        mDevicePolicyManager.addPersistentPreferredActivity(
                mAdminComponentName, intentFilter, new ComponentName(
                        getPackageName(), LockedActivity.class.getName()));
    } else {
        mDevicePolicyManager.clearPackagePersistentPreferredActivities(
                mAdminComponentName, getPackageName());
    }
}
 
Example 20
Source File: InstanceIDListenerService.java    From android_external_GmsLib with Apache License 2.0 4 votes vote down vote up
public void onCreate() {
    IntentFilter filter = new IntentFilter(ACTION_C2DM_REGISTRATION);
    filter.addCategory(getPackageName());
    registerReceiver(registrationReceiver, filter);
}