List of usage examples for android.nfc NfcAdapter getDefaultAdapter
public static NfcAdapter getDefaultAdapter(Context context)
From source file:org.mozilla.gecko.BrowserApp.java
@Override public void onDestroy() { mDynamicToolbar.destroy();//from w ww . j av a 2s.co m if (mBrowserToolbar != null) mBrowserToolbar.onDestroy(); if (mFindInPageBar != null) { mFindInPageBar.onDestroy(); mFindInPageBar = null; } if (mMediaCastingBar != null) { mMediaCastingBar.onDestroy(); mMediaCastingBar = null; } if (mSharedPreferencesHelper != null) { mSharedPreferencesHelper.uninit(); mSharedPreferencesHelper = null; } if (mOrderedBroadcastHelper != null) { mOrderedBroadcastHelper.uninit(); mOrderedBroadcastHelper = null; } if (mBrowserHealthReporter != null) { mBrowserHealthReporter.uninit(); mBrowserHealthReporter = null; } if (mReadingListHelper != null) { mReadingListHelper.uninit(); mReadingListHelper = null; } if (mZoomedView != null) { mZoomedView.destroy(); } EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener) this, "Menu:Open", "Menu:Update", "LightweightTheme:Update", "Search:Keyword", "Prompt:ShowTop", "Accounts:Exist"); EventDispatcher.getInstance().unregisterGeckoThreadListener((NativeEventListener) this, "Accounts:Create", "Accounts:CreateFirefoxAccountFromJSON", "CharEncoding:Data", "CharEncoding:State", "Favicon:CacheLoad", "Feedback:LastUrl", "Feedback:MaybeLater", "Feedback:OpenPlayStore", "Menu:Add", "Menu:Remove", "Reader:Share", "Sanitize:ClearHistory", "Sanitize:ClearSyncedTabs", "Settings:Show", "Telemetry:Gather", "Updater:Launch"); if (AppConstants.MOZ_ANDROID_BEAM) { NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); if (nfc != null) { // null this out even though the docs say it's not needed, // because the source code looks like it will only do this // automatically on API 14+ nfc.setNdefPushMessageCallback(null, this); } } super.onDestroy(); }
From source file:org.getlantern.firetweet.util.Utils.java
public static boolean setNdefPushMessageCallback(Activity activity, CreateNdefMessageCallback callback) { try {//from w w w . ja v a 2s . co m final NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity); if (adapter == null) return false; adapter.setNdefPushMessageCallback(callback, activity); return true; } catch (SecurityException e) { Crashlytics.logException(e); Log.w(LOGTAG, e); } return false; }
From source file:com.irccloud.android.activity.MainActivity.java
@Override public void onBufferSelected(int bid) { launchBid = -1;// ww w .ja v a2 s. co m launchURI = null; cidToOpen = -1; bufferToOpen = null; setIntent(new Intent(this, MainActivity.class)); if (suggestionsTimerTask != null) suggestionsTimerTask.cancel(); sortedChannels = null; sortedUsers = null; if (drawerLayout != null) { drawerLayout.closeDrawers(); } if (bid != -1 && conn != null && conn.getUserInfo() != null) { conn.getUserInfo().last_selected_bid = bid; } for (int i = 0; i < backStack.size(); i++) { if (buffer != null && backStack.get(i) == buffer.bid) backStack.remove(i); } if (buffer != null && buffer.bid >= 0 && bid != buffer.bid) { backStack.add(0, buffer.bid); buffer.draft = messageTxt.getText().toString(); } if (buffer == null || buffer.bid == -1 || buffer.cid == -1 || buffer.bid == bid) shouldFadeIn = false; else shouldFadeIn = true; buffer = BuffersDataSource.getInstance().getBuffer(bid); if (buffer != null) { Crashlytics.log(Log.DEBUG, "IRCCloud", "Buffer selected: cid" + buffer.cid + " bid" + bid + " shouldFadeIn: " + shouldFadeIn); server = ServersDataSource.getInstance().getServer(buffer.cid); try { TreeMap<Long, EventsDataSource.Event> events = EventsDataSource.getInstance() .getEventsForBuffer(buffer.bid); if (events != null) { events = (TreeMap<Long, EventsDataSource.Event>) events.clone(); for (EventsDataSource.Event e : events.values()) { if (e != null && e.highlight && e.from != null) { UsersDataSource.User u = UsersDataSource.getInstance().getUser(buffer.bid, e.from); if (u != null && u.last_mention < e.eid) u.last_mention = e.eid; } } } } catch (Exception e) { Crashlytics.logException(e); } try { if (Build.VERSION.SDK_INT >= 16 && buffer != null && server != null) { NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); if (nfc != null) { String uri = "irc"; if (server.ssl > 0) uri += "s"; uri += "://" + server.hostname + ":" + server.port; if (buffer.type.equals("channel")) { uri += "/" + URLEncoder.encode(buffer.name, "UTF-8"); ChannelsDataSource.Channel c = ChannelsDataSource.getInstance() .getChannelForBuffer(buffer.bid); if (c != null && c.hasMode("k")) uri += "," + c.paramForMode("k"); } nfc.setNdefPushMessage(new NdefMessage(NdefRecord.createUri(uri)), this); } } } catch (Exception e) { } } else { Crashlytics.log(Log.DEBUG, "IRCCloud", "Buffer selected but not found: bid" + bid + " shouldFadeIn: " + shouldFadeIn); server = null; } update_subtitle(); final Bundle b = new Bundle(); if (buffer != null) b.putInt("cid", buffer.cid); b.putInt("bid", bid); b.putBoolean("fade", shouldFadeIn); BuffersListFragment blf = (BuffersListFragment) getSupportFragmentManager() .findFragmentById(R.id.BuffersList); final MessageViewFragment mvf = (MessageViewFragment) getSupportFragmentManager() .findFragmentById(R.id.messageViewFragment); UsersListFragment ulf = (UsersListFragment) getSupportFragmentManager() .findFragmentById(R.id.usersListFragment); UsersListFragment ulf2 = (UsersListFragment) getSupportFragmentManager() .findFragmentById(R.id.usersListFragment2); if (mvf != null) mvf.ready = false; if (blf != null) blf.setSelectedBid(bid); if (ulf != null) ulf.setArguments(b); if (ulf2 != null) ulf2.setArguments(b); if (shouldFadeIn) { Crashlytics.log(Log.DEBUG, "IRCCloud", "Fade Out"); if (Build.VERSION.SDK_INT < 16) { AlphaAnimation anim = new AlphaAnimation(1, 0); anim.setDuration(150); anim.setFillAfter(true); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (mvf != null) mvf.setArguments(b); messageTxt.setText(""); if (buffer != null && buffer.draft != null) messageTxt.append(buffer.draft); } @Override public void onAnimationRepeat(Animation animation) { } }); try { mvf.getListView().startAnimation(anim); ulf.getListView().startAnimation(anim); } catch (Exception e) { } } else { mvf.getListView().animate().alpha(0).withEndAction(new Runnable() { @Override public void run() { if (mvf != null) mvf.setArguments(b); messageTxt.setText(""); if (buffer != null && buffer.draft != null) messageTxt.append(buffer.draft); } }); ulf.getListView().animate().alpha(0); } mvf.showSpinner(true); } else { if (mvf != null) mvf.setArguments(b); messageTxt.setText(""); if (buffer != null && buffer.draft != null) messageTxt.append(buffer.draft); } updateUsersListFragmentVisibility(); supportInvalidateOptionsMenu(); if (excludeBIDTask != null) excludeBIDTask.cancel(true); excludeBIDTask = new ExcludeBIDTask(); excludeBIDTask.execute(bid); if (drawerLayout != null) new RefreshUpIndicatorTask().execute((Void) null); if (buffer != null && buffer.cid != -1) { if (drawerLayout != null) { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT); getSupportActionBar().setHomeButtonEnabled(true); } } update_suggestions(false); }