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?
Related
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.
I am developing an Android app (and soon iPhone app). I need a way to identify the handset from server side. I was thinking I could write a secret (a cryptographic string of some sort) in persistent storage on the device the first time the app is run, and use this to identify the handset next time it speaks to the back end server. Is this how to do it? Is there a better way?
Clarification: The question should have said, I want to identify the user of the app. I'm not interested in tracking the actual device.
As much I understood your question, you wish to identify from which device request is coming, not the build or firmware of the phone. In this case you could identify them from their IMEI number, with following code -
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();
Add the following permission into your Manifest file :
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
I'm implementing an way to unique identify the device.
The architect send me the following specs:
devices with Wifi + 3G: IMEI Code
devices Wifi only - MacAddress
Both needs also the Manufacturer + Model for complete the id.
My questions are:
How do I get the IMEI from the device?
How can I get the Manufacturer and Model from the device? (I see theres some constants on Build class for it, but don't know where to use them)
Theres devices with 3G only?
How can I know if the device is wifi only, wifi+3g or 3g only if exists?
Also, suggestions for unique identifiers are available.
PS: I'm already able to get the MacAddres through WifiManager.
You can use the TelephonyManager getDeviceID method. This should return IMEI or MEID. For build information you can see android.os.Build and android.os.Build.VERSION. Also, if its about uniquely identifying your application installs, you may want to go through (and/or show your architect) the developer blog post on Identifying App Installations
How to get IMEI can be found in this question: How to get the device's IMEI/ESN programmatically in android?;
MANUFACTURER and MODEL can be retrieved from android.os.BUILD class.
Theoretically, yes, there might be devices without Wi-Fi but with 3G. But I haven't seen any.
If getSystemService(WIFI_SERVICE) returns null, then there is no Wi-Fi.
android.telephony.TelephonyManager.getDeviceId() gets you 'the IMEI for GSM and the MEID or ESN for CDMA phones'.
Build.MODEL is a static field, so you can just use it like that, so long as you've imported android.os.Build first.
Quite possibly.
You could try calling Context.getSystemService(Context.WIFI_SERVICE) and seeing if it's null, although I suppose it's possible that the service might still exist even if there's no wifi (in such a case, I would expect checking the wifi to return DISABLED.)
These questions have plagued Android developers for a while, see Is there a unique Android device ID?
The Android development team has tried to address these concerns directly in their blog here: http://android-developers.blogspot.com/2011/03/identifying-app-installations.html
In answer to your last question: just test for null when querying for SIM/MAC/Whatever and then act accordingly. It's been reported that there are cases where MAC will return null; see my first link.
Does anyone know if its possible to set the emulator's mobile number? I have not been able to find information about this anywhere. Thanks.
Mostly full control of the phone number detailed at the end of this blog:
http://blog.talosintel.com/2013/04/changing-imei-provider-model-and-phone.html
First 7 are fully configurable, last 4 can be one of 16 allowed port numbers.
It turns out that the phone number is stored on the SIM card. Since there is no actual SIM card, one is emulated. This emulated SIM is hard coded in the emulator-arm binary. The reason replacements for 1555521 failed is because SIM cards have a specification that does not store the MSISDN (Mobile Subscriber Integrated Services Digital Network-Number, AKA phone number) in plain text. Instead, each set of digits is swapped in some reverse nibbled endianness nightmare.
...
A quick way to find the MSISDN is to search for %d%df%d in the binary (highlighted in red below). The corresponding source code is in external/qemu/telephony/sim_card.c on line 436 in the current repo. The following is the format string portion of that sprintf:
"+CRSM:144,0,ffffffffffffffffffffffffffffffffffff0781515525%d1%d%df%dffffffffffff"
The interesting part is 515525%d1 (highlighted in blue). Swapping each set of two digits produces 1555521%d (thanks again CodePainters). That looks like the prefix to our mobile number.
Edit it in a hex editor.
I think this webpage will show you how to do it
https://www.wikihow.com/Find-Your-Phone-Number-on-Android
here instead of about phone try searching about the emulator device
You can simulate incoming SMS and calls in the simulator (using the simulator's port) but that's all, you can not set a device number or anything like that. For that kind of thing you will need a real device.
As I have found each emulator already has a phone number. If you run two emulators you can call from one emulator to another. To find out this phone numbers you can run in the terminal window:
Path\To\Your\Android\Sdk\platform-tools>adb devices
List of devices attached
emulator-5554 device
emulator-5556 device
First phone number is +15555215554, second +15555215556, i.e. phone number is prefix +1555521 plus emulator suffix 5554 or 5556.
In your emulated device, press on the 3 dots highlighted in yellow and choose phone and then you can change the mobile number, screenshot attached in link below
https://i.stack.imgur.com/zhbSV.png
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
System.out.println("gfvnchgjvbnvhjbbnvgjvbncghvmn ngvm"+imei);
// get SimSerialNumber
String simSerialNumber = tm.getSimSerialNumber();
System.out.println("854755745588954754855ngvm"+simSerialNumber);
//get SimCardNumber
String number = tm.getLine1Number();
System.out.println("gfch5652345651szdxfcgvhbjnfcgvh ngvm"+number);
And Import :]->
import android.content.Context;
import android.telephony.TelephonyManager;
The mobile number of an emulator is the port number of that emulator. For more details. please check this link:
http://developer.android.com/guide/developing/devices/emulator.html#calling
I'm working on a client-server Android application and trying to figure out how to identify different phones/users to the server unambiguously. My first attempt would be to use the phone number on the SIM card. Although now that I think about it, how common is it these days that your phone number changes when you e.g. change carrier? I guess it depends from country to country etc.
Anyway, I've been trying to figure out, since I don't have actual Android phones, how to change the phone number of the emulator phone to simulate different users. Is it possible or should I just think about alternative ways of identification?
The android_id is supposed to uniquely identify the device, however, it has been noted that the id can be changed if you know how Spoofing android_id
import android.provider.Settings.System;
String android_id = System.getString(this.getContentResolver(), System.ANDROID_ID);
In the emulator, the android_id does not have a value, so you will need to put a debugging routine in to assign a value yourself.
However, if you want to identify the user, and let the user access your service from different devices with one user id you are better off assigning them a user id and having them authenticate to your service using this user id as their credential. This would let them use their id's on many different devices, unless you used it in conjunction with the android_id (and the android_id wasn't spoofed) then you could limit them to one device.
You should use the number present by the emulator. Eg. usually first emulator that is running has number 5554, second 5555, and so on.
You can use these numbers to make calls, send text messages from emulator to emulator. This, I think, simulates different numbers/users for your purposes.
The SIM card info is hard-coded into the emulator-arm and emulator-x86 binaries. Changing the phone number (MSISDN) is detailed at the end of this blog post: new link, web archive
The SIM card stores the phone number with each 2 digits swapped. So (the first 7 of the phone number) 1555521 becomes 515525%d1 in the binary. While a little tedious, patching it for each test isn't the end of the world. You could also use sed:
cd path/to/android-sdk-linux/tools/
cp emulator-arm emulator-arm.backup
sed -i 's/515525%d1/816745%d3/g' emulator-arm
That will change the number to 1-876-543-[PORT NUMBER]. Details on why are in the linked blog post.