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


Java NdefRecord.createMime方法代碼示例

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


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

示例1: createNdefMessage

import android.nfc.NdefRecord; //導入方法依賴的package包/類
/**
 * Implementation for the CreateNdefMessageCallback interface
 */
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    Time time = new Time();
    time.setToNow();
    String text = ("Beam me up!\n\n" +
            "Beam Time: " + time.format("%H:%M:%S"));
    NdefMessage msg = new NdefMessage(NdefRecord.createMime(
            "application/com.example.android.beam", text.getBytes())
     /**
      * The Android Application Record (AAR) is commented out. When a device
      * receives a push with an AAR in it, the application specified in the AAR
      * is guaranteed to run. The AAR overrides the tag dispatch system.
      * You can add it back in to guarantee that this
      * activity starts when receiving a beamed message. For now, this code
      * uses the tag dispatch system.
      */
      //,NdefRecord.createApplicationRecord("com.example.android.beam")
    );
    return msg;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:24,代碼來源:Beam.java

示例2: writeTAG

import android.nfc.NdefRecord; //導入方法依賴的package包/類
protected void writeTAG(Tag tag) throws IOException, FormatException {
    Ndef ndefTag = Ndef.get(tag);
    byte[] stringBytes = passphrase.getBytes();

    NdefRecord data = NdefRecord.createMime(CONST.NFC_MIME_LOGIN, stringBytes);
    NdefMessage message = new NdefMessage(data);

    if (ndefTag != null) { //write to formatted tag
        ndefTag.connect();
        ndefTag.writeNdefMessage(message);
    } else { //format the tag
        NdefFormatable format = NdefFormatable.get(tag);
        if(format != null) {
            format.connect();
            format.format(message);
        }
    }
}
 
開發者ID:gtom1984,項目名稱:Eulen,代碼行數:19,代碼來源:nfctagbase.java

示例3: writeToNfc

import android.nfc.NdefRecord; //導入方法依賴的package包/類
private void writeToNfc(Ndef ndef, String message){

        mTvMessage.setText(getString(R.string.message_write_progress));
        if (ndef != null) {

            try {
                ndef.connect();
                NdefRecord mimeRecord = NdefRecord.createMime("text/plain", message.getBytes(Charset.forName("US-ASCII")));
                ndef.writeNdefMessage(new NdefMessage(mimeRecord));
                ndef.close();
                //Write Successful
                mTvMessage.setText(getString(R.string.message_write_success));

            } catch (IOException | FormatException e) {
                e.printStackTrace();
                mTvMessage.setText(getString(R.string.message_write_error));

            } finally {
                mProgress.setVisibility(View.GONE);
            }

        }
    }
 
開發者ID:Learn2Crack,項目名稱:android-nfc-tag-read-write,代碼行數:24,代碼來源:NFCWriteFragment.java

示例4: createNdefMessage

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    return new NdefMessage(
            new NdefRecord[] { NdefRecord.createMime(
                    "application/vnd.co.loubo.icicle", this.encodedNodeRef.getBytes(Charset.forName("US-ASCII")))
                    /**
                     * The Android Application Record (AAR) is commented out. When a device
                     * receives a push with an AAR in it, the application specified in the AAR
                     * is guaranteed to run. The AAR overrides the tag dispatch system.
                     * You can add it back in to guarantee that this
                     * activity starts when receiving a beamed message. For now, this code
                     * uses the tag dispatch system.
                     */
                    //,NdefRecord.createApplicationRecord("com.example.android.beam")
            });
}
 
開發者ID:louboco,項目名稱:Icicle,代碼行數:17,代碼來源:OpenReferenceActivity.java

示例5: toNdefRecord

import android.nfc.NdefRecord; //導入方法依賴的package包/類
/**
 * Converts mojo NfcRecord to android.nfc.NdefRecord
 */
private static NdefRecord toNdefRecord(NfcRecord record) throws InvalidNfcMessageException,
                                                                IllegalArgumentException,
                                                                UnsupportedEncodingException {
    switch (record.recordType) {
        case NfcRecordType.URL:
            return NdefRecord.createUri(new String(record.data, getCharset(record)));
        case NfcRecordType.TEXT:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                return NdefRecord.createTextRecord(
                        "en-US", new String(record.data, getCharset(record)));
            } else {
                return NdefRecord.createMime(TEXT_MIME, record.data);
            }
        case NfcRecordType.JSON:
        case NfcRecordType.OPAQUE_RECORD:
            return NdefRecord.createMime(record.mediaType, record.data);
        default:
            throw new InvalidNfcMessageException();
    }
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:24,代碼來源:NfcTypeConverter.java

