- Home /
Get Phone number of android mobile device - Android native code to Unity c#
Hi, everyone. I am working on integration that will allow users to pay for in-game items using their credit and i need their phone numbers as part of the authentication process. I know that I need to do the following in android native code to get the phone number
Code
TelephonyManager telephonyManager (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String mMobileNo = telephonyManager.getLine1Number();
Add following permission in AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
But how do I implement this in unity? Any help would be amazing thanks.
Answer by lgarczyn · Oct 04, 2019 at 11:15 PM
First, you would need to request the permission of the user:
https://docs.unity3d.com/Manual/android-RequestingPermissions.html
Some people have successfully obtained the Android TelephonyManager data from Unity: https://forum.unity.com/threads/solved-android-library-plugin-and-getsimserialnumber.344084/
However, this requires mixing java and unity, and is in general an invasive technique, that will displease users with multiple phone numbers.
Just ask the damn user for their phone numbers.
Answer by Anaxis_Studio · Oct 04, 2019 at 08:11 PM
Unity IAP should handle all of your needs but it might not be straight forward if this is your first time implementing custom IAPs via Unity.
"With Unity IAP, setting up in-app purchases across iOS, Mac, Google Play, Windows and other app stores has never been easier. You can enable in-app purchases across multiple stores with a single unified API. Once enabled, you get the insight you need to fully understand and optimize your in-game economy."
https://docs.unity3d.com/Manual/UnityIAP.html
https://unity3d.com/unity/features/iap
https://docs.unity3d.com/Manual/UnityAnalyticsReceiptVerification.html
https://docs.unity3d.com/Manual/UnityAnalyticsMonetization.html
Answer by ahere · Oct 04, 2019 at 09:13 PM
Thanks for the reply but I have already integrated unity IAP. What we are working on is a solution for, markets with low credit card penetration. Let me know if you have any insight on how to implement what I asked
You answered your own post. What you were trying to do was comment on the other answer.