send phone number through emulator - android

I am making an application and I want to retrieve the device phone number and send that on the server. But I am testing this application on android emulator. Can anybody please tell me how to set or get the phone number in emulator and actual device.
Thanks.

We can get the phone number in emulator if we use the Telephony manager
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String phone = tm.getLine1Number();
Toast toast = Toast.makeText(getApplicationContext(), phone, Toast.LENGTH_SHORT);
toast.show();
On making the toast of the phone number we get the phone number like..
15555215554
It also need the android.permission.READ_PHONE_STATE permission.
So Emulator is also having its own phone number.

In DDMS perspective You will see Emulator Control tab you can emulate the call from there.
If you don't see Emulator Control there . Use Window> Show /View > Emulator Control to make the tab appear.
To accesss device phone number in your code use telephonymanager.getLine1Number();
You need to set READ_PHONE_STATE permission in manifest file for that.

you cannot call the emulator from your device. But you can make calls to two emulators. For details on how to ? you can go to DDMS perspective then Emulator Control tab you can make the call from there to other emulator.
http://developer.android.com/tools/devices/emulator.html

Related

The phone return empty when I want to get the phone number

Some phones return null when I want to get the phone number. In other phones I get the phone number.
This happens when Settings -> About Phone -> Status -> My phone number is "Unkow". Not writed there the phone number.
Why is this happening?How can I get a phone number ?
The code:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
And:
TelephonyManager tMgr = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
Your code is perfect to get phone number of Android device.It will return you number.But sometimes it gives you null because that devices Service provider has not given permission to do that.
Means It works like : Android devices Request SIM card/Service provider for card info with phone number. And In response, Some provider have returned phone number of user and some has refused to do so.
Can you clarify what specifically you're asking for? If you're saying that it happens when in your phone's settings, under About Phone->Status->My phone number, it says "Unknown", then unfortunately that's not a programming question and not a question for here. Is that the case?
You cannot get device phone number in any ways. It depends on the service provider, some may allow access and some may not since it is completely dependent on the network access privileges. But in rare case you would get the phone number once the user has configured their own mobile number with the SIM card provider. The other way to do this by fetching the number from Facebook that too the user should have registered their mobile number, whereas the earlier versions of whatsapp provides this feature, but it is not compatible with the newer ones.
Note: It works with few custom phones which provides the access.(i.e., phones synced with only particular network providers)

Android Eclipse Emulator

Need Help -> I want to get phone number and show it, I have code like this
TelephonyManager tMgr =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
mPhoneNumber = tMgr.getLine1Number();
TextView t=(TextView)findViewById(R.id.TVphone);
t.setText(mPhoneNumber);
but nothing result, so I check my Android emulator with setting-phone-status-phone number show 'unknown', how to change it? I want my phone number not unknowm.
Thanks
Try to add a phone number to the emulator and try the above code.
See this link for more info.
"In DDMS perspective You will see Emulator Control tab you can emulate the call from there. If you don't see Emulator Control there . Use Window> Show /View > Emulator Control to make the tab appear."
Also you need the android.permission.READ_PHONE_STATE permission in your manifest, do you have that?

how to obtain mobile number of own device in android?

I want to retreive mobile number of device programatically. My code is:-
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String strMobileNumber = telephonyManager.getLine1Number();
and I have set READ_PHONE_STATE permission in AndroidManifest.xml file. This is working on emulator but on actual device with eclair version, it is returning empty string. Is there any other way to get mobile no?
There is no reliable way to "retreive mobile number of device programatically", AFAIK. getLine1Number() reports the number supplied by the SIM card for GSM phones, and the mobile number does not need to be on the SIM card.

Android emulator: Set mobile device number?

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

Send an SMS to the emulator

I am working on an android application and I want to send an SMS to the phone number of the phone i.e the emulator. I know there will be no real phone number for emulator, but how can I send an SMS from the phone?
Open Eclipse. Select "Emulator Control" from Window -->Show View -->Android.There will be an option called Telephony Actions. There under the Incoming number just specify a sample number.Select SMS and type the text that you want and finally click "Send"
You can try this sample app too
http://samplecodeviewer.googlecode.com/svn-history/r2/trunk/SampleCodeViewer/SMSTest.zip
and check for SMSSender.java class.

Categories

Resources