Permission send sms android -


i writing app send message inputted number through sms. when try send message error "user 10074 not have android.permission.send_sms" though have permission in manifest.

      try {                   smsmanager smsmanager = smsmanager.getdefault();                 smsmanager.sendtextmessage("5554", null, "hello", null, null);               //  smsmanager.sendtextmessage(number,null,matn,null,null);                  toast.maketext(sms.this, "ok", toast.length_long).show();             } catch (exception e) {                 toast.maketext(sms.this, "error"+e, toast.length_long).show();                    }         }     }); 

and code in manifest

 <uses-permission android:name="android.permission.send_sms" /> 

beginning in android 6.0 (api level 23), users grant permissions apps while app running, not when install app.

try ask run time permission

requestsmspermission();  private void requestsmspermission() {     string permission = manifest.permission.read_sms;     int grant = contextcompat.checkselfpermission(this, permission);     if (grant != packagemanager.permission_granted) {         string[] permission_list = new string[1];         permission_list[0] = permission;         activitycompat.requestpermissions(this, permission_list, 1);     } }  @override public void onrequestpermissionsresult(int requestcode, @nonnull string[] permissions,                                        @nonnull int[] grantresults) {     super.onrequestpermissionsresult(requestcode, permissions, grantresults);     if (requestcode == 1) {         if (grantresults[0] == packagemanager.permission_granted) {                                             toast.maketext(accountclass.this,"permission granted", toast.length_short).show();           } else {             toast.maketext(accountclass.this,"permission not granted", toast.length_short).show();         }     }  } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -