Java Code Examples for android.content.IntentFilter.MalformedMimeTypeException

The following are top voted examples for showing how to use android.content.IntentFilter.MalformedMimeTypeException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: react-native-nfc-manager   File: NfcManager.java   View source code 6 votes vote down vote up
@ReactMethod
  private void registerTagEvent(String alertMessage, Boolean invalidateAfterFirstRead, Callback callback) {
      Log.d(LOG_TAG, "registerTag");
isForegroundEnabled = true;

// capture all mime-based dispatch NDEF
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
	ndef.addDataType("*/*");
} catch (MalformedMimeTypeException e) {
	throw new RuntimeException("fail", e);
   }
intentFilters.add(ndef);

// capture all rest NDEF, such as uri-based
      intentFilters.add(new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED));
techLists.add(new String[]{Ndef.class.getName()});

// for those without NDEF, get them as tags
      intentFilters.add(new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED));

if (isResumed) {
	enableDisableForegroundDispatch(true);
}
      callback.invoke();
	}
 
Example 2
Project: Travel-Card-Reminder   File: MainActivity.java   View source code 6 votes vote down vote up
public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), ReadCardActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][]{};

    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType("*/*"); //TODO Use only needed MIME based dispatches.
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("MIME type not supported.");
    }

    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
 
Example 3
Project: android-testdpc   File: AddCrossProfileIntentFilterFragment.java   View source code 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 4
Project: NFCPoC   File: MainActivity.java   View source code 6 votes vote down vote up
/**
 * @param activity The corresponding {@link Activity} requesting the foreground dispatch.
 * @param adapter  The {@link NfcAdapter} used for the foreground dispatch.
 */
public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][]{};

    // Notice that this is the same filter as in our manifest.
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType(MIME_TEXT_PLAIN);
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("Check your mime type.");
    }

    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
 
Example 5
Project: KendaliPintuAndroid   File: NFCOpenDoorActivity.java   View source code 6 votes vote down vote up
public static void setupForegroundDispatch(final Activity activity,	NfcAdapter adapter) {
	final Intent intent = new Intent(activity.getApplicationContext(),activity.getClass());
	intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

	final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);

	IntentFilter[] filters = new IntentFilter[1];
	String[][] techList = new String[][] {};
	filters[0] = new IntentFilter();
	filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
	filters[0].addCategory(Intent.CATEGORY_DEFAULT);
	try {
		filters[0].addDataType(MIME_TEXT_PLAIN);
	} catch (MalformedMimeTypeException e) {
		throw new RuntimeException("Check your mime type.");
	}
	adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
 
Example 6
Project: SkunkWrx   File: NFCActivity.java   View source code 6 votes vote down vote up
/**
 * @param activity The corresponding {@link Activity} requesting the foreground dispatch.
 * @param adapter The {@link NfcAdapter} used for the foreground dispatch.
 */
public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
 
    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
 
    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][]{};
 
    // Notice that this is the same filter as in our manifest.
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType(MIME_TEXT_PLAIN);
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("Check your mime type.");
    }
     
    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
 
Example 7
Project: SkunkWrx   File: NFCActivity.java   View source code 6 votes vote down vote up
/**
 * @param activity The corresponding {@link Activity} requesting the foreground dispatch.
 * @param adapter The {@link NfcAdapter} used for the foreground dispatch.
 */
public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
 
    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
 
    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][]{};
 
    // Notice that this is the same filter as in our manifest.
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType(MIME_TEXT_PLAIN);
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("Check your mime type.");
    }
     
    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
 
