Java Code Examples for android.content.IntentFilter#addDataType()
The following examples show how to use
android.content.IntentFilter#addDataType() .
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: BasicManagedProfileFragment.java From enterprise-samples with Apache License 2.0 | 6 votes |
/** * 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
Source File: MainActivity.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 3
Source File: IntentMatchFilterTest.java From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 | 6 votes |
@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 4
Source File: IntentMatchFilterTest.java From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 | 6 votes |
@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 5
Source File: IntentMatchFilterTest.java From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 | 6 votes |
@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 6
Source File: ZannenNfcWriter.java From effective_android_sample with Apache License 2.0 | 6 votes |
/** 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 7
Source File: BasicManagedProfileFragment.java From android-BasicManagedProfile with Apache License 2.0 | 6 votes |
/** * 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 8
Source File: IntentMatchFilterTest.java From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 | 6 votes |
@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 9
Source File: IntentMatchFilterTest.java From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 | 6 votes |
@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 10
Source File: AddCrossProfileIntentFilterFragment.java From android-testdpc with Apache License 2.0 | 6 votes |
/** * 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 11
Source File: ActivityAddFriend.java From ploggy with GNU General Public License v3.0 | 6 votes |
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 12
Source File: PatientsList.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 13
Source File: AppRunnerActivity.java From PHONK with GNU General Public License v3.0 | 5 votes |
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 14
Source File: NfcDataWriteActivity.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 15
Source File: SampleMediaRouteProvider.java From android-MediaRouter with Apache License 2.0 | 5 votes |
private static void addDataTypeUnchecked(IntentFilter filter, String type) { try { filter.addDataType(type); } catch (MalformedMimeTypeException ex) { throw new RuntimeException(ex); } }
Example 16
Source File: SampleMediaRouteProvider.java From V.FlyoutTest with MIT License | 5 votes |
private static void addDataTypeUnchecked(IntentFilter filter, String type) { try { filter.addDataType(type); } catch (MalformedMimeTypeException ex) { throw new RuntimeException(ex); } }
Example 17
Source File: PatientRunner.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 18
Source File: BaseRunner.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 19
Source File: ForegroundDispatch.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@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 20
Source File: EncounterTaskList.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }