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


Java NdefRecord.createUri方法代碼示例

本文整理匯總了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.");
    }
}
 
開發者ID:appledong,項目名稱:AndroidthingsStudy,代碼行數:20,代碼來源:ForegroundNdefPush.java

示例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();
            }
        }
    }
 
開發者ID:vojta-horanek,項目名稱:APKMirror,代碼行數:17,代碼來源:MainActivity.java

示例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();
    }
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:24,代碼來源:NfcTypeConverter.java

示例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.");
    }
}
 
開發者ID:luoqii,項目名稱:ApkLauncher,代碼行數:20,代碼來源:ForegroundNdefPush.java

示例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;
}
 
開發者ID:Blaubot,項目名稱:Blaubot,代碼行數:18,代碼來源:BlaubotNFCBeacon.java

示例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;
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:9,代碼來源:WalletAddressFragment.java

示例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;
}
 
開發者ID:ccrama,項目名稱:Slide,代碼行數:10,代碼來源:BaseActivity.java

示例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);
	}
}
 
開發者ID:kemerelab,項目名稱:RodentDBS,代碼行數:13,代碼來源:UriRecord.java

示例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;
}
 
開發者ID:emdete,項目名稱:Simplicissimus,代碼行數:10,代碼來源:Sample.java

示例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) {
    }
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:49,代碼來源:RunUrlActivity.java

示例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)});
}
 
開發者ID:GuepardoApps,項目名稱:library_GuepardoAppsToolSet,代碼行數:6,代碼來源:NFCController.java

示例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();
	}
}
 
開發者ID:ZhaoYukai,項目名稱:NFCApp2,代碼行數:47,代碼來源:AutoOpenUriActivity.java

示例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();
            }
        });
    }
}
 
開發者ID:swandroid,項目名稱:swan-sense-studio,代碼行數:47,代碼來源:SwanLakeActivity.java

示例14: createUriRecord

import android.nfc.NdefRecord; //導入方法依賴的package包/類
private NdefRecord createUriRecord(String url) {
    return NdefRecord.createUri(url);
}
 
開發者ID:hatena-iti,項目名稱:MyNFCWriter,代碼行數:4,代碼來源:NfcWriter.java

示例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();
			}
		});
	}
}
 
開發者ID:nadinasovaiala,項目名稱:swan_sense_integration,代碼行數:47,代碼來源:SwanLakeActivity.java


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