當前位置: 首頁>>代碼示例>>Java>>正文


Java NdefRecord.TNF_MIME_MEDIA屬性代碼示例

本文整理匯總了Java中android.nfc.NdefRecord.TNF_MIME_MEDIA屬性的典型用法代碼示例。如果您正苦於以下問題:Java NdefRecord.TNF_MIME_MEDIA屬性的具體用法?Java NdefRecord.TNF_MIME_MEDIA怎麽用?Java NdefRecord.TNF_MIME_MEDIA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.nfc.NdefRecord的用法示例。


在下文中一共展示了NdefRecord.TNF_MIME_MEDIA屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractMimePayload

@Nullable
public static byte[] extractMimePayload(final String mimeType, final NdefMessage message) {
    final byte[] mimeBytes = mimeType.getBytes(Charsets.US_ASCII);

    for (final NdefRecord record : message.getRecords()) {
        if (record.getTnf() == NdefRecord.TNF_MIME_MEDIA && Arrays.equals(record.getType(), mimeBytes))
            return record.getPayload();
    }

    return null;
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:11,代碼來源:Nfc.java

示例2: generateNdefMessage

/**
 * Generate an NDEF message containing the given Wi-Fi configuration
 *
 * @param wifiNetwork the Wi-Fi configuration to convert
 * @return an NDEF message containing the given Wi-Fi configuration
 */
public static NdefMessage generateNdefMessage(WifiNetwork wifiNetwork) {
    byte[] payload = generateNdefPayload(wifiNetwork);

    NdefRecord mimeRecord = new NdefRecord(
            NdefRecord.TNF_MIME_MEDIA,
            NfcUtils.NFC_TOKEN_MIME_TYPE.getBytes(Charset.forName("US-ASCII")),
            new byte[0],
            payload);
    NdefRecord aarRecord = NdefRecord.createApplicationRecord(PACKAGE_NAME);

    return new NdefMessage(new NdefRecord[] {mimeRecord, aarRecord});
}
 
開發者ID:bparmentier,項目名稱:WiFiKeyShare,代碼行數:18,代碼來源:NfcUtils.java

示例3: parseTnf

private static String parseTnf(Context ctx, NdefRecord record) {
    short tnf = record.getTnf();
    switch(tnf) {
        case NdefRecord.TNF_ABSOLUTE_URI:
            return ctx.getString(R.string.tnf_abs_uri);
        case NdefRecord.TNF_EMPTY:
            return ctx.getString(R.string.tnf_empty);
        case NdefRecord.TNF_EXTERNAL_TYPE:
            return ctx.getString(R.string.tnf_external);
        case NdefRecord.TNF_MIME_MEDIA:
            return ctx.getString(R.string.tnf_mime_media);
        case NdefRecord.TNF_UNCHANGED:
            return ctx.getString(R.string.tnf_unchanged);
        case NdefRecord.TNF_WELL_KNOWN:
            return ctx.getString(R.string.tnf_well_known);
        default:
            return ctx.getString(R.string.tnf_unknown);
    }
}
 
開發者ID:TapTrack,項目名稱:TappyBLE,代碼行數:19,代碼來源:TcmpMessageDescriptor.java

示例4: parseType

private static String parseType(Context ctx, NdefRecord record) {
    byte[] type = record.getType();
    if(Arrays.equals(type, NdefRecord.RTD_URI))
        return ctx.getString(R.string.rtd_uri);
    else if(Arrays.equals(type,NdefRecord.RTD_ALTERNATIVE_CARRIER))
        return ctx.getString(R.string.rtd_alt_carrier);
    else if(Arrays.equals(type,NdefRecord.RTD_HANDOVER_CARRIER))
        return ctx.getString(R.string.rtd_handover_carrier);
    else if(Arrays.equals(type,NdefRecord.RTD_HANDOVER_REQUEST))
        return ctx.getString(R.string.rtd_handover_request);
    else if(Arrays.equals(type,NdefRecord.RTD_HANDOVER_SELECT))
        return ctx.getString(R.string.rtd_handover_select);
    else if(Arrays.equals(type,NdefRecord.RTD_SMART_POSTER))
        return ctx.getString(R.string.rtd_smart_poster);
    else if(Arrays.equals(type,NdefRecord.RTD_TEXT))
        return ctx.getString(R.string.rtd_text);
    else if (record.getTnf() == NdefRecord.TNF_MIME_MEDIA)
        return new String(type);
    else
        return ByteUtils.bytesToHex(type);
}
 
開發者ID:TapTrack,項目名稱:TappyBLE,代碼行數:21,代碼來源:TcmpMessageDescriptor.java

示例5: toNfcRecord

/**
 * Converts android.nfc.NdefRecord to mojo NfcRecord
 */
private static NfcRecord toNfcRecord(NdefRecord ndefRecord)
        throws UnsupportedEncodingException {
    switch (ndefRecord.getTnf()) {
        case NdefRecord.TNF_EMPTY:
            return createEmptyRecord();
        case NdefRecord.TNF_MIME_MEDIA:
            return createMIMERecord(
                    new String(ndefRecord.getType(), "UTF-8"), ndefRecord.getPayload());
        case NdefRecord.TNF_ABSOLUTE_URI:
            return createURLRecord(ndefRecord.toUri());
        case NdefRecord.TNF_WELL_KNOWN:
            return createWellKnownRecord(ndefRecord);
    }
    return null;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:18,代碼來源:NfcTypeConverter.java

示例6: createMessage

/**
 * Creates a new NdefMessage with payload of text field.
 * @return NFC Data Exchange Format
 */
private NdefMessage createMessage() {
    String mimeType = "application/net.xerael.beam";
    byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII"));

    //GENERATE PAYLOAD
    TextView text = (TextView) findViewById(R.id.text);
    byte[] payLoad = text.getText().toString().getBytes();

    //GENERATE NFC MESSAGE
    return new NdefMessage(
            new NdefRecord[]{
            new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
                    mimeBytes,
                    null,
                    payLoad),
            NdefRecord.createApplicationRecord("net.xerael.beam")
    });
}
 
開發者ID:git-commit,項目名稱:AndroidBeamTest,代碼行數:22,代碼來源:BeamActivity.java

示例7: createNdefMessage

@Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) {

    try {
        String msg = getEncryptedMessage();
        NdefRecord mimeRecord = new NdefRecord(
                NdefRecord.TNF_MIME_MEDIA,
                Const.ARROW_MIME.getBytes(Charset.forName("US-ASCII")),
                new byte[0],
                msg.getBytes(Charset.forName("US-ASCII")));
        NdefMessage message = new NdefMessage(new NdefRecord[]{mimeRecord});
        return message;
    } catch (Exception e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        Toast.makeText(ArrowActivity.this, ArrowActivity.this.getString(R.string.arrow_oops), Toast.LENGTH_LONG).show();
    }
    return null;
}
 
