xamarin.android - Reading Sim Number in Dual Sim Phone Xamarin.Form -


im getting error of java.lang.securityexception: getline1numberfordisplay: neither user 10710 nor current process has android.permission.read_sms. if added read_sms in androidmanifest.xml

mycode:

public string getnumber() {     telephonymanager telephonymanager = (telephonymanager)getsystemservice(telephonyservice);     return telephonymanager.line1number; } 

thanks in advance , day :d

this really simple runtime permission request example.

i highly recommend reading xamarin blog post , android doc linked below should show user "why" requesting permission before system dialog shows up.

[activity(label = "runtimepermissions", mainlauncher = true, icon = "@mipmap/icon")] public class mainactivity : activity {     const int permissionsmsrequestcode = 99;      protected override void oncreate(bundle savedinstancestate)     {         base.oncreate(savedinstancestate);         setcontentview(resource.layout.main);          button button = findviewbyid<button>(resource.id.mybutton);         button.click += delegate {              if ((int)build.version.sdkint < 23) // permissions accepted user during app install                 dosomework();              var permission = basecontext.checkselfpermission(manifest.permission.readsms);             if (permission == android.content.pm.permission.granted) // did user grant permission?                 dosomework();             else // ask user allow/deny permission request                 requestpermissions(new string[] { manifest.permission.readsms }, permissionsmsrequestcode);         };     }      public override void onrequestpermissionsresult(int requestcode, string[] permissions, android.content.pm.permission[] grantresults)     {         base.onrequestpermissionsresult(requestcode, permissions, grantresults);         if (requestcode == permissionsmsrequestcode)         {             if ((grantresults.count() > 0) && (grantresults[0] == android.content.pm.permission.granted))                 dosomework();             else                 log.debug("perm", "the user denied access!");         }     }      protected void dosomework()     {         log.debug("perm", "we have permission, it");     } } 

enter image description here

ref: requesting runtime permissions in android marshmallow

ref: requesting permissions @ run time


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -