Пример #1
1
 /**
  * Return true if NDEF Push feature is enabled.
  *
  * <p>This function can return true even if NFC is currently turned-off. This indicates that NDEF
  * Push is not currently active, but it has been requested by the user and will be active as soon
  * as NFC is turned on.
  *
  * <p>If you want to check if NDEF PUsh sharing is currently active, use <code>
  * {@link #isEnabled()} && {@link #isNdefPushEnabled()}</code>
  *
  * @return true if NDEF Push feature is enabled
  * @hide
  */
 public boolean isNdefPushEnabled() {
   try {
     return sService.isNdefPushEnabled();
   } catch (RemoteException e) {
     attemptDeadServiceRecovery(e);
     return false;
   }
 }
Пример #2
0
 /** @hide */
 public INfcAdapterExtras getNfcAdapterExtrasInterface() {
   try {
     return sService.getNfcAdapterExtrasInterface();
   } catch (RemoteException e) {
     attemptDeadServiceRecovery(e);
     return null;
   }
 }
Пример #3
0
 /**
  * Disable NFC hardware.
  *
  * <p>No NFC features will work after this call, and the hardware will not perform or respond to
  * any NFC communication.
  *
  * <p>This call is asynchronous. Listen for {@link #ACTION_ADAPTER_STATE_CHANGED} broadcasts to
  * find out when the operation is complete.
  *
  * <p>If this returns true, then either NFC is already off, or a {@link
  * #ACTION_ADAPTER_STATE_CHANGED} broadcast will be sent to indicate a state transition. If this
  * returns false, then there is some problem that prevents an attempt to turn NFC off.
  *
  * @hide
  */
 public boolean disable() {
   try {
     return sService.disable();
   } catch (RemoteException e) {
     attemptDeadServiceRecovery(e);
     return false;
   }
 }
Пример #4
0
 /**
  * Return the state of this NFC Adapter.
  *
  * <p>Returns one of {@link #STATE_ON}, {@link #STATE_TURNING_ON}, {@link #STATE_OFF}, {@link
  * #STATE_TURNING_OFF}.
  *
  * <p>{@link #isEnabled()} is equivalent to <code>{@link #getAdapterState()} == {@link #STATE_ON}
  * </code>
  *
  * @return the current state of this NFC adapter
  * @hide
  */
 public int getAdapterState() {
   try {
     return sService.getState();
   } catch (RemoteException e) {
     attemptDeadServiceRecovery(e);
     return NfcAdapter.STATE_OFF;
   }
 }
Пример #5
0
 /**
  * Return true if this NFC Adapter has any features enabled.
  *
  * <p>Application may use this as a helper to suggest that the user should turn on NFC in
  * Settings.
  *
  * <p>If this method returns false, the NFC hardware is guaranteed not to generate or respond to
  * any NFC transactions.
  *
  * @return true if this NFC Adapter has any features enabled
  */
 public boolean isEnabled() {
   try {
     return sService.getState() == STATE_ON;
   } catch (RemoteException e) {
     attemptDeadServiceRecovery(e);
     return false;
   }
 }
Пример #6
0
 void disableForegroundDispatchInternal(Activity activity, boolean force) {
   try {
     sService.setForegroundDispatch(null, null, null);
     if (!force && !activity.isResumed()) {
       throw new IllegalStateException(
           "You must disable foreground dispatching " + "while your activity is still resumed");
     }
   } catch (RemoteException e) {
     attemptDeadServiceRecovery(e);
   }
 }
Пример #7
0
 /**
  * Enable foreground dispatch to the given Activity.
  *
  * <p>This will give give priority to the foreground activity when dispatching a discovered {@link
  * Tag} to an application.
  *
  * <p>If any IntentFilters are provided to this method they are used to match dispatch Intents for
  * both the {@link NfcAdapter#ACTION_NDEF_DISCOVERED} and {@link
  * NfcAdapter#ACTION_TAG_DISCOVERED}. Since {@link NfcAdapter#ACTION_TECH_DISCOVERED} relies on
  * meta data outside of the IntentFilter matching for that dispatch Intent is handled by passing
  * in the tech lists separately. Each first level entry in the tech list represents an array of
  * technologies that must all be present to match. If any of the first level sets match then the
  * dispatch is routed through the given PendingIntent. In other words, the second level is ANDed
  * together and the first level entries are ORed together.
  *
  * <p>If you pass {@code null} for both the {@code filters} and {@code techLists} parameters that
  * acts a wild card and will cause the foreground activity to receive all tags via the {@link
  * NfcAdapter#ACTION_TAG_DISCOVERED} intent.
  *
  * <p>This method must be called from the main thread, and only when the activity is in the
  * foreground (resumed). Also, activities must call {@link #disableForegroundDispatch} before the
  * completion of their {@link Activity#onPause} callback to disable foreground dispatch after it
  * has been enabled.
  *
  * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
  *
  * @param activity the Activity to dispatch to
  * @param intent the PendingIntent to start for the dispatch
  * @param filters the IntentFilters to override dispatching for, or null to always dispatch
  * @param techLists the tech lists used to perform matching for dispatching of the {@link
  *     NfcAdapter#ACTION_TECH_DISCOVERED} intent
  * @throws IllegalStateException if the Activity is not currently in the foreground
  */
 public void enableForegroundDispatch(
     Activity activity, PendingIntent intent, IntentFilter[] filters, String[][] techLists) {
   if (activity == null || intent == null) {
     throw new NullPointerException();
   }
   if (!activity.isResumed()) {
     throw new IllegalStateException(
         "Foreground dispatch can only be enabled " + "when your activity is resumed");
   }
   try {
     TechListParcel parcel = null;
     if (techLists != null && techLists.length > 0) {
       parcel = new TechListParcel(techLists);
     }
     ActivityThread.currentActivityThread()
         .registerOnActivityPausedListener(activity, mForegroundDispatchListener);
     sService.setForegroundDispatch(intent, filters, parcel);
   } catch (RemoteException e) {
     attemptDeadServiceRecovery(e);
   }
 }