本文整理汇总了Java中android.nfc.NfcEvent类的典型用法代码示例。如果您正苦于以下问题:Java NfcEvent类的具体用法?Java NfcEvent怎么用?Java NfcEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NfcEvent类属于android.nfc包,在下文中一共展示了NfcEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNdefMessage
import android.nfc.NfcEvent; //导入依赖的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;
}
示例2: onCreate
import android.nfc.NfcEvent; //导入依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cinemas = DBHelper.getInstance(getContext()).getCinemas();
watcher = new Gson().fromJson(getArguments().getString("watcher"), Watcher.class);
nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
if(nfcAdapter != null) {
nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
return new NdefMessage(
new NdefRecord[] {
NdefRecord.createUri(BuildConfig.SERVER_BASE_URL + "w/" + watcher.getID()),
NdefRecord.createApplicationRecord(BuildConfig.APPLICATION_ID)
}
);
}
}, getActivity());
}
}
示例3: registerNfcCallback
import android.nfc.NfcEvent; //导入依赖的package包/类
public void registerNfcCallback(Activity activity) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter != null) {
// Register callback
nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
return new NdefMessage(
new NdefRecord[] {
NdefRecord.createMime(
"application/vnd.com.pgrenaud.android.p2p.beam",
getPeerRepository().encode().getBytes()
)
}
);
}
}, activity);
Log.d("PeerService", "NdefPushMessageCallback registered");
}
}
示例4: setAppDataPushMessageCallbackIfAvailable
import android.nfc.NfcEvent; //导入依赖的package包/类
public static boolean setAppDataPushMessageCallbackIfAvailable(Activity activity, final CreateNfcAppDataCallback callback) {
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity);
if (adapter == null) {
return false;
}
final String packageName = activity.getPackageName();
adapter.setNdefPushMessageCallback(new CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
byte[] appData = callback.createNfcAppData();
if (appData == null) {
return null;
}
NdefRecord[] records = new NdefRecord[] { createMimeRecord("application/" + packageName, appData),
NdefRecord.createApplicationRecord(packageName) };
return new NdefMessage(records);
}
}, activity);
return true;
}
示例5: setAppDataPushMessageCallbackIfAvailable
import android.nfc.NfcEvent; //导入依赖的package包/类
public static boolean setAppDataPushMessageCallbackIfAvailable(Activity activity, final CreateNfcAppDataCallback callback) {
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity);
if (adapter == null) {
return false;
}
final String packageName = activity.getPackageName();
adapter.setNdefPushMessageCallback(new CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
byte[] appData = callback.createNfcAppData();
if (appData == null) {
return null;
}
NdefRecord[] records = new NdefRecord[]{createMimeRecord("application/" + packageName, appData),
NdefRecord.createApplicationRecord(packageName)};
return new NdefMessage(records);
}
}, activity);
return true;
}
示例6: createBeamUris
import android.nfc.NfcEvent; //导入依赖的package包/类
@Override
public Uri[] createBeamUris(NfcEvent event) {
String transferFile = FullscreenActivity.songfilename;
File extDir;
if (FullscreenActivity.whichSongFolder.equals(getString(R.string.mainfoldername))) {
extDir =FullscreenActivity.dir;
} else {
extDir = new File(FullscreenActivity.dir + "/" + FullscreenActivity.whichSongFolder + "/");
}
File requestFile = new File(extDir, transferFile);
boolean b = requestFile.setReadable(true, false);
if (!b) {
// Get a URI for the File and add it to the list of URIs
Uri fileUri = Uri.fromFile(requestFile);
if (fileUri != null) {
mFileUris[0] = fileUri;
} else {
Log.e("My Activity", "No File URI available for file.");
}
return mFileUris;
} else {
return null;
}
}
示例7: setupNfcBeamPush
import android.nfc.NfcEvent; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void setupNfcBeamPush() {
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mAppContext);
if (adapter == null) {
return;
}
if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) {
// Disable beaming
adapter.setNdefPushMessage(null, CameraActivity.this);
return;
}
adapter.setBeamPushUris(null, CameraActivity.this);
adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
@Override
public Uri[] createBeamUris(NfcEvent event) {
return mNfcPushUris;
}
}, CameraActivity.this);
}
示例8: createNdefMessage
import android.nfc.NfcEvent; //导入依赖的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")
});
}
示例9: createNdefMessage
import android.nfc.NfcEvent; //导入依赖的package包/类
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
// NFC should be auto granted, but doesn't hurt to check.
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.NFC)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.NFC}, NFC_PERMISSIONS);
}
String url = URLEncoder.encodeBuild(this, currentBuild);
NdefMessage msg = new NdefMessage(
new NdefRecord[] { createMime(
"application/vnd.com.jamieadkins.heistr", url.getBytes())
,NdefRecord.createApplicationRecord("com.jamieadkins.heistr")
});
return msg;
}
示例10: start
import android.nfc.NfcEvent; //导入依赖的package包/类
@Override
public void start() {
if (!nfcAdapter.isEnabled())
{
this.activity.startActivity(new Intent(Settings.ACTION_NFC_SETTINGS));
return;
}
this.nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
byte[] payload = new byte[Preferences.getInstance().getPayloadSize()];
Arrays.fill(payload, (byte) 1);
return new NdefMessage(
new NdefRecord[] { NdefRecord.createMime(
MIMETYPE, payload)
});
}
},this.activity);
}
示例11: setupNfcBeamPush
import android.nfc.NfcEvent; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void setupNfcBeamPush() {
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(CameraActivity.this);
if (adapter == null) {
return;
}
if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) {
// Disable beaming
adapter.setNdefPushMessage(null, CameraActivity.this);
return;
}
adapter.setBeamPushUris(null, CameraActivity.this);
adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
@Override
public Uri[] createBeamUris(NfcEvent event) {
return mNfcPushUris;
}
}, CameraActivity.this);
}
示例12: createNdefMessage
import android.nfc.NfcEvent; //导入依赖的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;
}
示例13: initNFC
import android.nfc.NfcEvent; //导入依赖的package包/类
private void initNFC() {
NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (mNfcAdapter == null) {
return;
}
mNfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
String text = (GlobalContext.getInstance().getCurrentAccountName());
NdefMessage msg = new NdefMessage(
new NdefRecord[]{createMimeRecord(
"application/org.qii.weiciyuan.beam", text.getBytes()), NdefRecord.createApplicationRecord(getPackageName())
});
return msg;
}
}, this);
}
示例14: setAppDataPushMessageCallbackIfAvailable
import android.nfc.NfcEvent; //导入依赖的package包/类
/**
* Call this method in an Activity, between onCreate() and onDestroy(), to make its content sharable using Android Beam if available. MIME type of the data
* to share will be "application/" followed by the app's package name. Declare it in your Manifest's intent filters as the data type with an action of
* android.nfc.action.NDEF_DISCOVERED to handle the NFC Intents on the receiver side.
*
* @return true if NFC is available and the content was made available, false if not.
*/
public static boolean setAppDataPushMessageCallbackIfAvailable(Activity activity, final CreateNfcAppDataCallback callback) {
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity);
if (adapter == null) {
return false;
}
final String packageName = activity.getPackageName();
adapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
byte[] appData = callback.createNfcAppData();
if (appData == null) {
return null;
}
NdefRecord[] records = new NdefRecord[]{createMimeRecord("application/" + packageName, appData),
NdefRecord.createApplicationRecord(packageName)};
return new NdefMessage(records);
}
}, activity);
return true;
}
示例15: activateNFCSharing
import android.nfc.NfcEvent; //导入依赖的package包/类
@SuppressLint("NewApi")
public void activateNFCSharing(Activity activity) {
if (mShAIReHttpServer != null && mShAIReHttpServer.getRealUrl() != null) {
// NFC
if (android.os.Build.VERSION.SDK_INT > 14) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
if (nfcAdapter != null) {
nfcAdapter.setNdefPushMessageCallback(
new NfcAdapter.CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(
NfcEvent event) {
return new NdefMessage(
new NdefRecord[]{NdefRecord.createUri(Uri
.parse(mShAIReHttpServer
.getRealUrl()))});
}
}, activity);
}
}
}
}