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

The following examples show how to use android.content.IntentFilter#addDataType() . These examples are extracted from open source projects. 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
/**
 * Enables forwarding of share intent between private account and managed profile.
 */
private void enableForwarding() {
    Activity activity = getActivity();
    if (null == activity || activity.isFinishing()) {
        return;
    }
    DevicePolicyManager manager =
            (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    try {
        IntentFilter filter = new IntentFilter(Intent.ACTION_SEND);
        filter.addDataType("text/plain");
        filter.addDataType("image/jpeg");
        // This is how you can register an IntentFilter as allowed pattern of Intent forwarding
        manager.addCrossProfileIntentFilter(BasicDeviceAdminReceiver.getComponentName(activity),
                filter, FLAG_MANAGED_CAN_ACCESS_PARENT | FLAG_PARENT_CAN_ACCESS_MANAGED);
    } catch (IntentFilter.MalformedMimeTypeException e) {
        e.printStackTrace();
    }
}
 
Example 2
private void setupForegroundDispatch() {
    NfcAdapter nfcAdapter = getNfcAdapter();
    if (nfcAdapter != null) {
        IntentFilter intentFilter = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
        try {
            intentFilter.addDataType(getNfcMimeType());
        } catch (IntentFilter.MalformedMimeTypeException e) {
            Log.addEntry(LOG_TAG, e.getMessage());
            return;
        }
        nfcAdapter.enableForegroundDispatch(
               this,
               PendingIntent.getActivity(
                       this,
                       0,
                       new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0),
               new IntentFilter[] {intentFilter},
               null);
    }
}
 
Example 3
/**
 * 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 4
@Test
public void testMimeType1()
{
	try
	{
		Intent i = getIntent();
		i.setType("iccta");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("iccta/*");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v > 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 5
@Test
public void testMimeType2()
{
	try
	{
		Intent i = getIntent();
		i.setType("iccta/123");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("iccta/*");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v > 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 6
/**
 * Enables forwarding of share intent between private account and managed profile.
 */
private void enableForwarding() {
    Activity activity = getActivity();
    if (null == activity || activity.isFinishing()) {
        return;
    }
    DevicePolicyManager manager =
            (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    try {
        IntentFilter filter = new IntentFilter(Intent.ACTION_SEND);
        filter.addDataType("text/plain");
        filter.addDataType("image/jpeg");
        // This is how you can register an IntentFilter as allowed pattern of Intent forwarding
        manager.addCrossProfileIntentFilter(BasicDeviceAdminReceiver.getComponentName(activity),
                filter, FLAG_MANAGED_CAN_ACCESS_PARENT | FLAG_PARENT_CAN_ACCESS_MANAGED);
    } catch (IntentFilter.MalformedMimeTypeException e) {
        e.printStackTrace();
    }
}
 
Example 7
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    setContentView(R.layout.main);
    findViewById(R.id.write_tag).setOnClickListener(mTagWriter);

    // Handle all of our received NFC intents in this activity.
    mNfcPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Intent filters for reading a note from a tag or exchanging over p2p.
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
        ndefDetected.addDataType("text/plain");
    } catch (MalformedMimeTypeException e) { }
    mNdefExchangeFilters = new IntentFilter[] { ndefDetected };

    // Intent filters for writing to a tag
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    mWriteTagFilters = new IntentFilter[] { tagDetected };
}
 
