我想使用短信管理器从Android应用程序发送短信

我想使用短信管理器从Android应用程序发送短信,第1张

概述我尝试过发送但短信会自动发送而不知道.我想发送短信与To字段从我的代码预定义,并可以获得内置的短信APP.我的守则holder.SMS.setOnClickListener(newOnClickListener(){@OverridepublicvoidonClick(Viewv){Log.e("sssssss"

我尝试过发送但短信会自动发送而不知道.我想发送短信与To字段从我的代码预定义,并可以获得内置的短信APP.

我的守则

holder.SMS.setonClickListener(new OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                Log.e("sssssss", "aaaaaaaa");                try {//                  VIEw vIEw = (VIEw) v.getParent();//                  TextVIEw number = (TextVIEw) vIEw.findVIEwByID(R.ID.phone);//                  String selected_mobile_sms = number.getText().toString();//                  Log.e("sssssss", "ssssssss" + selected_mobile_sms);                    // sendSMS();                    SmsManager sm = SmsManager.getDefault();                    sm.sendTextMessage("tel:121", null, "test message", null,                            null);//                      //                  //                   Intent sendIntent = new Intent(Intent.ACTION_VIEW);//                   sendIntent.putExtra("sms_body", "");//                  ////                   sendIntent.setType("vnd.androID-dir/mms-sms");//                   activity.startActivity(sendIntent);                } catch (Exception e) {                    e.printstacktrace();                }                // Todo auto-generated method stub            }        });

解决方法:

您可以在此处使用此方法以预定义的电话号码发送您的消息.

 voID sendSMS(String phoneNumber, String message)    {              String SENT = "SMS_SENT";        String DEliVERED = "SMS_DEliVERED";        PendingIntent sentPI = PendingIntent.getbroadcast(this, 0,            new Intent(SENT), 0);        PendingIntent deliveredPI = PendingIntent.getbroadcast(this, 0,            new Intent(DEliVERED), 0);        //---when the SMS has been sent---        registerReceiver(new broadcastReceiver(){            @OverrIDe            public voID onReceive(Context arg0, Intent arg1) {                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;                }            }        }, new IntentFilter(SENT));        //---when the SMS has been delivered---        registerReceiver(new broadcastReceiver(){            @OverrIDe            public voID onReceive(Context arg0, 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;                                        }            }        }, new IntentFilter(DEliVERED));                SmsManager sms = SmsManager.getDefault();        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);            }
总结

以上是内存溢出为你收集整理的我想使用短信管理器从Android应用程序发送短信全部内容,希望文章能够帮你解决我想使用短信管理器从Android应用程序发送短信所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1097728.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存