Example 8
Project: Studentenportal   File: NfcLogin.java   View source code 6 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {
    // setup NFC
    // http://stackoverflow.com/questions/5685946/nfc-broadcastreceiver-problem
    // http://stackoverflow.com/questions/5685770/nfc-intent-get-info-from-the-tag
	// NOTE on devices without NFC, this method call returns NULL
    mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity);
    
    mNfcPendingIntent = PendingIntent.getActivity(mActivity, 0, new Intent(mActivity, mActivity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    IntentFilter tech = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
    try {
        tech.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    }
    mNfcFilters = new IntentFilter[] { tech };
    
    // Mifare Classic are also NfcA, but in contrary to NfcA, MifareClassic support is optional
    // http://developer.android.com/reference/android/nfc/tech/MifareClassic.html
    mNfcTechLists = new String[][] { new String[] { NfcA.class.getName() } };
}
 
Example 9
Project: nfc   File: StickyNotesActivity.java   View source code 6 votes vote down vote up
/** 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);
    mNote = ((EditText) findViewById(R.id.note));
    mNote.addTextChangedListener(mTextWatcher);

    // 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 10
Project: Android-NFC-P2P-Communication   File: MainActivity.java   View source code 6 votes vote down vote up
private void _init()
{
	_nfcAdapter = NfcAdapter.getDefaultAdapter(this);
	
	if (_nfcAdapter == null)
	{
		Toast.makeText(this, "This device does not support NFC.", Toast.LENGTH_LONG).show();
		return;
	}
	
	if (_nfcAdapter.isEnabled())
	{
		_pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
		
		IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
		try
		{
			ndefDetected.addDataType(_MIME_TYPE);
		} catch (MalformedMimeTypeException e)
		{
			Log.e(this.toString(), e.getMessage());
		}
		
		_intentFilters = new IntentFilter[] { ndefDetected };
	}
}
 
Example 11
Project: Android-NFC-P2P-Communication   File: ReadingWritingActivity.java   View source code 6 votes vote down vote up
private void _init()
{
	_nfcAdapter = NfcAdapter.getDefaultAdapter(this);
	
	if (_nfcAdapter == null)
	{
		Toast.makeText(this, "This device does not support NFC.", Toast.LENGTH_LONG).show();
		return;
	}
	
	if (_nfcAdapter.isEnabled())
	{
		_pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
		
		IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
		try
		{
			ndefDetected.addDataType(_MIME_TYPE);
		} catch (MalformedMimeTypeException e)
		{
			Log.e(this.toString(), e.getMessage());
		}
		
		_readIntentFilters = new IntentFilter[] { ndefDetected };
	}
}
 
Example 12
Project: AndroidNdefImplementation   File: NfcNdefReader.java   View source code 6 votes vote down vote up
public void setupForegroundDispatch(Activity activity) {
	final Intent intent = new Intent(activity.getApplicationContext(),
			activity.getClass());
	intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

	final PendingIntent pendingIntent = PendingIntent.getActivity(
			activity.getApplicationContext(), 0, intent, 0);

	IntentFilter[] filters = new IntentFilter[1];
	String[][] techList = new String[][] {};

	// Notice that this is the same filter as in our manifest.
	filters[0] = new IntentFilter();
	filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
	filters[0].addCategory(Intent.CATEGORY_DEFAULT);
	try {
		filters[0].addDataType(MIME_TEXT_PLAIN);
	} catch (MalformedMimeTypeException e) {
		throw new RuntimeException("Check your mime type.");
	}
	nfcAdapter.enableForegroundDispatch(activity, pendingIntent, filters,
			techList);
}
 
Example 13
Project: NFC-Reader-and-Chat   File: Beam.java   View source code 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.beamer);

	mInfoText = (TextView) findViewById(R.id.mInfo);
	writeText = (EditText) findViewById(R.id.textWrite);

	// Check for available NFC Adapter
	mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
	if (mNfcAdapter == null) {
		mInfoText = (TextView) findViewById(R.id.mInfo);
		mInfoText.setText("NFC is not available on this device.");
	}

	mNfcPendingIntent = PendingIntent.getActivity(this, 0,
			new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
	// Intent filters for exchanging over p2p.
	IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
	try {
		ndefDetected.addDataType("*/*");
	} catch (MalformedMimeTypeException e) {
		Toast.makeText(getApplicationContext(), "Error Exception", Toast.LENGTH_SHORT).show();
	}
	mNdefExchangeFilters = new IntentFilter[] { ndefDetected, };
}
 
Example 14
Project: effective_android_sample   File: ZannenNfcWriter.java   View source code 6 votes vote down vote up
/** 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 15
Project: deprecated-event-bus   File: EventsBus.java   View source code 6 votes vote down vote up
/**
 * @return Registration id to use in unregister(regId) method
 */
