Android Eclipse Emulator - android

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?

Related

How to get device name from phone settings in android

How to read the device name from phone setting in android, As shown in below image how to read the first field that is "device name" in android.
In some phones, the device name is the same as the model name but in some phones both are different so how to particular read device name from phone settings in android?
Any help is appreciated!
here you go
Settings.Global.getString(getContentResolver(), Settings.Global.DEVICE_NAME)
You can directly use this, Use in your logcat to see the result.
Build.DEVICE

How to fetch Device Name (NOT Build.MODEL) from Android programatically?

I have been searching for code through which I can fetch Device's name defined by user for his own device .
Have gone through various stackoverflow questions , but none seems to work for me ?
Image as seen in below : Will require Thanks Thanks (SM-T211 ) from android code
Try this:
String ownerInfo = Settings.Secure.getString(getContentResolver(),
"lock_screen_owner_info");
As of Android 4.4.2 the owner info value is moved to lock screen database,/data/system/locksettings.db to which 3rd-party apps have no read/write access. That's, there is no reliable way of reading owner info for later Android versions except for rooted device.
You need to get build.prop file of system which is possible either if your device is rooted or if your has system privileges....
heres the code you may follow to get and edit build.prop
Check this App in Play Store. build.prop Editor. Since it's open source, and the code is extremely simple, you can use it as a stating point: https://github.com/nathanpc/Build.prop-Editor
Try this :
BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
String deviceName = myDevice.getName();
Make sure you add to your manifest:
<uses-permission android:name="android.permission.BLUETOOTH"/>

Fail to display IMEI using code snippet

When I dial *#06# on my phone the IMEI is displayed. Fine.
But when I use this kind of code :
String imei="*#06#";
Intent cintent= new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+Uri.encode(imei)));
startActivity(cintent);
(or ACTION_CALL instead of ACTION_DIAL)
... the USSD code is displayed correctly on the dialer (*#06#). But even if I click call the IMEI never shows up (error : "Connection problem or invalid MMI code").
I've been through other similar topics, but found no solution and can't figure how to make it work (my phone is running Android 4.4.4).
Note that I don't want to get the result of the USSD, just have it executed somehow.If it is possible...
Thanks for your help !
We have a different way to get IMEI of device . you can follow the link(possible duplicate).How can I get phone serial number (IMEI)
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();
And you should add the following permission into your Manifest.xml file:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

send phone number through emulator

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

DDMS not able to send location to emulator

DDMS is not able to send location to the emulator. I have tried sending just the location from DDMS but still the emulator is not able to receive location. The application works properly in the device but its not able to capture location data in the emulator.
I am testing on Android 2.2 emulator. Can anyone let me know what can be the issue?
Make sure your AVD has GPS support hardware set to true
Create New AVD > Hardware > New > GPS support
Value should be "yes"
Also, ensure your app is requesting location updates in some way, otherwise the emulator will just ignore any incoming locations from DDMS or the console.
I just use the android console via telnet, it always works.
Just open a command line and:
telnet localhost 5554
5554 is the port number of your emulator, it is usually that but might change, it can be on the window fram of the emulator as PORT:AVD_NAME.
You should be greeted with an Android console message.
To send positions to your device just type.
geo fix []
Two valid statements would be
geo fix -77.036519 38.896143
geo fix -77.036519 38.896143 100
Hope this helps, its not DDMS, but it works always. You can also feed it nmea sentences but I dont think you need that.
I don't know what your setup looks like, but I've had problems sending locations via DDMS using Windows XP and regional settings set to Swedish. Changing the regional settings to English(USA) solves the problem for me. I guess it has something to do with how numbers are formatted. With swedish settings numbers are formatted as 123 456 789,00 and with English(USA) as 123,456,789.00. Hope it helps
I had this problem and I resolve it by disabling the firewall,
hope it works for you.

Categories

Resources