開發者ID:gdgjodhpur,項目名稱:gdgapp,代碼行數:18,代碼來源:ArrowActivity.java

示例8: doInBackground

@Override
protected String doInBackground(Tag... params)
{
    Tag tag = params[0];
    String result;

    mac_cnt = 0;

    Ndef ndef = Ndef.get(tag);

    if (ndef == null)
    {
        return null;
    }

    NdefMessage ndefMessage = ndef.getCachedNdefMessage();

    NdefRecord[] records = ndefMessage.getRecords();

    for (NdefRecord record : records) {
        if (record.getTnf() == NdefRecord.TNF_MIME_MEDIA) {
            /* Read the NFC Tags payload */
            readText(record);
        }
    }
    result = "OK";

    return result;
}
 
開發者ID:AinaWireless,項目名稱:PairingExample,代碼行數:29,代碼來源:MainActivity.java

示例9: getAsNdef

/**
 * Converts a Long into a NdefMessage in application/vnd.facebook.places MIMEtype.
 * <p/>
 * for writing Places
 */
public static NdefMessage getAsNdef(String content) {
    byte[] textBytes = content.getBytes();
    NdefRecord textRecord = new NdefRecord(
            NdefRecord.TNF_MIME_MEDIA,
            "application/eu.power_switch".getBytes(),
            new byte[]{},
            textBytes);
    return new NdefMessage(new NdefRecord[]{
            textRecord,
            NdefRecord.createApplicationRecord("eu.power_switch")});
}
 
開發者ID:Power-Switch,項目名稱:PowerSwitch_Android,代碼行數:16,代碼來源:NfcHandler.java

示例10: writeTag

public static boolean writeTag(Intent intent, String msg) {
    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    byte[] textBytes = msg.getBytes();
    NdefRecord textRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
            "application/vnd.kornkammer.products".getBytes(), new byte[] {}, textBytes);
    NdefMessage m = new NdefMessage(new NdefRecord[]{ textRecord });
    return writeTag(m, tag);
}
 
開發者ID:Kornkammer,項目名稱:foodcoapp,代碼行數:8,代碼來源:Nfc.java

示例11: createNdefMessage

