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

The following examples show how to use android.content.IntentFilter#addDataAuthority() . 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: BlogViewer.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // Get the NFC Adapter.
  NfcManager nfcManager = (NfcManager)getSystemService(Context.NFC_SERVICE);
  mNFCAdapter = nfcManager.getDefaultAdapter();

  // Create the Pending Intent.
  int flags = 0;
  Intent nfcIntent = new Intent(this, getClass());
  nfcIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  mNFCPendingIntent =
    PendingIntent.getActivity(this, NFC_REQUEST_CODE, nfcIntent, flags);

  // Create an Intent Filter limited to the URI or MIME type to
  // intercept TAG scans from.
  IntentFilter tagIntentFilter =
    new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
  tagIntentFilter.addDataScheme("http");
  tagIntentFilter.addDataAuthority("blog.radioactiveyak.com", null);
  mIntentFiltersArray = new IntentFilter[] { tagIntentFilter };

  // Create an array of technologies to handle.
  mTechListsArray = new String[][] {
    new String[] {
      NfcF.class.getName()
    }
  };

  // Process the Intent used to start the Activity/
  String action = getIntent().getAction();
  if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
    processIntent(getIntent());
}
 
Example 2
Source File: BleEvents.java    From science-journal with Apache License 2.0 5 votes vote down vote up
static IntentFilter createIntentFilter(String address) {
  IntentFilter intent = new IntentFilter();

  intent.addDataScheme(DATA_SCHEME);
  intent.addDataAuthority(address, null);

  intent.addAction(BLE_UNSUPPORTED);
  intent.addAction(BLE_DISABLED);

  intent.addAction(GATT_CONNECT);
  intent.addAction(GATT_CONNECT_FAIL);
  intent.addAction(GATT_DISCONNECT);
  intent.addAction(GATT_DISCONNECT_FAIL);
  intent.addAction(SERVICES_OK);
  intent.addAction(SERVICES_FAIL);

  intent.addAction(READ_CHAR_OK);
  intent.addAction(READ_CHAR_FAIL);
  intent.addAction(WRITE_CHAR_OK);
  intent.addAction(WRITE_CHAR_FAIL);

  intent.addAction(CHAR_CHANGED);

  intent.addAction(READ_DESC_OK);
  intent.addAction(READ_DESC_FAIL);
  intent.addAction(WRITE_DESC_OK);
  intent.addAction(WRITE_DESC_FAIL);

  return intent;
}
 
Example 3
Source File: Installer.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets an {@link IntentFilter} for matching events from the install
 * process based on {@code canonicalUri}, which is the global unique
 * ID for a package going through the install process.
 *
 * @see InstallManagerService for more about {@code canonicalUri}
 */
public static IntentFilter getInstallIntentFilter(Uri canonicalUri) {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Installer.ACTION_INSTALL_STARTED);
    intentFilter.addAction(Installer.ACTION_INSTALL_COMPLETE);
    intentFilter.addAction(Installer.ACTION_INSTALL_INTERRUPTED);
    intentFilter.addAction(Installer.ACTION_INSTALL_USER_INTERACTION);
    intentFilter.addDataScheme(canonicalUri.getScheme());
    intentFilter.addDataAuthority(canonicalUri.getHost(), String.valueOf(canonicalUri.getPort()));
    intentFilter.addDataPath(canonicalUri.getPath(), PatternMatcher.PATTERN_LITERAL);
    return intentFilter;
}
 
Example 4
Source File: DownloaderService.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get a prepared {@link IntentFilter} for use for matching this service's action events.
 *
 * @param canonicalUrl the URL used as the unique ID for the specific package
 */
public static IntentFilter getIntentFilter(String canonicalUrl) {
    Uri uri = Uri.parse(canonicalUrl);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Downloader.ACTION_STARTED);
    intentFilter.addAction(Downloader.ACTION_PROGRESS);
    intentFilter.addAction(Downloader.ACTION_COMPLETE);
    intentFilter.addAction(Downloader.ACTION_INTERRUPTED);
    intentFilter.addAction(Downloader.ACTION_CONNECTION_FAILED);
    intentFilter.addDataScheme(uri.getScheme());
    intentFilter.addDataAuthority(uri.getHost(), String.valueOf(uri.getPort()));
    intentFilter.addDataPath(uri.getPath(), PatternMatcher.PATTERN_LITERAL);
    return intentFilter;
}
 
Example 5
Source File: IntentFilterDB.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 4 votes vote down vote up
public IntentFilter toIntentFilter(int type)
{
	if (1 == type)
	{
		return toIntentFilter();
	}
	
	IntentFilter filter = toIntentFilter();
	
	try
	{
		//for mimetype
		if (type >= 1)
		{
			if (! StringUtil.isEmpty(dataAndType.getType()))
			{
				if (! StringUtil.isEmpty(dataAndType.getSubtype()))
				{
					filter.addDataType(dataAndType.getType() + "/" + dataAndType.getSubtype());
					filterType = 2;
				}
				else
				{
					filter.addDataType(dataAndType.getType());
					filterType = 2;
				}
			}
		}
		
		//for data
		if (type >= 2)
		{
			if (! StringUtil.isEmpty(dataAndType.getHost()))
			{
				if (! StringUtil.isEmpty(dataAndType.getPort()))
				{
					filter.addDataAuthority(dataAndType.getHost(), dataAndType.getPort());
				}
				else
				{
					filter.addDataAuthority(dataAndType.getHost(), null);
				}
				
				
				filterType = 3;
			}
			
			if (! StringUtil.isEmpty(dataAndType.getPath()))
			{
				filter.addDataPath(dataAndType.getPath(), PatternMatcher.PATTERN_LITERAL);
				
				filterType = 3;
			}
			
			if (! StringUtil.isEmpty(dataAndType.getScheme()))
			{
				filter.addDataScheme(dataAndType.getScheme());
				
				filterType = 3;
			}
		}
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
	}
	
	return filter;
}