i have a service to get Current Sim Serial and detect whether second sim card is inserted. So i would like to store the first sim card when the service run, Does anyone can tell me which way i can use to store integer value(sim serial).
When the second sim card inserted(after device reboot), i would like to compare the stored sim and current sim, if so detected then do something.
So basically i just want to write a sim card value to storage.
For store integer value(sim serial) You Should Use Android Preferences .
For More Refer these Links
http://developer.android.com/reference/android/preference/package-summary.html
http://viralpatel.net/blogs/android-preferences-activity-example/
http://www.javacodegeeks.com/2011/01/android-quick-preferences-tutorial.html
If you really are in for security id rather suggest using a PaaS like heroku and using your own web application to store that. Anyone can just erase the data from your application and have it think it is its first time running,
Related
How can I programmatically change the country & network of an Android phone's SIM without root access? I'm using this code to retrieve information:
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
System.out.println(tm.getSimCountryIso()); // prints 'us', but I want it to be 'fr'
System.out.println(tm.getNetworkCountryIso()); // prints 'us, but I want it to be 'fr'
As my SIM card is from the USA, both of the outputs are us. How can I programmatically make the output be fr (France) for example?
Basically, I want to trick my smartphone into thinking its SIM's country & network is France, for example.
Something like this would be perfect but it doesn't exist:
tm.setSimCountryIso('fr')
tm.setNetworkCountryIso('fr')
What you are asking for is not possible without root.
As already stated in the comments, it is not physically possible to change the ICCID of the SIM unless it is a special writable SIM.
As for the call to getSimCountryIso and getNetworkCountryIso() those are system API's.
Without root, there is no way to interfere with their operation.
Android is built with several layers of security including restricting app access based on user privileges, enforcing SELinux on by default, verity checks as part of verified boot and more.
If you do have root on device, you can create an Xposed framework module that can hook these functions and overwrite their return value.
If you are curious, the table used to translate ICCID info into a two letter country name is hardcoded here.
In case that link does not open right - it starts on line 316.
So changing that would require recompiling one of the core JARs of the OS.
Also note, that depending on your real purpose, altering the result of these two functions may not work at all.
For example, if you want to create a Google account from the phone for a different country, changing the SIM will not help, since Google will still look at your IP address, regardless of how you are connected to the internet.
I am able to retrieve contacts and all of their information, but in the Contact list I do not see "ME". I read that this was not supported, but t there was a ticket to Android about this (back in 2011?).
Is it possible to retrieve MY contact card in Android?
No, because you don't have one unless the user added one. Even if there is one, there's no promise of any actual data on it. Not even phone number, since its possible for a phone to not know its own phone number.
This question already has answers here:
Programmatically obtain the phone number of the Android phone
(22 answers)
Closed 9 years ago.
I want to get mobile number of own mobile, for add this part to my application .
I'm searching about this question ,
code is correct on emulator but in device show empty.
public String getMyPhoneNumber()
{
return ((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
.getLine1Number();
}
and :
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
But is it returning empty value. So How can I fetch the phone number detail ?
The method you are using is the only one part of the SDK to do this, and only works on devices where the number is stored on the SIM card, which only some carriers do. For all other carriers, you will have to ask the user to enter the phone number manually, as the number is simply not stored anywhere on the device from where you can retrieve it.
Answer from: Programmatically obtain the phone number of the Android phone
"There is no guaranteed solution to this problem because the phone number is not physically stored on all SIM-cards, or broadcasted from the network to the phone. This is especially true in some countries which requires physical address verification, with number assignment only happening afterwards. Phone number assignment happens on the network - and can be changed without changing the SIM card or device (e.g. this is how porting is supported).
I know it is pain, but most likely the best solution is just to ask the user to enter his/her phone number once and store it."
Your code should be fine, but you need the SIM card to be inserted in the phone. Also, as autocrat noted, if the number is not stored on sim card, you will get an empty string.
EDIT: Also, please check the link provided by Pontus Backlund, there's some good info there.
Go to setting -> about device -> status -> my phone number if my phone number is unknown u won't get mobile number.. because some of the mobile network won't give mobile number..
if my mobile number has number u can get mobile through following code
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
phoneNumber = tManager.getLine1Number();
I am creating a java application to receive messages on pc using jsms API. Whenever a user sends a particular message to a no, it receives it and adds to the database, the phone number and the area/ region where it belongs.
The region can either be the area where the phone number is registered, or it can also be the current location of the device. Either of these information will help me.
I would be really glad if any one could any one guide me on how to proceed with finding out the region using java code.
Note: I'm not looking for the country. I'm looking for the state/ region. Preferable Indian states.
You could try out libphonenumber. It basically defines the region based on the number.
There is a JavaScript try page here you could perform some tests.
I want to know if I can rely on the telephony values like country, MCC, etc on Android for my app. Can I change them on the run using setprop? I tried changing using setprop it didn't seem to work. From my understanding telephony manager is a class/interface which represents Hardware configuration of GSM or CDMA. In case of GSM this could be sim and in case of CDMA it cud be a hardware. My questions are:
Who update these values in both the cases for the first time?
Are these values are saved by OS as read only?
What if a user travels to different country or zone will some of the values like country code and MCC values updated automatically?
Can I reset these values?
I have no intention of changing any of these values but want to understand its working! I would appreciate if someone can help me on this.
According to android documentation
Provides access to information about the telephony services on the
device. Applications can use the methods in this class to determine
telephony services and states, as well as to access some types of
subscriber information. Applications can also register a listener to
receive notification of telephony state changes.
TelephonyManager is used for reading phone information. Regarding your question about MCC & MNC codes: yes, they will change when phone will be in other country. You can subscribe to receive those events and determine that user now in different country.
#Bo
The way CDMA works is different from GSM. CDMA has always got one home base and many visitor base location. and you can always get to know about visitor Operator using TelephonyManager methods which is considered as unreliable for CDMA.
I decided to add it as answer as well...
I found a way to tackle this problem on CDMA phone.. if it is a CDMA phone , then the phone always has an ICC hardware comparable to SIM cards in GSM. All you gotta do is use the system properties associated with the hard ware . Programmatically you can use Java reflection to get this information . This is not changeable even system is rooted unlike GSM device. Class c=Class.forName("android.os.SystemProperties"); Method get = c.getMethod("get", String.class); String homeOperator = ((String) get.invoke(c, "ro.cdma.home.operator.numeric"));