本文整理匯總了Java中android.nfc.NfcAdapter.setNdefPushMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java NfcAdapter.setNdefPushMessage方法的具體用法?Java NfcAdapter.setNdefPushMessage怎麽用?Java NfcAdapter.setNdefPushMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.nfc.NfcAdapter
的用法示例。
在下文中一共展示了NfcAdapter.setNdefPushMessage方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setBeamSessionUri
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
/**
* Sets this activity's Android Beam message to one representing the given session.
*/
public static void setBeamSessionUri(Activity activity, Uri sessionUri) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
if (nfcAdapter == null) {
// No NFC :-(
return;
}
nfcAdapter.setNdefPushMessage(new NdefMessage(
new NdefRecord[]{
new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
ScheduleContract.makeContentItemType(
ScheduleContract.Sessions.CONTENT_TYPE_ID).getBytes(),
new byte[0],
sessionUri.toString().getBytes())
}), activity);
}
示例2: setPushMessage
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
@TargetApi(14)
public static boolean setPushMessage(Activity activity, Uri toShare) {
NfcAdapter adapter = getAdapter(activity);
if (adapter != null) {
adapter.setNdefPushMessage(new NdefMessage(new NdefRecord[]{
NdefRecord.createUri(toShare),
}), activity);
return true;
}
return false;
}
示例3: onCreate
import android.nfc.NfcAdapter; //導入方法依賴的package包/類
@SuppressFBWarnings("DM_EXIT")
@SuppressLint("InlinedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
ensureActivityNotExported();
// The browser process must be started here because this Activity may be started explicitly
// from Android notifications, when Android is restoring Preferences after Chrome was
// killed, or for tests. This should happen before super.onCreate() because it might
// recreate a fragment, and a fragment might depend on the native library.
try {
ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();
} catch (ProcessInitException e) {
Log.e(TAG, "Failed to start browser process.", e);
// This can only ever happen, if at all, when the activity is started from an Android
// notification (or in tests). As such we don't want to show an error messsage to the
// user. The application is completely broken at this point, so close it down
// completely (not just the activity).
System.exit(-1);
return;
}
super.onCreate(savedInstanceState);
mIsNewlyCreated = savedInstanceState == null;
String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// If savedInstanceState is non-null, then the activity is being
// recreated and super.onCreate() has already recreated the fragment.
if (savedInstanceState == null) {
if (initialFragment == null) initialFragment = MainPreferences.class.getName();
Fragment fragment = Fragment.instantiate(this, initialFragment, initialArguments);
getFragmentManager().beginTransaction()
.replace(android.R.id.content, fragment)
.commit();
}
if (ApiCompatibilityUtils.checkPermission(
this, Manifest.permission.NFC, Process.myPid(), Process.myUid())
== PackageManager.PERMISSION_GRANTED) {
// Disable Android Beam on JB and later devices.
// In ICS it does nothing - i.e. we will send a Play Store link if NFC is used.
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter != null) nfcAdapter.setNdefPushMessage(null, this);
}
Resources res = getResources();
ApiCompatibilityUtils.setTaskDescription(this, res.getString(R.string.app_name),
BitmapFactory.decodeResource(res, R.mipmap.app_icon),
ApiCompatibilityUtils.getColor(res, R.color.default_primary_color));
}