示例6: doInBackground

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@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;
  }
  try {
    NdefMessage msg = new NdefMessage(
        new NdefRecord[] { NdefRecord.createMime(
            "application/pubk.com.sawyer.easypgp", publicKeyBytes) });
    ndef.connect();
    ndef.writeNdefMessage(msg);
    ndef.close();
    return "Success";
  } catch (Exception e) {
    e.printStackTrace();
  }

  return null;
}
 
開發者ID:masstamike,項目名稱:easypgp,代碼行數:24,代碼來源:NfcActivity.java

示例7: finish

import android.nfc.NdefRecord; //導入方法依賴的package包/類
public void finish() {
    try {
        //store userID and query in JSON
        JSONArray jsonArray = new JSONArray(Arrays.asList(values));
        jsonArray.put(userID);

        //convert JSON to byte form
        byte[] jsonToByte = jsonArray.toString().getBytes(); //convert json to bytes

        //compress JSON
        try {
            //build simple NDEF record for transmission
            ndefMessage = new NdefMessage(NdefRecord.createMime(CONST.NFC_MIME_BEAM, jsonToByte));

            //flip flags for local use
            for(int c = 5; c <= values.length; c = c + 3) {
                if(values[c].equals("1")) {
                    values[c] = "2";
                } else if(values[c].equals("2")) {
                    values[c] = "1";
                }
            }
        } catch (Exception e) {
            // do nothing
        }
    } catch (Exception je) {
        // do nothing
    }
}
 
開發者ID:gtom1984,項目名稱:Eulen,代碼行數:30,代碼來源:KeyOTP.java

示例8: createNdefMessage

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public NdefMessage createNdefMessage(final NfcEvent event) {
	final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	final Properties properties = new Properties();

	properties.put(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, "com.example.deviceowner");

	// Make sure to put local time in the properties. This is necessary on some devices to
	// reliably download the device owner APK from an HTTPS connection.
	properties.put(
			DevicePolicyManager.EXTRA_PROVISIONING_LOCAL_TIME,
			String.valueOf(System.currentTimeMillis())
	);
	// To calculate checksum execute command (taken from http://stackoverflow.com/questions/26509770/checksum-error-while-provisioning-android-lollipop):
	// cat Something.apk | openssl dgst -binary -sha1 | openssl base64 | tr '+/' '-_' | tr -d '='
	properties.put(
			DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM,
			"[Device owner app checksum]"
	);
	properties.put(
			DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION,
			"[Device owner app URL]"
	);

	try {
		properties.store(outputStream, getString(R.string.nfc_comment));
		final NdefRecord record = NdefRecord.createMime(
				DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC,
				outputStream.toByteArray()
		);

		return new NdefMessage(new NdefRecord[]{record});
	} catch (final IOException e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:raynor73,項目名稱:NfcProvisioning,代碼行數:37,代碼來源:MainActivity.java

示例9: onNewIntent

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
protected void onNewIntent(Intent intent) {
    if (writeMode &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN &&
            NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
        Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        NdefRecord record = NdefRecord.createMime(this.tag.getMimeType(), this.tag.getMessage().getBytes());
        NdefMessage message = new NdefMessage(new NdefRecord[] { record });
        if (writeTag(message, detectedTag)) {
            tagWritten = true;
        }
    }
}
 
開發者ID:pfiorentino,項目名稱:eCarNet,代碼行數:14,代碼來源:WriteTagActivity.java

示例10: createNdefMessage

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
	NdefMessage msg = new NdefMessage(new NdefRecord[] {
		NdefRecord.createMime("application/vnd.org.pyneo.android.sample", uri.getBytes()),
		NdefRecord.createUri(uri),
		NdefRecord.createApplicationRecord("org.pyneo.android.gui"),
		});
	return msg;
}
 
開發者ID:emdete,項目名稱:Simplicissimus,代碼行數:10,代碼來源:Sample.java

示例11: createNdefMessage

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
    if (beamUri == null || beamUri.isEmpty()) {
        return null;
    } else {
        return new NdefMessage(new NdefRecord[]{NdefRecord.createMime("application/vnd.com.thebluealliance.androidclient", beamUri.getBytes())});
    }
}
 
