Python Bluetooth: Can't get android to print connected device name - android

I'm fairly new to python SL4A and I could not find a question that helped me, so bear with me.
Here is what I'm working with so far:
import sl4a
UUID = ''
droid = sl4a.Android()
droid.toggleBluetoothState(True, False)
droid.bluetoothConnect(UUID)
print(droid.bluetoothGetConnectedDeviceName())
Here is the error that I get when I run the above code:
"java.io.IOException: Bluetooth not ready for this connID."
If I run the above code without the last line, I can see on my laptop that it's connected, but I want to see from the android's side that I can return the device name (for shits n' gigs).
What am I doing incorrectly so that I can get the android to return the device's name?
Edit: Please let me know if I should ask in a different manner; this is my first post, but I regularly troll this website for answers when I come to a roadblock.

Related

Listing Computers in a Network

I have been using the following code to list computers on my Home Network.
if (path.equals("smb://")) {
domains = (new SmbFile(path)).listFiles();
}
When I had 2 Windows 10 PCs on my network, this worked fine.
However, since I added a 3rd Windows 10 PC, it throws an exception : "jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.".
If I turn the new computer off, the code works again.
ES File Explorer can access the new Computer from the same Android device.
My question is in 2 parts.
a) Can anyone tell me what I need to do to get the new PC to appear in the list?
or
b) Can I get listfiles() to ignore the PC? I see you can add an SMBFileNameFilter to the call but can't find much information on what this does and how to use it.

Get phone number from Python coded app

I'm making an android app with python. I made an authentication server which receives phone's status (serial number, phone number...) and compares it with another server to figure out if the user purchased this app or not.
At this point I've got a problem. I can't find the way how to extract phone number with python made app.
What I figured out is there's a function called 'TelephonyManager' which works in java.
TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)
Isn't there any module or function in Python to replace that?
If you use Python under SL4A:
import android
droid = android.Android()
print droid.getLine1Number().result
However, as in Java this might not work depending on SIM card. See TelephonyManager.getLine1Number() failing?

Cannot set temperature interval on sensortag

I'm creating an android application that interfaces with the texas instruments sensortag. One of the things the app needs to do is be able to change the frequency in which the temperature is reported to the app. I am able to change it through the official TI app which is great, but I cannot seem to get it working in my app.
When viewing the official app (iOS, can't run the android one?), it shows the temperature GATT service, which contains 3 characteristics. When I inspect the characteristics discovered by my app however, it only seems to find two - the data, and the notifications. Not the interval. I have attempted to construct this characteristic myself and write it however it doesn't do anything - no error, no success, just nothing.
The steps I've taken are essentially:
bluetoothGatt.discoverServices();
...
services = bluetoothGatt.getServices();
...
BluetoothGattService service = bluetoothGatt.getService(serviceUUID);
System.out.println("Characteristic = " + service.getCharacteristic(SensorTagGatt.UUID_IRT_PERI));
The output yields null. Is there something obvious I'm missing or that I should be doing that I might not be?
EDIT:
I've installed another app onto the phone written by another developer, and using this to inspect the services and characteristics available shows that it too is unable to find it, so I'm assuming there is something wrong with the android service discovery? The official iOS app is working as expected, and showing all characteristics. Unfortunately, the official android app seems to be incompatible with the version 1.5 firmware and crashes when trying to connect but I assume it too will fail to find the characteristic.
Has anyone else run into this issue and if so been able to get around it?

Parse.com saveInBackground not working on all devices

I have a simple piece of code:
ParseObject testobject = new ParseObject("Test");
testobject.put("customerName", "John");
testobject.saveInBackground();
If I run this on my emulator, it works, a Test class is made in my Parse project and the value John is added to the Row customername.
If I run this on my mobile phone the result is also succesful.
But if I run the exact same program on my Tablet, nothing happens.
(the callback = null, .getResult() and .getError() are also null)
Any idea where the problem lies?
Are you using Wi-fi on your phone or using mobile internet? Depending on where you are (Home, School/University) they may have blocked some ports which stop the service from running.
Something I saw is, you've got spaces between 'testobject .put' and 'testobject .saveInBackground();', that may be your issue?

how to get mac address in android with python

I am trying to code an addon in XBMC linux environment within Android.
I can see Mac address inside XBMC. But I'd like to grab the mac address for the addon and I can't figure out how.
mac=uuid.getnode()
I have already tried with code like above but gives me numbers only and different everytime when run in android.
could someone give any suggestion please
You can use XBMC InfoLabels
if xbmc.getInfoLabel('Network.MacAddress') != None:
mac_address = xbmc.getInfoLabel('Network.MacAddress')
else:
mac_address = None
If you look at the docs:
Get the hardware address as a 48-bit positive integer. The first time this runs, it may launch a separate program, which could be quite slow. If all attempts to obtain the hardware address fail, we choose a random 48-bit number with its eighth bit set to 1 as recommended in RFC 4122.
The first part explains why it's "numbers only". It's supposed to be a number. If you want that in some particular hex-string format, just format it—e.g., by calling hex().
The last sentence explains why it's "different everytime". If you look at the source, on any non-Windows platform, getnode will try _unixdll_getnode, then _ifconfig_getnode, then fall back to a random number. The former requires a function called uuid_generate_time in either libuuid or libc, which doesn't exist on Android. The latter runs the command ifconfig with a series of different flags and searches for specific strings, and falls back to arp and lanscan. Again, none of this works on Android.
There is no recommended way to get the MAC address on Android, mainly because they don't want you to get one. This blog post explains why, and this SO question (especially Seka Alekseyev's answer) adds more detail. Some apps try persisting the MAC address once they've gotten it, and never checking again, which gets around some of the problems, but not most of them.
There is a Java API to get the MAC for each service where it makes sense—WiFi, 3G, Bluetooth, etc. It's up to you to decide which is "the" MAC, and you need the right permissions (e.g., android.permission.ACCESS_WIFI_STATE), and there may be no value or a garbage value, but you can get it with code like this:
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
String mac = wm.getConnectionInfo().getMacAddress();
As far as I know, there's nothing in SL4A or any other Android Python distribution that exposes these functions directly, so you'll have to write your own wrapper.
You can get mac address on this easy way, assume "eth0" is your network device name:
o = open('/sys/class/net/eth0/address', 'r')
mac_address = o.read().strip() #on "ff:ff:ff:ff:ff:ff" form

Categories

Resources