当前位置: 首页>>代码示例>>Java>>正文


Java Message类代码示例

本文整理汇总了Java中org.ndeftools.Message的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Message类属于org.ndeftools包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ndefWrite

import org.ndeftools.Message; //导入依赖的package包/类
private void ndefWrite() {
	Log.d(TAG, "NDEF write");
	
	Message message = new Message();
	
	UriRecord record = new UriRecord();
	record.setUri(Uri.parse("https://github.com/skjolber/external-nfc-api"));
	
	message.add(record);
	
	try {
		ndef.connect();
		
		ndef.writeNdefMessage(message.getNdefMessage());
		
		ndef.close();
	} catch (Exception e) {
		Log.d(TAG, "Problem writing NDEF message", e);
	}
}
 
开发者ID:skjolber,项目名称:external-nfc-api,代码行数:21,代码来源:MainActivity.java

示例2: ndefFormat

import org.ndeftools.Message; //导入依赖的package包/类
private void ndefFormat() {
	Log.d(TAG, "NDEF format write");
	
	Message message = new Message();
	
	UriRecord record = new UriRecord();
	record.setUri(Uri.parse("https://github.com/skjolber/external-nfc-api"));
	
	message.add(record);
	
	try {
		ndefFormatable.connect();
		
		ndefFormatable.format(message.getNdefMessage());
		
		ndefFormatable.close();
	} catch (Exception e) {
		Log.d(TAG, "Problem writing NDEF message", e);
	}
}
 
开发者ID:skjolber,项目名称:external-nfc-api,代码行数:21,代码来源:MainActivity.java

示例3: showRecords

import org.ndeftools.Message; //导入依赖的package包/类
/**
 * 
 * Show NDEF records in the list
 * 
 */

private void showRecords(Message message) {
	// display the message in the gui
	
	ListView listView = (ListView) findViewById(R.id.recordListView);
	View ndefRecords = findViewById(R.id.ndefRecords);
	if(message != null && !message.isEmpty()) {
		Log.d(TAG, "Show " + message.size() + " records");

		ArrayAdapter<? extends Object> adapter = new NdefRecordAdapter(this, message);
		listView.setAdapter(adapter);
		listView.setVisibility(View.VISIBLE);
		
		ndefRecords.setVisibility(View.VISIBLE);
	} else {
		listView.setVisibility(View.GONE);
		
		ndefRecords.setVisibility(View.GONE);
	}
	
}
 
开发者ID:skjolber,项目名称:external-nfc-api,代码行数:27,代码来源:MainActivity.java

示例4: createNdefMessage

import org.ndeftools.Message; //导入依赖的package包/类
@Override
protected NdefMessage createNdefMessage() {
    // Create the NDEF message to be written when a tag is within range.
    Message message = new Message();

    // add an External type Record with the proper message
    String domain = "rnel.rice.edu";
    String externalRecordType = "rsm";

    byte[] byteDomain = domain.getBytes(Charset.forName("UTF-8"));
    byte[] byteType = externalRecordType.getBytes(Charset.forName("UTF-8"));
    byte[] b = new byte[byteDomain.length + 1 + byteType.length];
    System.arraycopy(byteDomain, 0, b, 0, byteDomain.length);
    b[byteDomain.length] = ':';
    System.arraycopy(byteType, 0, b, byteDomain.length + 1, byteType.length);

    byte[] EMPTY = new byte[]{};

    // external type id must be empty
    //NdefRecord record =  new NdefRecord(NdefRecord.TNF_EXTERNAL_TYPE, b, EMPTY, NDEFData);
    GenericExternalTypeRecord record = new GenericExternalTypeRecord(domain, externalRecordType, NDEFData);
    message.add(record);

    return message.getNdefMessage();
}
 
开发者ID:kemerelab,项目名称:RodentDBS,代码行数:26,代码来源:NFCWriteActivity.java

示例5: parseNdefRecord

