我需要从SIM卡中检索IMEI号码和电话号码。我成功地从SIM卡中获得了IMEI号码。但未检索电话号码。使用电话管理器行号时显示为空。谁能知道其他一些想法来获取电话号码信息?我正在使用上面的代码:
如果(Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this,Manifest.Permission.ReadSms)!= Android.Content.PM.Permission.Granted && Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this,Manifest.Permission.ReadPhoneNumbers)!= Android.Content.PM.Permission.Granted && Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadPhoneState)!= Android.Content.PM.Permission.Granted && Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this,Manifest.Permission.AccessCoarseLocation)!= Android.Content.PM.Permission.Granted) { RequestPermissions(new String [] {Manifest.Permission.ReadPhoneState,Manifest.Permission.ReadPhoneNumbers,Manifest.Permission.ReadSms,Manifest.Permission.AccessCoarseLocation},PERMISSIONS_REQUEST_READ_PHONE_STATE);
}
else
{
setDeviceImei();
}
private void setDeviceImei() {
var tMgr = (TelephonyManager)Forms.Context.ApplicationContext.GetSystemService(Android.Content.Context.TelephonyService);
Console.WriteLine(tMgr.Line1Number);
//string deviceId = getDeviceID(telephonyManager,0);
//string deviceId1 = getDeviceID(telephonyManager, 1);
String imeiNumber1 = tMgr.GetDeviceId(0); //(API level 23)
String imeiNumber2 = tMgr.GetDeviceId(1);
Console.WriteLine(imeiNumber1, imeiNumber2);
SubscriptionManager smgr = (SubscriptionManager)GetSystemService(TelephonySubscriptionService);
SubscriptionInfo sim1 = smgr.GetActiveSubscriptionInfoForSimSlotIndex(0);
SubscriptionInfo sim2 = smgr.GetActiveSubscriptionInfoForSimSlotIndex(1);
Console.WriteLine(sim1);
Console.WriteLine(sim2);
}
[您必须记住,Xamarin移动开发基本上是使用C#进行的本机开发,因此,与以本机语言(iOS的Obj-C,Android的Java)构建应用程序的开发人员一样,您也受到类似的限制。
iOS
Apple具有非常强大的隐私实现,因此它们不允许应用程序“窃取”可以唯一地属于设备/用户的任何信息。因此,无法直接从设备获取IMEI number或Phone Number。您可以在测试过程中使用“私有API”来获取它,但是该应用将在审核过程中被拒绝,因此无用。
但是,有一种“合法”的方式来捕获电话号码,而没有任何尚未阻止的用户数据输入,例如described here:
想法是让该应用以编程方式将SMS消息发送到 带有应用程序唯一安装代码的服务器。然后,该应用可以查询 同一台服务器,以查看它最近是否收到来自 具有此唯一应用程序安装代码的设备。如果有,它可以 阅读发送它的电话号码。这是显示过程的demo video。尽你所能 瞧,它就像一个魅力!
Android
//正在进行的答案,保存至今,不会被删除
这有什么用例?我也许可以为您提供更好的解决方案。