帮我任何代码!
提前致谢!
解决方法broadcastReceiver sendbroadcastReceiver = new SentReceiver(); broadcastReceiver deliverybroadcastRecIEver = new DeliverReceiver();; @OverrIDe protected voID onPause() { // Todo auto-generated method stub super.onPause(); try { unregisterReceiver(sendbroadcastReceiver); unregisterReceiver(deliverybroadcastRecIEver); } catch (Exception e) { // Todo auto-generated catch block e.printstacktrace(); } }@OverrIDeprotected voID onDestroy() { // Todo auto-generated method stub super.onDestroy(); try { unregisterReceiver(sendbroadcastReceiver); unregisterReceiver(deliverybroadcastRecIEver); } catch (Exception e) { // Todo auto-generated catch block e.printstacktrace(); }} send_sms.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub if (textVIEw.getText().toString().equals("") | textVIEw.getText().toString().equals(null)) { Toast.makeText(SendSMS.this,enter_ph_no,Toast.LENGTH_LONG) .show(); } else { sendSMS(textVIEw.getText().toString(),"sms_content"); finish(); } } });private voID sendSMS(String phoneNumber,String message) { String SENT = "SMS_SENT"; String DEliVERED = "SMS_DEliVERED"; PendingIntent sentPI = PendingIntent.getbroadcast(this,new Intent( SENT),0); PendingIntent deliveredPI = PendingIntent.getbroadcast(this,new Intent(DEliVERED),0); registerReceiver(sendbroadcastReceiver,new IntentFilter(SENT)); registerReceiver(deliverybroadcastRecIEver,new IntentFilter(DEliVERED)); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber,null,message,sentPI,deliveredPI); } class DeliverReceiver extends broadcastReceiver { @OverrIDe public voID onReceive(Context context,Intent arg1) { switch (getResultCode()) { case Activity.RESulT_OK: Toast.makeText(getBaseContext(),sms_delivered,Toast.LENGTH_SHORT).show(); break; case Activity.RESulT_CANCELED: Toast.makeText(getBaseContext(),sms_not_delivered,Toast.LENGTH_SHORT).show(); break; } } } class SentReceiver extends broadcastReceiver { @OverrIDe public voID onReceive(Context context,sms_sent,Toast.LENGTH_SHORT) .show(); startActivity(new Intent(SendSMS.this,ChooSEOption.class)); overrIDePendingTransition(R.anim.animation,R.anim.animation2); 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; } } }总结
以上是内存溢出为你收集整理的Android中的短信发送报告全部内容,希望文章能够帮你解决Android中的短信发送报告所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)