import org.ndeftools.Message; //导入依赖的package包/类
public static SmartPosterRecord parseNdefRecord(NdefRecord ndefRecord) throws FormatException {
	byte[] payload = ndefRecord.getPayload();

	normalizeMessageBeginEnd(payload);

	SmartPosterRecord smartPosterRecord = new SmartPosterRecord();
	
	if(payload.length > 0) {
		List<Record> records = Message.parseNdefMessage(payload);

		for (Record record : records) {
			if (record instanceof UriRecord) {
				smartPosterRecord.setUri((UriRecord)record);
			}
			else if (record instanceof TextRecord) {
				smartPosterRecord.setTitle((TextRecord)record);
			}
			else if (record instanceof ActionRecord) {
				smartPosterRecord.setAction((ActionRecord)record);
			}
		}
	}
	return smartPosterRecord;
	
}
 
开发者ID:kemerelab,项目名称:RodentDBS,代码行数:26,代码来源:SmartPosterRecord.java

示例6: getNdefRecord

import org.ndeftools.Message; //导入依赖的package包/类
@Override
public NdefRecord getNdefRecord() {
	Message message = new Message();
	if (hasTitle()) {
		message.add(title);
	}
	if (hasUri()) {
		message.add(uri);
	}
	if (hasAction()) {
		message.add(action);
	}
	
	return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_SMART_POSTER, id != null ? id : EMPTY, message.getNdefMessage().toByteArray());
	
}
 
开发者ID:kemerelab,项目名称:RodentDBS,代码行数:17,代码来源:SmartPosterRecord.java

示例7: createNdefMessage

import org.ndeftools.Message; //导入依赖的package包/类
/**
 * 
 * Implementation of {@link CreateNdefMessageCallback} interface.
 * 
 * This method is called when another device is within reach (communication is to take place).
 */

@Override
public NdefMessage createNdefMessage(NfcEvent event) {
	Log.d(TAG, "Create message to be beamed");
	
	// create message to be pushed, for example
	Message message = new Message();
	// add text record
	message.add(new TextRecord("This is my beam text record"));
	// add 'my' external type record
	message.add(new GenericExternalTypeRecord("my.domain", "atype", "My data".getBytes(Charset.forName("UTF-8"))));
				
	// encode to NdefMessage, will be pushed via beam (now!) (unless there is a collision)
	return message.getNdefMessage();
}
 
开发者ID:javawolfpack,项目名称:CSCI567---Workspace,代码行数:22,代码来源:DefaultNfcBeamWriterActivity.java

示例8: createNdefMessage

import org.ndeftools.Message; //导入依赖的package包/类
/**
 * Create an NDEF message to be written when a tag is within range.
 *
 * @return the message to be written
 */

@Override
protected NdefMessage createNdefMessage() {

    // compose our own message
    Message message = new Message();

    if (uuid != null) {
        // add a Text Record with the message which is entered
        MimeRecord textRecord = new MimeRecord();
        textRecord.setMimeType("application/oly.netpowerctrl");
        textRecord.setData(uuid.toString().getBytes());
        message.add(textRecord);
    }

    // add an Android Application Record so that this app is launches if a tag is scanned :-)
    AndroidApplicationRecord androidApplicationRecord = new AndroidApplicationRecord();
    androidApplicationRecord.setPackageName(getPlayIdentifier());
    message.add(androidApplicationRecord);

    return message.getNdefMessage();
}
 
开发者ID:davidgraeff,项目名称:Android-NetPowerctrl,代码行数:28,代码来源:NfcTagWriterActivity.java

示例9: readNdefMessage

import org.ndeftools.Message; //导入依赖的package包/类
/**
 * An NDEF message was read and parsed. This method prints its contents to log and then shows its contents in the GUI.
 *
 * @param message the message
 */

