Java 类android.content.IntentFilter.MalformedMimeTypeException 实例源码

项目:react-native-nfc-manager    文件:NfcManager.java   
@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();
    }
项目:Travel-Card-Reminder    文件:MainActivity.java   
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);
}
项目:android-testdpc    文件:AddCrossProfileIntentFilterFragment.java   
/**
 * 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;
}
项目:NFCPoC    文件:MainActivity.java   
/**
 * @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);
}
项目:KendaliPintuAndroid    文件:NFCOpenDoorActivity.java   
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);
}
项目:SkunkWrx    文件:NFCActivity.java   
/**
 * @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);
}
项目:SkunkWrx    文件:NFCActivity.java   
/**
 * @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);
}
项目:Studentenportal    文件:NfcLogin.java   
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() } };
}
项目:nfc    文件:StickyNotesActivity.java   
/** 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 };
}
项目:Android-NFC-P2P-Communication    文件:MainActivity.java   
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 };
    }
}
项目:Android-NFC-P2P-Communication    文件:ReadingWritingActivity.java   
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 };
    }
}
项目:AndroidNdefImplementation    文件:NfcNdefReader.java   
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);
}
项目:NFC-Reader-and-Chat    文件:Beam.java   
@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, };
}
项目:effective_android_sample    文件:ZannenNfcWriter.java   
/** 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 };
}
项目:deprecated-event-bus    文件:EventsBus.java   
/**
 * @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;
}
项目:android-basic-test    文件:NfcTest.java   
@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);
}
项目:mensacard-hack    文件:NfcPlugin.java   
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);
    }
}
项目:mensacard-hack    文件:NfcPlugin.java   
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);
    }
}
项目:mensacard-hack    文件:NfcPlugin.java   
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;
}
项目:AndroidthingsStudy    文件:ForegroundDispatch.java   
@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() } };
}
项目:anroid-nfc-plugin    文件:ScanActivity.java   
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() } };          
}
项目:android-nfc-wrapper    文件:NFCManager.java   
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 };
}
项目:FMTech    文件:lbt.java   
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.");
    }
  }
}
项目:ApkLauncher    文件:ForegroundDispatch.java   
@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() } };
}
项目:ApiDemos    文件:ForegroundDispatch.java   
@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() } };
}
项目:easypgp    文件:NfcActivity.java   
/**
 * @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);
}
项目:informant-droid    文件:SampleMediaRouteProvider.java   
private static void addDataTypeUnchecked(IntentFilter filter, String type) {
    try {
        filter.addDataType(type);
    } catch (MalformedMimeTypeException ex) {
        throw new RuntimeException(ex);
    }
}
项目:RejsekortReader    文件:DumpRaw.java   
@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);
}
项目:nfc    文件:MainActivity.java   
@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};
}
项目:V.FlyoutTest    文件:SampleMediaRouteProvider.java   
private static void addDataTypeUnchecked(IntentFilter filter, String type) {
    try {
        filter.addDataType(type);
    } catch (MalformedMimeTypeException ex) {
        throw new RuntimeException(ex);
    }
}
项目:sana.mobile    文件:BaseRunner.java   
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;
}
项目:sana.mobile    文件:EncounterTaskList.java   
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;
}
项目:droidNFCdemo    文件:MainActivity.java   
@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());
       }

}
项目:flingtap-done    文件:UpdateService.java   
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;
}
项目:andevconnfc    文件:MainActivity.java   
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");

        }
    }
项目:GameLivreNFC    文件:KeynoteActivity.java   
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);
}
项目:timelapse-sony    文件:NFCHandler.java   
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};
}
项目:geoPingProject    文件:GeoTrackOverlay.java   
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();

}
项目:felix-on-android    文件:ForegroundDispatch.java   
@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() } };
}
项目:MEng    文件:ForegroundDispatch.java   
@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() } };
}