I created an application that checks the payload of an NFC tag, and when it matches the application, it switches Bluetooth.
Unfortunately, the application seems to go into an endless loop where it asks the user for permission to manipulate Bluetooth, ignores the selection and starts again (again asking the same question / action). onActivityResult does not seem to be called.
The output from my console log calls:
Payload: 'quicktags-togglebluetooth' Bluetooth should now be on
If I continue to delete βYesβ in the permissions action, then Bluetooth switches continuously and the console log (logcat) looks like this:
Payload: quicktags-togglebluetooth Bluetooth should now be on Bluetooth should now be off Bluetooth should now be on Bluetooth should now be off Bluetooth should now be on Bluetooth should now be off
etc.
AndroidManifest lists the correct permissions, see below:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.getquicktags.qt" android:versionCode="1" android:versionName="1.0" android:installLocation="auto"> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" /> <uses-permission android:name="android.permission.NFC" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".CardActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <data android:mimeType="application/vnd.getquicktags.qt"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> </application> </manifest>
The CardActivity.java file that launches this chaos of Bluetooth can be found below:
package com.getquicktags.qt; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.nfc.NfcAdapter; import android.os.Bundle; import android.os.Parcelable; import android.util.Log; import android.bluetooth.*; public class CardActivity extends Activity implements OnClickListener { private static final String TAG = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.card_activity);
You can see that according to logcat, onActivityResults and therefore closeApp not called.
I am testing a Nexus 7. The tag is fine, I tested using various NFC readers.
There are some errors from logcat when checking the tag, but they don't seem to make much sense to me. See below:
01-07 00:18:41.595: E/bt-btif(5830): btif_enable_service: current services:0x100020 01-07 00:18:41.605: E/bt-btif(5830): btif_enable_service: current services:0x140020 01-07 00:18:41.605: E/bt-btif(5830): btif_enable_service: current services:0x140020 01-07 00:18:42.415: E/bt-btif(5830): Calling BTA_HhEnable 01-07 00:18:42.415: E/btif_config.c(5830): ## btif_config_get assert section && *section && key && *key && name && *name && bytes && type failed at line:186 ## 01-07 00:18:42.415: E/bt-btif(5830): btif_storage_get_adapter_property service_mask:0x140020 01-07 00:18:42.435: E/btif_config.c(5830): ## btif_config_get assert section && *section && key && *key && name && *name && bytes && type failed at line:186 ## 01-07 00:18:42.445: E/bt_h4(5830): vendor lib postload completed 01-07 00:18:42.545: E/BluetoothServiceJni(5830): SOCK FLAG = 1 *********************** 01-07 00:18:42.605: E/BluetoothServiceJni(5830): SOCK FLAG = 0 *********************** 01-07 00:18:42.715: E/BtOppRfcommListener(5830): Error accept connection java.io.IOException: read failed, socket might closed, read ret: -1 01-07 00:18:42.915: E/bt-btif(5830): BTA AG is already disabled, ignoring ... 01-07 00:18:42.935: E/bt-btif(5830): btif_disable_service: Current Services:0x140020 01-07 00:18:42.945: E/bt-btif(5830): btif_disable_service: Current Services:0x100020 01-07 00:18:42.945: E/bt-btif(5830): btif_disable_service: Current Services:0x100020
Mass thanks for any help on this. As you can imagine, this is driving me crazy :)