/**
 * Callback message that will be called on NFC activity and creates an NFC
 * message containing our identity to be send out
 */
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
	Log.v(TAG, "createNdefMessage()");

	AbstractIdentity idToSend = panbox.getIdentity();

	Log.v(TAG, "identity null? " + idToSend);

	if (idToSend == null) {
		return null;
	}

	ByteArrayOutputStream baos = new ByteArrayOutputStream();

	AbstractIdentityManager idm = IdentityManagerAndroid
			.getInstance(context);

	idm.exportMyIdentity(idToSend, baos);

	try {
		baos.flush();
		baos.close();
	} catch (IOException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}

	//
	byte[] idFileData = baos.toByteArray();

	NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
			MIME_TYPE.getBytes(Charset.forName("US-ASCII")), new byte[0],
			idFileData);
	NdefMessage msg = new NdefMessage(new NdefRecord[] { record });

	return msg;
}
 
開發者ID:Rohde-Schwarz-Cybersecurity,項目名稱:PanBox,代碼行數:41,代碼來源:CustomActionBarActivity.java

示例12: doInBackground

@Override
protected String doInBackground(Tag... params)
{
    Tag tag = params[0];

    Ndef ndef = Ndef.get(tag);
    if (ndef == null)
    {
        // NDEF is not supported by this Tag.
        return null;
    }

    NdefMessage ndefMessage = ndef.getCachedNdefMessage();

    NdefRecord[] records = ndefMessage.getRecords();
    for (NdefRecord ndefRecord : records)
    {
        if (ndefRecord.getTnf() == NdefRecord.TNF_MIME_MEDIA)
        {
            try
            {
                return readText(ndefRecord);
            }
            catch (UnsupportedEncodingException e)
            {
                Log.e(LOGGER_TAG, "Unsupported Encoding", e);
            }
        }
    }

    return null;
}
 
開發者ID:mofosyne,項目名稱:NFCMessageBoard,代碼行數:32,代碼來源:ReadHtmlTags.java

示例13: createNdefMessage

@Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) {

    String mimeType = "application/com.coursera.cardswap";
    byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII"));

    //encapsulate the data in an array of NdefRecords
    NdefRecord[] ndefRecord = new NdefRecord[]{

            // each NdefRecord has to have a tnf, type, id, and payload.
            // the tnf specifies what the data will be which we specify as a MIME.
            // the type is what the intent filter (in the manifest) for an activity will look for.
            // We give a default byte for the id. And the payload is the data in bytes.
            new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], personName.getBytes()),
            new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], business.getBytes()),
            new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], address.getBytes()),
            new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], cityStateZip.getBytes()),
            new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], number.getBytes()),
            new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], email.getBytes()),
            new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], website.getBytes()),

            // this creates the application record for this app, which takes the user to this app
            // in the google play store, if when the NFC happens, the receiving phone doesn't have
            // this app installed
            NdefRecord.createApplicationRecord("com.coursera.cardswap")
    };

    //An NdefMessage is what gets sent in the NFC and we pass the array of our NdefRecords
    //to encapsulate it in the NdefMessage
    return new NdefMessage(ndefRecord);
}
 
開發者ID:vdisawar,項目名稱:CardSwap,代碼行數:31,代碼來源:CardSwap.java

示例14: getNdefRecord

@Override
public NdefRecord getNdefRecord() {
	if(!hasMimeType()) {
		throw new IllegalArgumentException("Expected content type");
	}

	// the android api normalizes the content type, I dont see why you would want that
	return new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeType.getBytes(Charset.forName("US-ASCII")), id != null ? id : EMPTY, data != null ? data : EMPTY);
}
 
開發者ID:kemerelab,項目名稱:RodentDBS,代碼行數:9,代碼來源:MimeRecord.java

示例15: createNdefMessage

@Override
public NdefMessage createNdefMessage(NfcEvent arg0) {
	String payload = getIntent().getStringExtra("price");
	String mimeType = "application/com.touch.pay";
	byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII"));

	// create an NdefRecord that holds the data payload to transfer to
	// target phone
	NdefRecord[] record = new NdefRecord[] {
			new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, // the type
																	// of
																	// the
																	// data
					new byte[0], // the ID of the payload
					payload.getBytes()), // the payload in byte array
			// TODO add tokens for extra payload
					
			// create the android application record to go to play store if
			// user doesn't have app
			NdefRecord.createApplicationRecord("com.touch.pay")

	};

	// encapsulate data in message object
	NdefMessage message = new NdefMessage(record);
	return message;
}
 
開發者ID:vdisawar,項目名稱:TouchPay,代碼行數:27,代碼來源:TransferActivity.java


注:本文中的android.nfc.NdefRecord.TNF_MIME_MEDIA屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。