Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Make the method as public static which you are going to access from another activity. then call it as activity1.sendsms(); </p> <p>This is the way . if you post the code will advice you better way... hope this will help you .</p> <p><strong>Hi use the below code. the thing is you need to use Context.</strong> </p> <pre><code>import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.widget.Toast; public class SendingSms extends Activity { static Context context; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); context=this; } public static void sendSMS(String telNo, String mesaj) { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent(SENT), 0); PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent(DELIVERED), 0); context.registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent arg1) { // TODO Auto-generated method stub switch(getResultCode()) { case Activity.RESULT_OK: Toast.makeText(context, "SMS Gönderildi",Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(context, "Generic failure",Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(context, "No service",Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(context, "Null PDU",Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(context, "Radio off",Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(SENT)); context. registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(context, "SMS iletildi", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(context, "SMS iletilemedi", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(DELIVERED)); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(telNo, null, mesaj, sentPI, deliveredPI); Toast.makeText(context, telNo.toString() + " - " + mesaj.toString(), Toast.LENGTH_LONG).show(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload