Java Code Examples for android.nfc.NfcAdapter#setNdefPushMessage()
The following examples show how to use
android.nfc.NfcAdapter#setNdefPushMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraActivity.java From Camera2 with Apache License 2.0 | 6 votes |
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); }
Example 2
Source File: BeamActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
@Override protected void onResume() { super.onResume(); // Listing 18-21: Creating an Android Beam NDEF message String payload = "Two to beam across"; String mimeType = "application/com.professionalandroid.apps.nfcbeam"; byte[] tagId = new byte[0]; NdefMessage nfcMessage = new NdefMessage(new NdefRecord[] { // Create the NFC payload. new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeType.getBytes(Charset.forName("US-ASCII")), tagId, payload.getBytes(Charset.forName("US-ASCII"))), // Add the AAR (Android Application Record) NdefRecord.createApplicationRecord("com.professionalandroid.apps.nfcbeam") }); // Set static beam message NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); nfcAdapter.setNdefPushMessage(nfcMessage, this); // Set dynamic beam message setBeamMessage(); }
Example 3
Source File: NfcHelper.java From fdroidclient with GNU General Public License v3.0 | 5 votes |
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; }
Example 4
Source File: Preferences.java From delion with Apache License 2.0 | 4 votes |
@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 (checkPermission(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)); }
Example 5
Source File: Preferences.java From AndroidChromium with Apache License 2.0 | 4 votes |
@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)); }
Example 6
Source File: Preferences.java From 365browser with Apache License 2.0 | 4 votes |
@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)); }