Qpython Bluetooth admin permission patch

Qpython for android is very handy for getting an idea up and running quickly. There is a problem with its bluetooth permissions though which means that whenever any Bluetooth related function is run, a permissions error occurs. Sometimes the error message says something about Bluetooth requiring administrator permission to be used but in this case I received a connection refused message:
SC20140330-181316

After searching online, there was only one post related to this on a forum. Luckily a user suggested that decompiling the .apk file, editing the AndroidManifest.xml file to give the Qpython app the correct permissions and then rebuilding the .apk file should fix the issue. To work with the .apk file I used apktool for decompiling and rebuilding. Here are the commands used:

Place the .apk file (in this case I renamed mine to test.apk) in the same directory as the apktool.jar file and run the following command to decompile the .apk file:

java -jar d test.apk

After the file is decompiled, open up the AndroidManifest.xml and add in the following line:

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" ⁄ >

So now we want to rebuild the .apk file. This is done with the following command: (Just make sure the dirctory given points to the folder containing the decompiled .apk file)

java -jar apktool.jar b /usr/local/bin/test

So now the .apk file has been rebuilt. Now it need to be signed before it can be installed on an android phone. SignAPK was used for this. This is the command used:

java -jar signapk.jar certificate.pem key.pk8 test.apk test_signed.apk

This will take test.apk, sign it and output test_signed.apk. Now the app can be transferred to a smartphone and installed. After the modified app was installed I managed to find and connect to my computer with no errors. Here is what it looked like in the terminal:
Selection_067

Here is the Qpython script used:

#qpy:console
from androidhelper import Android

droid = Android()

droid.toggleBluetoothState(True)# turn on bluetooth
if droid.checkBluetoothState().result == True:
    print 'Bluetooth is on'
else:
	print "could not turn on bluetooth"

print " Phone info:" + str(droid.bluetoothGetLocalName())
print "Computer info: " + str(droid.bluetoothGetRemoteDeviceName(address='88:53:2E:E8:65:4C'))
droid.bluetoothConnect(address='88:53:2E:E8:65:4C') # connect to computer
print "Active connections : " + str(droid.bluetoothActiveConnections())

Download link to updated Qpython apk file.

Advertisements

2 thoughts on “Qpython Bluetooth admin permission patch

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s