public static synchronized int register(String receiverId, EventsListener listener) {
    check();

    if (listener == null) throw new NullPointerException("Listener cannot be null");

    EventsReceiver receiver = new EventsReceiver();
    receiver.mReceiverId = receiverId;
    receiver.mListener = listener;

    try {
        sAppContext.registerReceiver(receiver, new IntentFilter(sIntentAction, BASE_MIME_TYPE + "/*"));
    } catch (MalformedMimeTypeException e) {
        e.printStackTrace();
    }

    sReceiversMap.put(++sRegistrationId, receiver);

    for (Intent sticky : sStickyEventsMap.values()) {
        receiver.onReceive(sAppContext, sticky);
    }

    return sRegistrationId;
}
 
Example 16
Project: android-basic-test   File: NfcTest.java   View source code 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());

    Intent intent = new Intent(getActivity(), getActivity().getClass());
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mPendingIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);

    mTechLists = new String[][] {new String[] {MifareClassic.class.getName()}};
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
    try {
        ndef.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    }
    mFilters = new IntentFilter[] {ndef};

    setButtonVisibility(true);
}
 
Example 17
Project: mensacard-hack   File: NfcPlugin.java   View source code 5 votes vote down vote up
private void removeMimeType(JSONArray data, CallbackContext callbackContext) throws JSONException {
    String mimeType = "";
    try {
        mimeType = data.getString(0);
        /*boolean removed =*/ removeIntentFilter(mimeType);
        callbackContext.success();
    } catch (MalformedMimeTypeException e) {
        callbackContext.error("Invalid MIME Type " + mimeType);
    }
}
 
Example 18
Project: mensacard-hack   File: NfcPlugin.java   View source code 5 votes vote down vote up
private void registerMimeType(JSONArray data, CallbackContext callbackContext) throws JSONException {
    String mimeType = "";
    try {
        mimeType = data.getString(0);
        intentFilters.add(createIntentFilter(mimeType));
        callbackContext.success();
    } catch (MalformedMimeTypeException e) {
        callbackContext.error("Invalid MIME Type " + mimeType);
    }
}
 
Example 19
Project: mensacard-hack   File: NfcPlugin.java   View source code 5 votes vote down vote up
private boolean removeIntentFilter(String mimeType) throws MalformedMimeTypeException {
  boolean removed = false;
  Iterator<IntentFilter> iter = intentFilters.iterator();
  while (iter.hasNext()) {
    IntentFilter intentFilter = iter.next();
    String mt = intentFilter.getDataType(0);
    if (mimeType.equals(mt)) {
      intentFilters.remove(intentFilter);
      removed = true;
    }
  }
  return removed;
}
 
