Android: Get MY Contact info - java

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.

Related

Is there a way to access the 'hide my phone number' (caller ID) function with code in Android studio?

When you dial a phone number (on your Android phone), the person being called can see your phone number.
If you do not wish that, you can hide your phone number for outgoing calls from your phone by activating the corresponding feature.
Is there a way to access (toggle) this caller ID feature (hide/show) with code? I searched on the Internet but couldn't find anything.
And of course, if it is possible, what would be the code/method to do so?

How to put additional Information to Arraylist which is used for ListView wirhout showing the additional Information

I made an activity which reads all my contacts and put the names into an Arraylist. This ArrayList is used to fill up my ListView. If I'll click on an item in this ListView the app will search in my contacts for the name and start an Activity with putting the name and number through intent.putExtra. The Chat is stored with tinyDB (https://github.com/kcochibili/TinyDB--Android-Shared-Preferences-Turbo/blob/master/TinyDB.java) which takes the phonenumber as the key.
All works fine but one scenario breaks this concept. If I have one contact with multiple phone numbers and I'll click on him in the ListView my code is going to search for the name in my contacts and take this number to start the chat. So the chat will be started with the phone number of the contact which my code will find first every time. So it is impossible to start the chat activity with the second phone number.
So I thought I should put the phone number into the arraylist too but then they will shown up in the ListView.
Some advices?
You have a couple of bad assumptions there, note the following:
A contact may have zero, one or multiple phones, and you need to handle all 3 cases.
A contact name is not unique, and you may have 2 or more "John" in your contacts list.
A phone number may be stored within more then one contact (think of a home phone number that is shared between a married couple)
When passing around search keys between your different activities, you must use a unique identifier that identified exactly the selected item, like a Contact-ID, or a position in the list.
In your main list two options come to mind:
either show a list item per phone and not per contact,
or when a contact is clicked and it has more then one phone, show an AlertDialog asking the user to select which phone to use.
if you are making a chat application this answer might help.
how do apps like whatsapp show contacts that are only using app
To keep it simple You can do it fetch the contacts in the background using Async
Read more about async here.
Async Task
Normalize the number you can use googlelibphoneLib to do so.
Google Lib Phone Number
and save them in SQLite.

How get my phone number on android using CallLog

In my app I'm using CallLog's and I'm getting data of calls. I can receive all data, but there is no information about my number phone. How can I receive this information? getLine1Number() from TelephonyManager return empty string..
To get the phone number from the device , first you have to set your own phone number on the device, just through :
Settings -> About Phone -> Status -> My phone Number
Phone numbers are not available on SIM for each operators, like in india Sim dont have phone numbers in any memory, So WE cant get phone number from these connection. However, some countries, and operators have stored phone numbers on SIM, and we can get those.
Yes. This is because not all operators support retrieving phone number from the SIM card. There is no fail-safe way to always retrieve the phone number through your app. Your best bet is to ask the user to enter their phone number into the app and then save it to shared preferences or something.
It depends on Mobile Operator. In India Airtel support this feature.

How to get mobile number phone on android 4.1.2 ? [duplicate]

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();

Android Service to store Sim Card serial

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,

Categories