Example 8
@Test
public void testMimeType5()
{
	try
	{
		Intent i = getIntent();
		i.setType("123/*");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("123/iccta");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v > 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 9
@Test
public void testMimeType6()
{
	try
	{
		Intent i = getIntent();
		i.setType("*/123");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("1234/123");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v < 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 10
@Test
public void testMimeType7()
{
	try
	{
		Intent i = getIntent();
		i.setType("*");
		
		IntentFilter f = getIntentFilter();
		f.addDataType("abc/123");
		
		int v = f.match(i.getAction(), i.getType(), i.getScheme(), i.getData(), i.getCategories(), "IccTA");
		
		Assert.assertTrue(v < 0);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
		Assert.fail();
	}
}
 
Example 11
@Override
protected void onResume() {
    super.onResume();
    Logf.I(TAG, "onResume()");
    IntentFilter filter = new IntentFilter(Response.RESPONSE);
    try {
        filter.addDataType(Encounters.CONTENT_ITEM_TYPE);
        filter.addDataType(EncounterTasks.CONTENT_ITEM_TYPE);
    } catch (Exception e) {
    }
    LocalBroadcastManager.getInstance(this.getApplicationContext()).registerReceiver(mReceiver, filter);
    //bindSessionService();
    // This prevents us from relaunching the login on every resume
    dump();
    hideViewsByRole();
}
 
Example 12
@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    setContentView(R.layout.foreground_dispatch);
    mText = (TextView) findViewById(R.id.text);
    mText.setText("Scan a tag");

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Setup an intent filter for all MIME based dispatches
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
        ndef.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    }
    mFilters = new IntentFilter[] {
            ndef,
    };

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}
 
Example 13
public void init() {
    Intent nfcIntent = new Intent(this, this.getClass());
    nfcIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, nfcIntent, 0);
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
        ndef.addDataType("*/*");    /* Handles all MIME based dispatches.
                                   You should specify only the ones that you need. */
    } catch (IntentFilter.MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    }
    IntentFilter[] intentFiltersArray = new IntentFilter[]{ndef,};
    String[][] techList = new String[1][1];
    techList[0][0] = MifareClassic.class.getName();
    nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techList);
    disposable.add(
            nfcManager.requestProgressProcessor().onBackpressureBuffer()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(
                            message -> binding.currentMessage.setText(message),
                            Timber::e
                    )
    );

    disposable.add(
            nfcManager.requestInitProcessor()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(init -> {
                                if (!init) {
                                    binding.nfcBg.animate().scaleX(0.1f).scaleY(0.1f).setDuration(1500)
                                            .withEndAction(() -> binding.nfcBg.setVisibility(View.GONE));
                                }
                            },
                            Timber::e)
    );
}
 
Example 14
public void initializeNFC() {

        if (nfcInit == false) {
            PackageManager pm = getPackageManager();
            nfcSupported = pm.hasSystemFeature(PackageManager.FEATURE_NFC);

            if (nfcSupported == false) {
                return;
            }

            // when is in foreground
            MLog.d(TAG, "starting NFC");
            mAdapter = NfcAdapter.getDefaultAdapter(this);

            // PedingIntent will be delivered to this activity
            mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

            // Setup an intent filter for all MIME based dispatches
            IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
            try {
                ndef.addDataType("*/*");
            } catch (IntentFilter.MalformedMimeTypeException e) {
                throw new RuntimeException("fail", e);
            }
            mFilters = new IntentFilter[]{ndef,};

            // Setup a tech list for all NfcF tags
            mTechLists = new String[][]{new String[]{NfcF.class.getName()}};
            nfcInit = true;
        }
    }
 
Example 15
public IntentFilter buildFilter() {
    Log.i(TAG, "buildFilter()");
    IntentFilter filter = new IntentFilter(Response.RESPONSE);
    filter.addDataScheme(Subjects.CONTENT_URI.getScheme());
    try {

        filter.addDataType(Subjects.CONTENT_TYPE);
        filter.addDataType(Subjects.CONTENT_ITEM_TYPE);
    } catch (IntentFilter.MalformedMimeTypeException e) {

    }
    return filter;
}
 
Example 16
private static void addDataTypeUnchecked(IntentFilter filter, String type) {
    try {
        filter.addDataType(type);
    } catch (MalformedMimeTypeException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 17
Source Project: V.FlyoutTest   File: SampleMediaRouteProvider.java    License: MIT License 5 votes vote down vote up
private static void addDataTypeUnchecked(IntentFilter filter, String type) {
    try {
        filter.addDataType(type);
    } catch (MalformedMimeTypeException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 18
@Override
public IntentFilter buildFilter() {
    Log.i(TAG, "buildFilter()");
    IntentFilter filter = new IntentFilter(Response.RESPONSE);
    filter.addDataScheme(Subjects.CONTENT_URI.getScheme());
    try {
        filter.addDataType(Subjects.CONTENT_ITEM_TYPE);
        filter.addDataType(Subjects.CONTENT_TYPE);
    } catch (Exception e) {

    }
    return filter;
}
 
Example 19
public IntentFilter buildFilter() {
    Log.i(TAG, "buildFilter()");
    IntentFilter filter = new IntentFilter(DispatchResponseReceiver.BROADCAST_RESPONSE);
    filter.addDataScheme(Encounters.CONTENT_URI.getScheme());
    try {

        filter.addDataType(Encounters.CONTENT_ITEM_TYPE);
    } catch (MalformedMimeTypeException e) {

    }
    return filter;
}
 
Example 20
public IntentFilter buildFilter() {
    IntentFilter filter = new IntentFilter(Response.RESPONSE);
    try {
        filter.addDataType(EncounterTasks.CONTENT_TYPE);
        filter.addDataType(EncounterTasks.CONTENT_ITEM_TYPE);
        filter.addDataType(Subjects.CONTENT_TYPE);
    } catch (MalformedMimeTypeException e) {
    }
    return filter;
}