Example 20
Project: AndroidthingsStudy   File: ForegroundDispatch.java   View source code 5 votes vote down vote up
@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 21
Project: anroid-nfc-plugin   File: ScanActivity.java   View source code 5 votes vote down vote up
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	// Create NFC Adapter
	mAdapter = NfcAdapter.getDefaultAdapter(this);

	// Pending intent
	mPendingIntent = PendingIntent.getActivity(this, 0,
			new Intent(this, ScanActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

	// Setup an intent filter for all MIME based dispatches (TEXT);
	IntentFilter ndefText = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
	try {
		ndefText.addDataType("*/*");
	} catch (MalformedMimeTypeException e) {
	}		

	// Setup an intent filter for all MIME based dispatches (URI);
	IntentFilter ndefURI = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
	ndefURI.addDataScheme("http");
	ndefURI.addDataScheme("https");

	mFilters = new IntentFilter[] { ndefText, ndefURI};	
	
	// Setup a tech list for all NfcF tags
	mTechLists = new String[][] { new String[] { NfcF.class.getName() } };  		
}
 
Example 22
Project: android-nfc-wrapper   File: NFCManager.java   View source code 5 votes vote down vote up
public IntentFilter[] getIntentFilter(String action, String category, String mimeType) {
    IntentFilter filter = new IntentFilter();
    if(action != null) filter.addAction(action);
    if(category != null) filter.addCategory(category);

    if(mimeType != null) {
        try {
            filter.addDataType(mimeType);
        } catch (MalformedMimeTypeException e) {
            throw new RuntimeException("Error handling MIME type.");
        }
    }

    return new IntentFilter[] { filter };
}
 
Example 23
Project: FMTech   File: lbt.java   View source code 5 votes vote down vote up
public final void a(Bundle paramBundle)
{
  super.a(paramBundle);
  this.ac = this.m.getString("square_id");
  if (paramBundle != null)
  {
    this.ag = ((Uri)paramBundle.getParcelable("uploading_image_uri"));
    this.ah = ((Uri)paramBundle.getParcelable("current_data"));
    this.Z = ((ipf)paramBundle.getParcelable("selected_user_photo"));
    this.b = ((RectF)paramBundle.getParcelable("CROP_COORDINATES"));
  }
  mbf localmbf = this.bn;
  if (lcm.a == null)
  {
    IntentFilter localIntentFilter = new IntentFilter();
    lcm.a = localIntentFilter;
    localIntentFilter.addAction("com.google.android.libraries.social.squares.edit.UPLOAD_PROGRESS");
  }
  try
  {
    lcm.a.addDataType("image/*");
    fy.a(localmbf.getApplicationContext()).a(new lcn(this), lcm.a);
    return;
  }
  catch (IntentFilter.MalformedMimeTypeException localMalformedMimeTypeException)
  {
    for (;;)
    {
      Log.e("UploadSquarePhotoTask", "MIME type cannot be recognized.");
    }
  }
}
 
Example 24
Project: ApkLauncher   File: ForegroundDispatch.java   View source code 5 votes vote down vote up
@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 = org.bbs.apklauncher.emb.PendingIntentHelper.getActivity(this, 0,
            new org.bbs.apklauncher.emb.IntentHelper(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 25
Project: ApiDemos   File: ForegroundDispatch.java   View source code 5 votes vote down vote up
@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 26
Project: easypgp   File: NfcActivity.java   View source code 5 votes vote down vote up
/**
 * @param activity
 *          The corresponding {@link Activity} requesting the foreground
 *          dispatch.
 * @param adapter
 *          The {@link NfcAdapter} used for the foreground dispatch.
 */
public static void setupForegroundDispatch(final Activity activity,
    NfcAdapter adapter) {
  final Intent intent = new Intent(activity.getApplicationContext(),
      activity.getClass());
  intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

  final PendingIntent pendingIntent = PendingIntent.getActivity(
      activity.getApplicationContext(), 0, intent, 0);

  IntentFilter[] filters = new IntentFilter[1];
  String[][] techList = new String[][] {};

  // Notice that this is the same filter as in our manifest.
  filters[0] = new IntentFilter();
  filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
  filters[0].addCategory(Intent.CATEGORY_DEFAULT);
  try {
    filters[0].addDataType(MIME_PUBLIC_KEY);
    filters[0].addDataType(MIME_TEXT_PLAIN);
  } catch (MalformedMimeTypeException e) {
    throw new RuntimeException("Check your mime type.");
  }

  adapter
      .enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
 
Example 27
Project: informant-droid   File: SampleMediaRouteProvider.java   View source code 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 28
Project: RejsekortReader   File: DumpRaw.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_dump_raw);
	// Show the Up button in the action bar.
	setupActionBar();
	
	mAdapter = NfcAdapter.getDefaultAdapter(this);
       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);
    }
	IntentFilter td = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
	mFilters = new IntentFilter[] { ndef, td };

	// Setup a tech list for all NfcF tags
	mTechLists = new String[][] { 
			new String[] { 
					/*NfcV.class.getName(),
					NfcF.class.getName(),*/ 
					NfcA.class.getName(),
					//NfcB.class.getName() 
					} 
			};
	
	txtRaw = (TextView) findViewById(R.id.txtRaw);
}
 
Example 29
Project: nfc   File: MainActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    findViewById(R.id.write_tag).setOnClickListener(mTagWriter);
    mNote = ((EditText) findViewById(R.id.note));
    mNote.addTextChangedListener(mTextWatcher);

    // 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) {
        Log.d(TAG, "Failed to addDataType");
    }
    mNdefExchangeFilters = new IntentFilter[]{ndefDetected};

    // Intent filters for writing to a tag
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    mWriteTagFilters = new IntentFilter[]{tagDetected};
}
 
Example 30
Project: V.FlyoutTest   File: SampleMediaRouteProvider.java   View source code 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 31
Project: sana.mobile   File: BaseRunner.java   View source code 5 votes vote down vote up
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 32
Project: sana.mobile   File: EncounterTaskList.java   View source code 5 votes vote down vote up
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;
}
 
