I am working on authentication procedure and the best that I found is this link. This matches to my app needs perfectaly.
But problem that I am facing is that , after doing described steps, I get a phone number picker dialog shown ad hidden and I get reply in onActivityResult callback as a canceld result and with empty data.
I do not know why that dialog closes it self not letting the user to choose the phone number and it returned it self in the OnActivityResult with canceled result code.
Please help me , I am stuck in it and I have no clue to go in that direction with.
I think its the problem of SIM. Some sim card allow this and some not. I will suggest you to do testing on real device. And change your sim card to ensure it must not be the carrier problem.
I have the same issue and then I changed SIM card and that codes start working for me. And that was really amazing to notice that it was not working from all sim cards. I am from India. Hope so it will be helpful for any Asian developer.
I have exactly same issue with this.
On some phone(even if it is brand new phone), phone number dialog is appeared and dismissed quickly.
And then credential id is returning null value.
onActivityResult
val credential: Credential? = data.getParcelableExtra(Credential.EXTRA_KEY)
var phoneNumber = credential?.id
if (phoneNumber == null) {
val tMgr = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
phoneNumber = tMgr.line1Number
}
I try to find a reason but failed. Instead, I use telephonyManager in this exceptional case. This is still not a good solution because user should see abnormal behavior and also should agree with phone permission. I also think this is related with SIM card.
Related
I have recently created an app which required certain security majors.
One of which is that we need to stop the dialog coming from Google when a user logs into the app.
The main thing is that password gets saved in google chrome.
When a user comes to app again it shows options for the user to autologin with usernames in a list and adds password automatically so anyone gets access to the phone can log into the app and can steal the data.
Currently, this issue is found in only one One Plus 5 device.
I want to stop this programmatically.
Any help would be appreciated,
Thanks
Update:
Thanks, Flyzzx, because of your reply I searched for android autofill and found out that it was introduced in Oreo to autofill data.
But when on the login screen it detects the username/password combo and prompts you for password save.
The solution to this is:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AutofillManager autofillManager = getSystemService(AutofillManager.class);
autofillManager.disableAutofillServices();
editText.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
}
Here, only autofillManager.disableAutofillServices(); is also sufficient but on some devices, you should also add editText.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO); this to work.
You have to do this for all edittexts which you don't want to get auto-filled.
Hope It will help others like me.
I am currently using the following code to obtain the current user name:
String username;
{
Cursor c = ctx.getContentResolver().query(Profile.CONTENT_URI,
new String[]{Profile.DISPLAY_NAME}, null, null, null);
if (c.getCount() > 0)
{
c.moveToFirst();
username = c.getString(0);
}
On my test device (Samsung Galaxy Tab Pro), with the correct permissions, this works well for the "owner" user, as well as other non-restricted users. However, things seem to fall apart for limited user profiles:
The code always returns zero cursor rows. I had hoped that enabling access to the Contacts app would allow it to work, but that has no effect.
At any rate, unlike non-limited profiles, the profile of the limited user account does not seem to be connected to the name displayed on the lock screen, so even if I could get this code to work I'm not sure how useful it would be.
Please forgive the multi-part question, but:
Is this a peculiarity of the Samsung tablet, or is this behavior consistent across devices?
Is there any way to read the profile of a limited user?
Is there a better way to obtain the current user name?
Any insight appreciated.
I have tried to search about it & can say it's not possible to get details of "Restricted Profile (User)".
In background when you try to read details for "Restricted Profile user" they are trying to change in database and throw SQLiteexception : delete then re-write existing database throws SQLiteReadOnlyDatabaseException on getWritableDatabase. due to this exception I don't think there is chance to read user name.
Without use your above code you can get directly call getUsername() of UserManager class.[API Level 17]
I am working on an APP using Xamarin MonoTouch, this App requires custom licence key as provided by us. To identify each and every installation we have to store some kind of device information to control misuse of App.
After trying various ways, now the problems are:
Device Id or Android id : gets changed every time a device is factory reset or format.
Settings.System.GetString(this.ContentResolver, Settings.Secure.AndroidId);
IMEI Number: No SIM Tabs dont have. Double SIM phones have no fix slot wise imei and sends randomly chose one.
var telephonyManager = (TelephonyManager)GetSystemService(TelephonyService);
string imei = telephonyManager.DeviceId;
WIFI Mac Address: Good way but some sets like HTC and Chinese ones throwing exception while retrieving mac address, but works some time. SO not getting fix id everytime app starts.
WifiManager wm = (WifiManager)GetSystemService(WifiService);
string macid = wm.ConnectionInfo.MacAddress;
So everytime any of the above ID fails, user needs to re register app again and again. Do we have any fool proof way of doing this?
Ok, as per comment by Matt, since there is not fool-proof method of getting unique id from an android device. So I have made a provision of validating installations against WIFI Mac ID and Android ID both. If any one of these found matched then installation is genuine or spoofed.
i am developing the application in which user mobile no and international country code should be set automatically on the basis of SIM card provider.
i.e if i install this application in first page country code and my phone no should be filled automatically.i want this result as my output.
i have done this using static code but i want to do dynamically.if user uses this application then country code and mobile no should be selected automatically.
i have searched on net but there is not a exact answer of this question.
I have seen the application in which they are doing this thing so how they are doing?
Thanks
There is also one library which will helpful to you for validate user entered Phone number
as
http://code.google.com/p/libphonenumber/
Here is the code snippet that will help you in getting the phone number:
TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = tMgr.getLine1Number();
Don't forget to include READ_PHONE_STATE permission in manifest file.
I have to make an application which shows the contact no of the SIM card that is being used in the cell. For that I need to use TelephonyManager class. Can I get details on its usage?
You can use the TelephonyManager to do this:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String number = tm.getLine1Number();
The documentation for getLine1Number() says this method will return null if the number is "unavailable", but it does not say when the number might be unavailable.
You'll need to give your application permission to make this query by adding the following to your Manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
(You shouldn't use TelephonyManager.getDefault() to get the TelephonyManager as that is a private undocumented API call and may change in future.)
Hi Actually this is my same question but I didn't get anything.Now I got mobile number and his email-Id from particular Android real device(Android Mobile).Now a days 90% people using what's App application on Android Mobile.And now I am getting Mobile no and email-ID Through this What's app API.Its very simple to use see this below code.
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccounts();
for (Account ac : accounts)
{
acname = ac.name;
if (acname.startsWith("91")) {
mobile_no = acname;
}else if(acname.endsWith("#gmail.com")||acname.endsWith("#yahoo.com")||acname.endsWith("#hotmail.com")){
email = acname;
}
// Take your time to look at all available accounts
Log.i("Accounts : ", "Accounts : " + acname);
}
and import this API
import android.accounts.Account;
import android.accounts.AccountManager;
I have to make an application which shows the Contact no of the SIM card that is being used in the cell. For that I need to use Telephony Manager class. Can i get details on its usage?
Yes,
You have to use Telephony Manager;If at all you not found the contact no. of user;
You can get Sim Serial Number of Sim Card and Imei No. of Android Device by using the same Telephony Manager Class...
Add permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Import:
import android.telephony.TelephonyManager;
Use the below code:
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
imei = tm.getDeviceId();
// get SimSerialNumber
simSerialNumber = tm.getSimSerialNumber();
Well, all could be temporary hacks, but there is no way to get mobile number of a user. It is against ethical policy.
For eg, one of the answers above suggests getting all accounts and extracting from there. And it doesn't work anymore!
All of these are hacks only.
Only way to get user's mobile number is going through operator. If you have a tie-up with mobile operators like Aitel, Vodafone, etc, you can get user's mobile number in header of request from mobile handset when connected via mobile network internet.
Not sure if any manufacturer tie ups to get specific permissions can help - not explored this area, but nothing documented atleast.
Sometimes you can retreive the phonenumber with a USSD request to your operator.
For example I can get my phonenumber by dialing *116#
This can probably be done within an app, I guess, if the USSD responce somehow could be catched.
Offcourse this is not a method I would recommend to use within an app that is to be distributed, the code may even differ between operators.
As many said:
String phoneNumber = TelephonyManager.getDefault().getLine1Number();
The availability depends strictly on the carrier and the way the number is encoded on the SIM card. If it is hardcoded by the company that makes the SIMs or by the mobile carrier itself. This returns the same as in Settings->about phone.