@Override
public void readNdefMessage(Message message) {
    if (message.size() > 1) {
        toast(getString(R.string.readMultipleRecordNDEFMessage));
    } else {
        Record record = message.get(0);
        if (record instanceof ExternalTypeRecord) {
            String domain = ((ExternalTypeRecord) record).getDomain();
            String recordType = ((ExternalTypeRecord) record).getType();
            if ((((ExternalTypeRecord) record).getDomain().equals("rnel.rice.edu")) &&
                    (((ExternalTypeRecord) record).getType().equals("rsm"))) {
                RSMDevice device = new RSMDevice(((ExternalTypeRecord) record).getData());
                if (device.isValid == true) {
                    toast(getString(R.string.readRSMNDEFMessage));
                    rsmDevice = device;
                    updateDeviceDisplay();
                } else {
                    toast(getString(R.string.readRSMMessageError));
                }
            }
            else {
                toast(getString(R.string.readExternalRecordNDEFMessage));
            }
        }
        else {
            toast(getString(R.string.readSingleRecordNDEFMessage));
        }
    }

}
 
开发者ID:kemerelab,项目名称:RodentDBS,代码行数:37,代码来源:MainActivity.java

示例10: nfcIntentDetected

import org.ndeftools.Message; //导入依赖的package包/类
@Override
public void nfcIntentDetected(Intent intent, String action) {
	Log.d(TAG, "nfcIntentDetected: " + action);
	
	Parcelable[] messages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
	if (messages != null) {
		NdefMessage[] ndefMessages = new NdefMessage[messages.length];
	    for (int i = 0; i < messages.length; i++) {
	        ndefMessages[i] = (NdefMessage) messages[i];
	    }
	    
	    if(ndefMessages.length > 0) {
	    	// read as much as possible
			Message message = new Message();
			for (int i = 0; i < messages.length; i++) {
		    	NdefMessage ndefMessage = (NdefMessage) messages[i];
		        
				for(NdefRecord ndefRecord : ndefMessage.getRecords()) {
					try {
						message.add(Record.parse(ndefRecord));
					} catch (FormatException e) {
						// if the record is unsupported or corrupted, keep as unsupported record
						message.add(UnsupportedRecord.parse(ndefRecord));
					}
				}
		    }
			readNdefMessage(message);
	    } else {
	    	readEmptyNdefMessage();
	    }
	} else  {
		readNonNdefMessage();
	}
}
 
开发者ID:kemerelab,项目名称:RodentDBS,代码行数:35,代码来源:NfcReaderActivity.java

示例11: parseNdefRecord

import org.ndeftools.Message; //导入依赖的package包/类
public static HandoverRequestRecord parseNdefRecord(NdefRecord ndefRecord) throws FormatException {
	byte[] payload = ndefRecord.getPayload();
	
	HandoverRequestRecord handoverRequestRecord = new HandoverRequestRecord();

	byte minorVersion = (byte)(payload[0] & 0x0F);
	byte majorVersion = (byte)((payload[0] >> 4) & 0x0F);

	handoverRequestRecord.setMinorVersion(minorVersion);
	handoverRequestRecord.setMajorVersion(majorVersion);

	normalizeMessageBeginEnd(payload, 1, payload.length -1);

	List<Record> records = Message.parseNdefMessage(payload, 1, payload.length -1);

	if (records.isEmpty()) {
		throw new IllegalArgumentException(
				"Expected collision resolution record and at least one alternative carrier");
	}

	for (int i = 0; i < records.size(); i++) {
		Record record = records.get(i);
		if (record instanceof CollisionResolutionRecord) {
			handoverRequestRecord.setCollisionResolution((CollisionResolutionRecord)record);
		}
		else if (record instanceof AlternativeCarrierRecord)
			handoverRequestRecord.add((AlternativeCarrierRecord)records.get(i));
		// An implementation SHALL silently ignore and SHALL NOT raise an error 
		// if it encounters other unknown record types.
	}

	if (handoverRequestRecord.getAlternativeCarriers().size() == 0)
		throw new IllegalArgumentException("Expected at least one alternative carrier");

	return handoverRequestRecord;
}
 
开发者ID:kemerelab,项目名称:RodentDBS,代码行数:37,代码来源:HandoverRequestRecord.java

