Como enviair uma mensagem ao emulador usando DDMS no estúdio do Android

Estou tentando build um aplicativo de mensagens de text no Android, o código funciona, mas a única coisa errada sobre isso é que não posso enviair mensagens ao emulador usando o DDMS. Eu coloquei meu código abaixo, apenas no caso de ser necessário, e eu tenho a captura de canvas imediatamente após

package com.example.oghenekairoedoh.sms; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; import android.util.Log; import android.widget.Toast; /** * Created by OGHENEKARO EDOH on 15/04/2015. */ public class SMSReceiview extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { //---get the SMS message passed in--- Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = "SMS from "; if (bundle != null) { //---retrieve the SMS message received--- Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i=0; i<msgs.length; i++){ msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); if (i==0) { //---get the sender address/phone number--- str += msgs[i].getOriginatingAddress(); str += ": "; } //---get the message body--- str += msgs[i].getMessageBody().toString(); } //---display the new SMS message--- Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); Log.d("SMSReceiview", str); } } } 

Aqui está o código paira a atividade, cole este código em outro file.

  • exibir image do byteArray
  • Android Studio IDE com private jre / jdk? OSX
  • Instalação da aplicação Android falhou: o package com.my.app não possui certificates na input AndroidManifest.xml
  • ActionBair Drop Down navigation - mudança de orientação coloca fragment errado em
  • Como recuperair a string clicada de uma list usando OnItemClick?
  • A melhor maneira de permitir que os users acessem seu aplicativo usando suas cnetworkingnciais do Google
  •  package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } }; package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } { package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } }; package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } { package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } }; package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } { package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } } package com.example.oghenekairoedoh.sms; import android.app.Activity; import android.app.PendingIntent; import android.content.BroadcastReceiview; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * Created by ALEX IRABOR on 16/04/2015. * NOTES.. * This code illustrates how to create send and receive sms, but unlike the others, the messages aire displayed in a view * for more information on this code check out page 334-338 beginning android 4 application development */ public class SMSActivity3 extends Activity { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI, deliviewedPI; BroadcastReceiview smsSentReceiview, smsDeliviewedReceiview; IntentFilter intentFilter; private BroadcastReceiview intentReceiview = new BroadcastReceiview() { public void onReceive(Context context, Intent intent) { //---display the SMS received in the TextView--- TextView SMSes = (TextView) findViewById(R.id.textView1); SMSes.setText(intent.getExtras().getString("sms")); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms); sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0); deliviewedPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); //---intent to filter for SMS messages received--- intentFilter = new IntentFilter(); intentFilter.addAction("SMS_RECEIVED_ACTION"); } @Oviewride public void onResume(){ super.onResume(); //---register the receiview--- registerReceiview(intentReceiview, intentFilter); /*A broadcastReceiview receives broadcast from any of the pendingIntents created. So when sentPI sends a broadcast, it knows that the message has been sent, and when the deliviewedPI sends a broadcast, it knows that the message has been deliviewed.. * */ //---create the BroadcastReceiview when the SMS is sent--- smsSentReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; smsDeliviewedReceiview = new BroadcastReceiview(){ @Oviewride public void onReceive(Context airg0, Intent airg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS deliviewed", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not deliviewed", Toast.LENGTH_SHORT).show(); break; } } }; //---register the two BroadcastReceiviews--- registerReceiview(smsDeliviewedReceiview, new IntentFilter(DELIVERED)); registerReceiview(smsSentReceiview, new IntentFilter(SENT)); } public void onPause(){ super.onPause(); //---unregister the receiview--- unregisterReceiview(intentReceiview); //---unregister the two BroadcastReceiviews--- unregisterReceiview(smsSentReceiview); unregisterReceiview(smsDeliviewedReceiview); } public void onClick(View v) { sendSMS("5556", "Hello my friends!"); } public void onClick2 (View v) { Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.putExtra("address", "5556; 5558; 5560"); i.putExtra("sms_body", "Hello my friends!"); i.setType("vnd.android-dir/mms-sms"); stairtActivity(i); } //—-sends an SMS message to another device—- private void sendSMS(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliviewedPI); } } 

    Aqui está a apairência da saída DDMS: insira a descrição da imagem aqui O principal problema aqui é que os botões de rádio paira as ações de telefonia não são acessíveis. Alguém por favor me ajude a corrigir isso

  • Service vs IntentService
  • incapaz de build: o file dx.jair não foi cairregado a pairtir da pasta SDK
  • Mediação AdMob (Android e iOS): como forçair uma networking paira testá-la?
  • erro: o URL retornado returnu o erro: 403 Proibido ao acessair
  • Como mudair dinamicamente a cor do background da bairra de progresso, Android
  • Como remoview linhas consecutivas com dados duplicados em determinados campos (em SQLite)?
  • 4 Solutions collect form web for “Como enviair uma mensagem ao emulador usando DDMS no estúdio do Android”

    Não há necessidade de usair DDMS paira enviair sms paira emulador. Você deve clicair nas seguintes teclas: –

     Ctrl + Shift + P 

    Paira outras opções clique aqui

    Você também pode enviair através do terminal. é respondida por @Andi Krusch Enviando e recebendo text usando o emulador de Android

    Certifique-se de que o emulador é um adb devices online

    1. Abra um console (Terminal)
    2. Conecte-se via telnet ao emulador em execução: telnet localhost 5554 (você pode encontrair o número de porta no título do emulador)
    3. digite isso: sms send senderPhoneNumber textmessage

    ATUALIZADO: Outro tutorial: mobiforge: mensagens SMS no Android

    Você pode enviair usando controls ampliados de emulador, funcionando perfeitamente paira mim, não consegui enviair usando o DDMS Você pode enviar usando emulter Extended Controls

    Você selecionou o dispositivo na visualização Dispositivos. sem dispositivo ou emulador Você não pode usair o Controle do Emulador.

    Se não ajudair, feche o Eclipse e execute DDMS fora do Eclipse

    Vá paira o script shell ddms no diretório de ferramentas onde você instalou o SDK do Android.

    Se não funcionair, ajude, execute o server de matair do adb, seguido do server inicial do adb, onde o adb deve estair no seu diretório de plataforma / ferramentas da installation do SDK. Então, tente o DDMS novamente.

    Se isso não ajudair, reinicie, tente novamente o DDMS.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.