Example 33
Project: droidNFCdemo   File: MainActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
	
	IntentFilter ndef1 = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
	//IntentFilter ndef2 = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
	mFilters = new IntentFilter[] {
            ndef1,
            //ndef2,
    };
	
       try {
           ndef1.addDataType("*/*");
           //ndef2.addDataType("*/*");
       } catch (MalformedMimeTypeException e) {
           throw new RuntimeException("fail", e);
       }
       mAdapter = NfcAdapter.getDefaultAdapter(this);
       
       if (getIntent() != null){
       	resolveIntent(getIntent());
       }
        
}
 
Example 34
Project: flingtap-done   File: UpdateService.java   View source code 5 votes vote down vote up
protected IntentFilter getIntentFilter() throws MalformedMimeTypeException {
	IntentFilter filter = new IntentFilter(Intent.ACTION_VIEW);
	filter.addDataScheme("http");
	filter.addDataAuthority("beta.leankeen.com", null);
	filter.addDataAuthority("www.leankeen.com", null);
	filter.addDataAuthority("www.flingtap.com", null);
	filter.addDataAuthority("market.android.com", null);
	
	return filter;
}
 
Example 35
Project: andevconnfc   File: MainActivity.java   View source code 5 votes vote down vote up
private void resetForegroundDispatcher() {

		nfcAdapter.disableForegroundDispatch(this);

		if (!readRtdOnly) {
			nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, null,
					null);
			Log.i(DEBUG_MAIN_ACTIVITY, "Listening for any type of tag scan");
		} else {
			IntentFilter rtdFilter = new IntentFilter(
					NfcAdapter.ACTION_NDEF_DISCOVERED);
			try {
				rtdFilter.addDataType("text/plain");
			} catch (MalformedMimeTypeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			IntentFilter[] filters = new IntentFilter[] { rtdFilter };
			nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent,
					filters, null);

			Log.i(DEBUG_MAIN_ACTIVITY,
					"Listening only for an RTD_TEXT NDEF record on a tag");

		}
	}
 
Example 36
Project: GameLivreNFC   File: KeynoteActivity.java   View source code 5 votes vote down vote up
private void prepareNFC() {
	IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);

	try {
		ndefDetected.addDataType("application/vnd.serpro.nfcevents");
	} catch (MalformedMimeTypeException e) {
	}
	mNdefExchangeFilters = new IntentFilter[] { ndefDetected };

	mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
	mNfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
}
 
Example 37
Project: timelapse-sony   File: NFCHandler.java   View source code 5 votes vote down vote up
public static IntentFilter[] getIntentFilterArray() {
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
        ndef.addDataType(SONY_MIME_TYPE);
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    }
    return new IntentFilter[]{ndef};
}
 
Example 38
Project: geoPingProject   File: GeoTrackOverlay.java   View source code 5 votes vote down vote up
public GeoTrackOverlay(final Context ctx, final MapView mapView, final ResourceProxy pResourceProxy, LoaderManager loaderManager, Person person, long timeInMs, GeotrackLastAddedListener geotrackLastAddedListener) {
super(pResourceProxy);
GEOTRACK_LIST_LOADER = R.id.config_id_geotrack_list_loader + (int) person.id + 1000;
// person.id;
Log.d(TAG, "#################################");
Log.d(TAG, "### Create " + person);
Log.d(TAG, "#################################");
this.context = ctx;
this.person = person;
this.loaderManager = loaderManager;
this.mapView = mapView;
this.mMapController = mapView.getController();

setDateRange(timeInMs);
// Service
this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
enableThreadExecutors();
if (Geocoder.isPresent()) {
	this.geocoder = new Geocoder(context, Locale.getDefault());
} else {
	this.geocoder = null;
	Log.w(TAG, "The Geocoder is not Present");
}
// Listener
this.geotrackLastAddedListener = geotrackLastAddedListener;
mStatusReceiver = new StatusReceiver();
try {
	mStatusReceiverIntentFilter = new IntentFilter(Intents.ACTION_NEW_GEOTRACK_INSERTED, GeoTrackerProvider.Constants.ITEM_MIME_TYPE);
} catch (MalformedMimeTypeException e) {
	Log.e(TAG, "Coud not create Intenfilter for mStatusReceiver : " + e.getMessage(), e);
 
}

// Init
initDirectionPaint(person.color);
onResume();

}
 
Example 39
Project: felix-on-android   File: ForegroundDispatch.java   View source code 5 votes vote down vote up
@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 40
Project: MEng   File: ForegroundDispatch.java   View source code 5 votes vote down vote up
@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() } };
}