test also whether NFC turned on

This commit is contained in:
Eric House 2013-11-12 19:12:47 -08:00
parent b3bc738cae
commit b7d756957c
2 changed files with 12 additions and 3 deletions

View file

@ -411,7 +411,7 @@ public class DlgDelegate {
.setPositiveButton( R.string.button_text, lstnr )
.setNegativeButton( R.string.button_html, lstnr );
if ( NFCUtils.nfcAvail() ) {
if ( NFCUtils.nfcAvail( m_activity ) ) {
builder.setNeutralButton( R.string.button_nfc, lstnr );
}
Dialog dialog = builder.create();

View file

@ -21,10 +21,12 @@
package org.eehouse.android.xw4;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcManager;
import android.os.Parcelable;
import java.nio.charset.Charset;
@ -32,9 +34,16 @@ public class NFCUtils {
private static boolean s_inSDK =
14 <= Integer.valueOf( android.os.Build.VERSION.SDK );
public static boolean nfcAvail()
public static boolean nfcAvail( Context context )
{
return s_inSDK /*&& turnedOn*/;
boolean result = s_inSDK;
if ( result ) {
NfcManager manager =
(NfcManager)context.getSystemService( Context.NFC_SERVICE );
NfcAdapter adapter = manager.getDefaultAdapter();
result = null != adapter && adapter.isEnabled();
}
return result;
}
public static void buildAndPush( Activity activity, String data )