開發者ID:the-blue-alliance,項目名稱:the-blue-alliance-android,代碼行數:10,代碼來源:BaseActivity.java

示例12: createNdefMessage

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
	try {
		Properties p = new Properties();

		p.setProperty(
				DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
				"com.randygroff.deviceownercheck");
		p.setProperty(
				DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION,
				"https://storage.googleapis.com/randy/DeviceOwnerCheck.apk");
		p.setProperty(
				DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM,
				"FRaAsqdPSjp9nC5hKIU/ElPv+e4");

		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		OutputStream out = new ObjectOutputStream(bos);
		p.store(out, "");
		final byte[] bytes = bos.toByteArray();
		
		h.post(new Runnable() {
			@Override
			public void run() {
				TextView tv = (TextView) findViewById(R.id.nfc_message);
				tv.setText(new String(bytes));
			}
		});
		
		NdefMessage msg = new NdefMessage(NdefRecord.createMime(
				DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, bytes));
		return msg;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:rg1220,項目名稱:AndroidProvisioningTest,代碼行數:36,代碼來源:MainActivity.java

示例13: createNdefMessage

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    // Get the current contact URI
    Uri contactUri = mContactFragment.getUri();
    ContentResolver resolver = mContactFragment.getActivity().getContentResolver();
    if (contactUri != null) {
        long rawContactId = ContentUris.parseId(contactUri);
        Uri shareUri = ContentUris.withAppendedId(RawContacts.CONTENT_VCARD_URI, rawContactId);
        shareUri = shareUri.buildUpon().appendQueryParameter(RawContacts.QUERY_PARAMETER_VCARD_NO_PHOTO, "true").build();

        ByteArrayOutputStream ndefBytes = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int r;
        try {
            InputStream vcardInputStream = resolver.openInputStream(shareUri);
            while ((r = vcardInputStream.read(buffer)) > 0) {
                ndefBytes.write(buffer, 0, r);
            }
            NdefRecord record = NdefRecord.createMime(RawContacts.CONTENT_VCARD_TYPE, ndefBytes.toByteArray());
            return new NdefMessage(record);
        }
        catch (IOException e) {
            Log.e(TAG, "IOException creating vcard.");
            return null;
        }
    }
    else {
        Log.w(TAG, "No contact URI to share.");
        return null;
    }
}
 
開發者ID:SilentCircle,項目名稱:silent-contacts-android,代碼行數:32,代碼來源:NfcHandler.java

示例14: onCreate

import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_client);

    status = (TextView) findViewById(R.id.status);

    TextView macAddress = (TextView) findViewById(R.id.mac_address);
    macAddress.setText(GameSetupManager.getInstance().getAddress());

    Button name_button = (Button) findViewById(R.id.change_name_button);
    name_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Client.this);
            final EditText name = new EditText(getApplicationContext());
            builder.setView(name);
            builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Match.getInstance().getYou().setNickname(name.getText().toString());
                }
            });
            builder.setNegativeButton("Cancel", null);
            builder.create().show();
        }
    });
    GameSetupManager.getInstance().startListening();

    status.setText("Listening");

    mPlayerList = (ListView) findViewById(R.id.bluetooth_device_list);
    mDeviceAdapter = new DeviceAdapter(this, 0, Match.getInstance().getPlayerList());
    mPlayerList.setAdapter(mDeviceAdapter);

    NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    try {
        NdefMessage msg = new NdefMessage(new NdefRecord[]{
                NdefRecord.createMime("tenebris/player", GameSetupManager.getInstance().getAddress().getBytes())
        });
        mNfcAdapter.setNdefPushMessage(msg, this);
    } catch (Exception e) {
        e.printStackTrace();
    }

    GameSetupManager.getInstance().setHostStatusListener(this);
}
 
開發者ID:xbhatnag,項目名稱:Tenebris,代碼行數:49,代碼來源:Client.java

示例15: encode

import android.nfc.NdefRecord; //導入方法依賴的package包/類
public NdefMessage encode() {
    this.record = NdefRecord.createMime(this.type.toLowerCase(), this.data.getBytes());
    return new NdefMessage(new NdefRecord[] { this.record });
}
 
開發者ID:wesleydebruijn,項目名稱:android-nfc-wrapper,代碼行數:5,代碼來源:NFCTag.java


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