本文整理匯總了Java中android.nfc.NdefRecord.createUri方法的典型用法代碼示例。如果您正苦於以下問題:Java NdefRecord.createUri方法的具體用法?Java NdefRecord.createUri怎麽用?Java NdefRecord.createUri使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.nfc.NdefRecord
的用法示例。
在下文中一共展示了NdefRecord.createUri方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
mAdapter = NfcAdapter.getDefaultAdapter(this);
// Create an NDEF message a URL
mMessage = new NdefMessage(NdefRecord.createUri("http://www.android.com"));
setContentView(R.layout.foreground_dispatch);
mText = (TextView) findViewById(R.id.text);
if (mAdapter != null) {
mAdapter.setNdefPushMessage(mMessage, this);
mText.setText("Tap another Android phone with NFC to push a URL");
} else {
mText.setText("This phone is not NFC enabled.");
}
}
示例2: setupNFC
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private void setupNFC(String url) {
if (nfcAdapter != null) { // in case there is no NFC
try {
// create an NDEF message containing the current URL:
NdefRecord rec = NdefRecord.createUri(url); // url: current URL (String or Uri)
NdefMessage ndef = new NdefMessage(rec);
// make it available via Android Beam:
nfcAdapter.setNdefPushMessage(ndef, this, this);
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
}
示例3: 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();
}
}
示例4: onCreate
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
mAdapter = NfcAdapter.getDefaultAdapter(this);
// Create an NDEF message a URL
mMessage = new NdefMessage(NdefRecord.createUri("http://www.android.com"));
setContentView(R.layout.foreground_dispatch);
mText = (TextView) findViewById(R.id.text);
if (mAdapter != null) {
mAdapter.setNdefPushMessage(mMessage, this.getHostActivity());
mText.setText("Tap another Android phone with NFC to push a URL");
} else {
mText.setText("This phone is not NFC enabled.");
}
}
示例5: createNdefMessage
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
if (currentUri == null) { // || !isStarted) ignore ...
if (Log.logErrorMessages()) {
Log.e(LOG_TAG, "I have no URI, can't send NFC message. ");
}
return null; // don't provide a message
}
if (Log.logDebugMessages()) {
Log.d(LOG_TAG, "NFC transaction is taking place ...");
}
NdefMessage msg = new NdefMessage(
new NdefRecord[]{
NdefRecord.createUri(currentUri)
});
return msg;
}
示例6: createNdefMessage
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public NdefMessage createNdefMessage(final NfcEvent event) {
final String uri = currentAddressUriRef.get();
if (uri != null)
return new NdefMessage(new NdefRecord[] { NdefRecord.createUri(uri) });
else
return null;
}
示例7: createNdefMessage
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
if (shareUrl != null) {
return new NdefMessage(new NdefRecord[]{
NdefRecord.createUri(shareUrl)
});
}
return null;
}
示例8: getNdefRecord
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
@SuppressLint("NewApi")
public NdefRecord getNdefRecord() {
if(!hasUri()) {
throw new IllegalArgumentException("Expected URI");
}
if (android.os.Build.VERSION.SDK_INT >= 14) {
return NdefRecord.createUri(uri);
} else {
return createUri(uri);
}
}
示例9: 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;
}
示例10: writeNFCTag
import android.nfc.NdefRecord; //導入方法依賴的package包/類
/**
* 往標簽寫數據的方法
*
* @param tag
*/
public void writeNFCTag(Tag tag) {
if (tag == null) {
return;
}
NdefMessage ndefMessage = new NdefMessage(new NdefRecord[]{NdefRecord
.createUri(Uri.parse("http://www.baidu.com"))});
//轉換成字節獲得大小
int size = ndefMessage.toByteArray().length;
try {
//2.判斷NFC標簽的數據類型(通過Ndef.get方法)
Ndef ndef = Ndef.get(tag);
//判斷是否為NDEF標簽
if (ndef != null) {
ndef.connect();
//判斷是否支持可寫
if (!ndef.isWritable()) {
return;
}
//判斷標簽的容量是否夠用
if (ndef.getMaxSize() < size) {
return;
}
//3.寫入數據
ndef.writeNdefMessage(ndefMessage);
Toast.makeText(this, "寫入成功", Toast.LENGTH_SHORT).show();
} else { //當我們買回來的NFC標簽是沒有格式化的,或者沒有分區的執行此步
//Ndef格式類
NdefFormatable format = NdefFormatable.get(tag);
//判斷是否獲得了NdefFormatable對象,有一些標簽是隻讀的或者不允許格式化的
if (format != null) {
//連接
format.connect();
//格式化並將信息寫入標簽
format.format(ndefMessage);
Toast.makeText(this, "寫入成功",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "寫入失敗", Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
}
}
示例11: createNdefMessage
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
_logger.Debug("createNdefMessage NFC");
return new NdefMessage(new NdefRecord[]{NdefRecord.createUri(_url)});
}
示例12: writeNFCTag
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private void writeNFCTag(Tag tag){
if(tag == null){
return;
}
NdefMessage ndefMessage = new NdefMessage( new NdefRecord[]{NdefRecord.createUri(Uri.parse("http://www.baidu.com"))} );
int size = ndefMessage.toByteArray().length;
try {
Ndef ndef = Ndef.get(tag);
//���ж�һ�������ǩ�Dz���NDEF��
if(ndef != null){ //�����NDEF��ʽ��
ndef.connect();
//�����ж������ǩ�Ƿ��ǿ�д��
if( ! ndef.isWritable()){ //����Dz���д�ģ�ֱ�ӾͿ��Խ�����
Toast.makeText(this , "��NFC��ǩ����д!" , Toast.LENGTH_SHORT).show();
return;
}
//�����жϵ�ǰ��ǩ����������Ƿ���װ������Ҫд�����Ϣ
if(ndef.getMaxSize() < size){
Toast.makeText(this , "��NFC��ǩ������д����̫С!" , Toast.LENGTH_SHORT).show();
return;
}
//����Ϊֹ���Ϳ��Է��ĵİѶ���д��NFC��ǩ����
ndef.writeNdefMessage(ndefMessage);
Toast.makeText(this , "NFC��ǩд�����ݳɹ�" , Toast.LENGTH_SHORT).show();
}
else{ //�������NDEF��ʽ��
//���Խ������NDEF��ǩ��ʽ����NDEF��ʽ��
NdefFormatable format = NdefFormatable.get(tag);
//��Ϊ��Щ��ǩ��ֻ���ģ�����������Ҫ�ж�һ��
//���format��Ϊnull����ʾ�����ǩ�ǿ��Խ��ܸ�ʽ����
if(format != null){
format.connect();
format.format(ndefMessage); //ͬʱ����˸�ʽ����д����Ϣ�IJ���
Toast.makeText(this , "NFC��ǩ��ʽ��д��ɹ�" , Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(this , "��NFC��ǩ������ʽ��" , Toast.LENGTH_SHORT).show();
}
}
}
catch (Exception e) {
Toast.makeText(this , "����ȡ��NFC��ǩ" , Toast.LENGTH_SHORT).show();
}
}
示例13: updateNFC
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private void updateNFC() {
String regId = Registry.get(this, Expression.LOCATION_SELF);
if (regId == null) {
Log.d(TAG,
"Not registered with Google Cloud Messaging, cannot share");
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(
SwanLakeActivity.this,
"Not registered with Google Cloud Messaging, cannot share",
Toast.LENGTH_LONG).show();
}
});
return;
}
if (mNfcAdapter != null) {
String userFriendlyName = PreferenceManager
.getDefaultSharedPreferences(SwanLakeActivity.this)
.getString("name", null);
if (userFriendlyName == null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(SwanLakeActivity.this,
"Please set a name for your device",
Toast.LENGTH_SHORT).show();
showDialog(DIALOG_SET_NAME);
}
});
return;
}
NdefRecord data = NdefRecord.createUri("swan://" + userFriendlyName
+ ":" + regId);
NdefMessage message = new NdefMessage(new NdefRecord[]{data});
mNfcAdapter.enableForegroundNdefPush(this, message);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(SwanLakeActivity.this,
"Ready for NFC sharing", Toast.LENGTH_LONG).show();
}
});
}
}
示例14: createUriRecord
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private NdefRecord createUriRecord(String url) {
return NdefRecord.createUri(url);
}
示例15: updateNFC
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private void updateNFC() {
String regId = Registry.get(this, Expression.LOCATION_SELF);
if (regId == null) {
Log.d(TAG,
"Not registered with Google Cloud Messaging, cannot share");
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(
SwanLakeActivity.this,
"Not registered with Google Cloud Messaging, cannot share",
Toast.LENGTH_LONG).show();
}
});
return;
}
if (mNfcAdapter != null) {
String userFriendlyName = PreferenceManager
.getDefaultSharedPreferences(SwanLakeActivity.this)
.getString("name", null);
if (userFriendlyName == null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(SwanLakeActivity.this,
"Please set a name for your device",
Toast.LENGTH_SHORT).show();
showDialog(DIALOG_SET_NAME);
}
});
return;
}
NdefRecord data = NdefRecord.createUri("swan://" + userFriendlyName
+ ":" + regId);
NdefMessage message = new NdefMessage(new NdefRecord[] { data });
mNfcAdapter.enableForegroundNdefPush(this, message);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(SwanLakeActivity.this,
"Ready for NFC sharing", Toast.LENGTH_LONG).show();
}
});
}
}