示例12: parseNdefRecord

import org.ndeftools.Message; //导入依赖的package包/类
public static GenericControlRecord parseNdefRecord(NdefRecord ndefRecord) throws FormatException {
	byte[] payload = ndefRecord.getPayload();

	normalizeMessageBeginEnd(payload, 1, payload.length -1);
	
	Message payloadNdefMessage = Message.parseNdefMessage(payload, 1, payload.length - 1);

	GenericControlRecord genericControlRecord = new GenericControlRecord();
	genericControlRecord.setConfigurationByte(payload[0]);
	
	for (Record record : payloadNdefMessage) {
		if (record instanceof GcTargetRecord) {
			genericControlRecord.setTarget((GcTargetRecord)record);
		} else if (record instanceof GcActionRecord) {
			genericControlRecord.setAction((GcActionRecord)record);
		} else if (record instanceof GcDataRecord) {
			genericControlRecord.setData((GcDataRecord)record);
		} else {
			throw new IllegalArgumentException("Unexpected record " + record.getClass().getName());
		}
	}

	if (!genericControlRecord.hasTarget()) {
		throw new IllegalArgumentException("Expected target record");
	}
	
	return genericControlRecord;
}
 
开发者ID:kemerelab,项目名称:RodentDBS,代码行数:29,代码来源:GenericControlRecord.java

示例13: readNdefMessage

import org.ndeftools.Message; //导入依赖的package包/类
/**
 * An NDEF message was read and parsed. This method prints its contents to log and then shows its contents in the GUI.
 * 
 * @param message the message
 */

@Override
public void readNdefMessage(Message message) {
	if(message.size() > 1) {
        toast(getString(R.string.readMultipleRecordNDEFMessage));
	} else {
        toast(getString(R.string.readSingleRecordNDEFMessage));
	}		
	
	this.message = message;
	
	// process message
	
	// show in log
	if(message != null) {
		// iterate through all records in message
		Log.d(TAG, "Found " + message.size() + " NDEF records");

		for(int k = 0; k < message.size(); k++) {
			Record record = message.get(k);
			
			Log.d(TAG, "Record " + k + " type " + record.getClass().getSimpleName());
			
			// your own code here, for example:
			if(record instanceof MimeRecord) {
				// ..
			} else if(record instanceof ExternalTypeRecord) {
				// ..
			} else if(record instanceof TextRecord) {
				// ..
			} else { // more else
				// ..
			}
		}
	}
	
	// show in gui
	showList();
}
 
开发者ID:javawolfpack,项目名称:CSCI567---Workspace,代码行数:45,代码来源:DefaultNfcReaderActivity.java

示例14: createNdefMessage

import org.ndeftools.Message; //导入依赖的package包/类
/**
 * 
 * Create an NDEF message to be written when a tag is within range.
 * 
 * @return the message to be written
 */

@Override
protected NdefMessage createNdefMessage() {
	Message message = new Message();
	
	TextRecord textRecord = new TextRecord();
	textRecord.setText("This is my text");
	textRecord.setEncoding(Charset.forName("UTF-8"));
	textRecord.setLocale(Locale.ENGLISH);
	
	message.add(textRecord);
	
	return message.getNdefMessage();
}
 
开发者ID:javawolfpack,项目名称:CSCI567---Workspace,代码行数:21,代码来源:DefaultNfcTagWriterActivity.java

示例15: readNdefMessage

import org.ndeftools.Message; //导入依赖的package包/类
/**
 * An NDEF message was read and parsed
 * 
 * @param message the message
 */

@Override
protected void readNdefMessage(Message message) {
	if(message.size() > 1) {
        toast(getString(R.string.readMultipleRecordNDEFMessage));
	} else {
        toast(getString(R.string.readSingleRecordNDEFMessage));
	}		
}
 
开发者ID:javawolfpack,项目名称:CSCI567---Workspace,代码行数:15,代码来源:DefaultNfcBeamWriterActivity.java


注:本文中的org.ndeftools.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。