Este es mi error:
{Java.Lang.SecurityException: Sending SMS message: uid 10249 does not have
android.permission.SEND_SMS.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c]
in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod
(Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo
method,
Java.Interop.JniArgumentValue* args) [0x00069] in
<6cd960837cc24c26bab2a0a29b597627>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeAbstractVoidMethod
(System.String encodedMember, Java.Interop.IJavaPeerable self,
Java.Interop.JniArgumentValue* parameters) [0x00014] in
<6cd960837cc24c26bab2a0a29b597627>:0
at Android.Telephony.SmsManager.SendTextMessage (System.String
destinationAddress, System.String scAddress, System.String text,
Android.App.PendingIntent sentIntent, Android.App.PendingIntent
deliveryIntent) [0x000ae] in <952e88faf9b94435845932f104eb293a>:0
at LoginSystem.Autorizacion.MBtnEnviar_Click (System.Object sender,
System.EventArgs e) [0x000c0] in C:\Users\Lenovo\documents\visual studio
2017\Projects\LoginSystem\LoginSystem\Autorizacion.cs:182
--- End of managed Java.Lang.SecurityException stack trace ---
java.lang.SecurityException: Sending SMS message: uid 10249 does not have
android.permission.SEND_SMS.
at android.os.Parcel.readException(Parcel.java:1602)
at android.os.Parcel.readException(Parcel.java:1555)
at com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber(ISms.java:860)
at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:319)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:298)
at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:30)
at android.view.View.performClick(View.java:5264)
at android.view.View$PerformClick.run(View.java:21297)
at android.os.Handler.handleCallback(Handler.java:743)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5621)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
}
código clase:
using System;
using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using Android.Content;
using Java.IO;
using Android.Provider;
using System.IO;
using Uri = Android.Net.Uri;
using System.Net;
using System.Net.Mail;
using System.Linq;
using Android.Content.PM;
using Android.Telephony;
using Android;
namespace LoginSystem
{
public class OnAutorizacionEventArgs
{
public string mTxtCedula;
public string mTxtFirstName;
public string mTxtFirst;
public string mTxtEmail;
public string mTxtCelular;
public string mTxtTelefono;
public string Cedula
{
get { return mTxtCedula; }
set { mTxtCedula = value; }
}
public string Nombre
{
get { return mTxtFirstName; }
set { mTxtFirstName = value; }
}
public string Apellido
{
get { return mTxtFirst; }
set { mTxtFirst = value; }
}
public string Email
{
get { return mTxtEmail; }
set { mTxtEmail = value; }
}
public string Celular
{
get { return mTxtCelular; }
set { mTxtCelular = value; }
}
public string Telefono
{
get { return mTxtTelefono; }
set { mTxtTelefono = value; }
}
public void Dialog_Autorizacion() { }
public void SDialog_Autorizacion(string cedula, string nombre, string email, string telefono, string celular)
{
this.Cedula = celular;
this.Nombre = nombre;
this.Email = email;
this.Celular = celular;
this.Telefono = telefono;
}
public OnAutorizacionEventArgs(string cedula, string nombre, string email, string telefono, string celular)
{
this.Cedula = celular;
this.Nombre = nombre;
this.Email = email;
this.Celular = celular;
this.Telefono = telefono;
}
}
public class Autorizacion : DialogFragment
{
private string MSJTOMARgaleria = "Por favor reucuerda tomar primero la foto de la Autorizacion";
private string MSJTEnvioExitoso = "Tu solicitud Esta En proceso, muy pronto te dare una respuesta";
private EditText mTxtInstitucion;
private string mTxtCedula;
private string mTxtNombre;
private EditText mTxtCiudad;
private ImageView imageView;
private Button Adjuntar;
private Button Enviar;
private View textView;
System.String uris;
private string mTxtApellido;
public Autorizacion(string mTxtNombre, string mTxtCedula)
{
this.mTxtNombre = mTxtNombre;
this.mTxtCedula = mTxtCedula;
}
public Autorizacion(string mTxtNombre, string mTxtApellido, string mTxtCedula) : this(mTxtNombre, mTxtCedula)
{
this.mTxtApellido = mTxtApellido;
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
textView = inflater.Inflate(Resource.Layout.Autorizaciones, container, false);
textView.FindViewById<TextView>(Resource.Id.txtAutoNombre).Text = mTxtNombre + mTxtApellido;
textView.FindViewById<TextView>(Resource.Id.txtAutoCedula).Text = mTxtCedula;
textView.FindViewById<TextView>(Resource.Id.txtNota).Text = MSJTOMARgaleria;
imageView = textView.FindViewById<ImageView>(Resource.Id.ImgMostrarFotos);
Adjuntar = textView.FindViewById<Button>(Resource.Id.btnCamara);
Enviar = textView.FindViewById<Button>(Resource.Id.btnEnviar);
Enviar.Visibility = ViewStates.Invisible;
imageView.Visibility = ViewStates.Invisible;
Adjuntar.Click += MBtnAdjuntar_Click;
Enviar.Click += MBtnEnviar_Click;
return textView;
}
private void MBtnAdjuntar_Click(object sender, EventArgs e)
{
var imageIntent = new Intent();
imageIntent.SetType("image/*");
imageIntent.SetAction(Intent.ActionGetContent);
StartActivityForResult(Intent.CreateChooser(imageIntent, "Select photo"), 0);
}
private void MBtnEnviar_Click(object sender, EventArgs e)
{
if (mTxtInstitucion.Text.Equals("")|| mTxtCiudad.Text.Equals(""))
{
Toast.MakeText(Activity, "has dejado Institución o Ciudad vacia", ToastLength.Short).Show();
}
else
{
try
{
//Configurando el cliente SMTP
SmtpClient client = new SmtpClient()
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("[email protected]", "jwspvnzutniimvkm")
};
//Preparando archivo adjunto
var filePath = System.IO.Path.Combine(uris, "");
var File = new Java.IO.File(filePath);
var path = Uri.FromFile(File);
//Enviando correo
MailMessage mail = new MailMessage()
{
From = new MailAddress("[email protected]")
};
mail.To.Add(new MailAddress("[email protected]"));
mail.Subject = "Solicitud Autorizacion Medica " + mTxtNombre + " " + mTxtApellido + "" + mTxtCedula;
mail.IsBodyHtml = true;
mail.Body = "Hola Solicito por favor autorizar procedimiento, adjunto anexo solicitud Medica especificaciones el nombre de la Institución es " + mTxtInstitucion.Text +
" , ciudad " + mTxtCiudad.Text + " ,Nombre de usuario " + mTxtNombre + " " + mTxtApellido + " y Cedula " + mTxtCedula +
" " + "Gracias por su atención"
;
mail.Attachments.Add(new Attachment(File.Path));
client.Send(mail);
textView.FindViewById<TextView>(Resource.Id.txtNota).Text = MSJTEnvioExitoso;
Enviar.Visibility = ViewStates.Invisible;
imageView.Visibility = ViewStates.Invisible;
textView.FindViewById<TextView>(Resource.Id.txtAutoCiudad).Text = "";
textView.FindViewById<TextView>(Resource.Id.txtAutoInstitucion).Text = "";
SmsManager.Default.SendTextMessage("57301111111", null,
"Hello from Xamarin.Android", null, null);
var smsUri = Android.Net.Uri.Parse("smsto:57301111111");
var smsIntent = new Intent(Intent.ActionSendto, smsUri);
smsIntent.PutExtra("sms_body", "Hello from Xamarin.Android");
StartActivity(smsIntent);
}
catch (Exception ex)
{
Toast.MakeText(Activity, "Mensaje Fallido"+ex, ToastLength.Short).Show();
}
}
}
public override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == Result.Ok)
{
imageView = textView.FindViewById<ImageView>(Resource.Id.ImgMostrarFotos);
imageView.SetImageURI(data.Data);
imageView.Visibility = ViewStates.Visible;
uris = GetPathToImage(data.Data);
Enviar.Visibility = ViewStates.Visible;
mTxtInstitucion = textView.FindViewById<EditText>(Resource.Id.txtAutoInstitucion);
mTxtCiudad = textView.FindViewById<EditText>(Resource.Id.txtAutoCiudad);
textView.FindViewById<TextView>(Resource.Id.txtNota).Text = "";
}
}
private string GetPathToImage(Uri uri )
{
string doc_id = "";
using (var c1 = Application.Context.ContentResolver.Query(uri, null, null, null, null))
{
c1.MoveToFirst();
System.String document_id = c1.GetString(0);
doc_id = document_id.Substring(document_id.LastIndexOf(":") + 1);
}
string path = null;
string selection = MediaStore.Images.Media.InterfaceConsts.Id + " =? ";
using (var cursor = Application.Context.ContentResolver.Query(MediaStore.Images.Media.ExternalContentUri, null, selection, new string[] { doc_id }, null))
{
if (cursor == null) return path;
var columnIndex = cursor.GetColumnIndexOrThrow(MediaStore.Images.Media.InterfaceConsts.Data);
cursor.MoveToFirst();
path = cursor.GetString(columnIndex);
}
return path;
}
private void TextBox1_Leave(object sender, System.EventArgs e)
{
if (mTxtInstitucion.Text != String.Empty && mTxtCiudad.Text != String.Empty)
{
//Significa que hay texto en tus 3 txt
Adjuntar.Enabled = true; //activas tu boton
}
}
public override void OnActivityCreated(Bundle savedInstanceState)
{
Dialog.Window.RequestFeature(WindowFeatures.NoTitle);
base.OnActivityCreated(savedInstanceState);
Dialog.Window.Attributes.WindowAnimations = Resource.Style.dialog_animation;
}
}
}
manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="LoginSystem.LoginSystem" android:versionCode="1"
android:versionName="1.0" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAG" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-feature android:name="android.hardware.telephony"/>
<application android:label="Mi Asesor" android:icon="@drawable/Icon"
android:theme="@drawable/ic_green_button"></application>
</manifest>