use of android.nfc.NfcAdapter in project weiciyuan by qii.
the class AbstractAppActivity method initNFC.
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);
}
use of android.nfc.NfcAdapter in project AndroidChromium by JackyAndroid.
the class Preferences method onCreate.
@SuppressFBWarnings("DM_EXIT")
@SuppressLint("InlinedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
ensureActivityNotExported();
// 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);
// 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));
}
use of android.nfc.NfcAdapter in project AndroidChromium by JackyAndroid.
the class BeamController method registerForBeam.
/**
* If the device has NFC, construct a BeamCallback and pass it to Android.
*
* @param activity Activity that is sending out beam messages.
* @param provider Provider that returns the URL that should be shared.
*/
public static void registerForBeam(final Activity activity, final BeamProvider provider) {
final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
if (nfcAdapter == null)
return;
if (ApiCompatibilityUtils.checkPermission(activity, Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_DENIED) {
return;
}
try {
final BeamCallback beamCallback = new BeamCallback(activity, provider);
nfcAdapter.setNdefPushMessageCallback(beamCallback, activity);
nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity);
} catch (IllegalStateException e) {
Log.w("BeamController", "NFC registration failure. Can't retry, giving up.");
}
}
use of android.nfc.NfcAdapter in project platform_frameworks_base by android.
the class NfcFCardEmulation method recoverService.
void recoverService() {
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext);
sService = adapter.getNfcFCardEmulationService();
}
use of android.nfc.NfcAdapter in project android_frameworks_base by DirtyUnicorns.
the class NfcFCardEmulation method recoverService.
void recoverService() {
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext);
sService = adapter.getNfcFCardEmulationService();
}
Aggregations