【问题标题】:(Android) Why i use SmsManager.getDefault().sendTextMessage but apps dont send sms?(Android) 为什么我使用 SmsManager.getDefault().sendTextMessage 但应用程序不发送短信?
【发布时间】:2013-08-09 13:48:27
【问题描述】:

我使用了 SmsManager.getDefault().sendTextMessage 但不发送短信我想以编程方式发送短信请查看此代码

编辑代码:

    public void sendEmail(View view){
            if (hasConnection() == false){
                Intent goPop = new Intent(getApplicationContext(),ShowPopup.class);
                startActivity(goPop);
                finish();
            }
            statusOfGPS = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

            // Set Email option
            final Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",OpsEmail, null));


            //Check Send SMS
            if (mSMSCheckbox.isChecked()){
                SMS = true;
            }else{  
                SMS = false;
            }       

            //Check GPs
            if (statusOfGPS == true){
                LocationBy = "GPS";

            }else{
                LocationBy = "INTERNET";
            }
            setUpAddress();
            //SMS true
            if (mLocationClient != null && mLocationClient.isConnected() && SMS == true) {
                //set massage to send
                DescribeText = "This is a Emergency message \n\n PLEASE HELP ME!!! at\n\n "+
                        addressText+ "\n Location("+LocationBy+"):("+mLocationClient.getLastLocation().getLatitude() + mLocationClient.getLastLocation().getLongitude()+
                        ") \n\n Please check maps <a href='https://maps.google.com/maps?q="+mLocationClient.getLastLocation().getLatitude()+","+mLocationClient.getLastLocation().getLongitude()+"&ll="+mLocationClient.getLastLocation().getLatitude()+","+mLocationClient.getLastLocation().getLongitude()+"&z=17'>here</a>";

                //send SMS First
                String sent = "android.telephony.SmsManager.STATUS_ON_ICC_SENT";
                SmsManager smsManager = SmsManager.getDefault();
                PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(sent), 0);
                smsManager.sendTextMessage(OpsPhoneNumber, null, DescribeText, pi,null);

                //send email
                i.putExtra(Intent.EXTRA_SUBJECT, "Emergency Location");
                i.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(DescribeText));
                try {
                    startActivity(Intent.createChooser(i, "Send mail..."));
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_LONG).show();
                }

             Log.d(TAG, "gps =" + statusOfGPS);
            }
}

下一行 //send SMS First

我用

SmsManager.getDefault().sendTextMessage(OpsPhoneNumber, null, 描述文本, null,null);

在我的清单文件中,我有:

<uses-permission android:name="android.permission.SEND_SMS"/>

我要测试的设备是 android 4.2.2 和 4.1.1 但是应用程序不发送短信如何解决这个问题?

【问题讨论】:

标签: android methods smsmanager


【解决方案1】:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("", null, "< message body>", null, null);

SmsManager 需要,在您的 android mainfest 中具有 SMS_SEND 权限。

【讨论】:

  • 是的,我会尽力回答你的问题,我有 但不发送短信。
  • 可以的话能否提供一下logcat
  • 很抱歉,logcat 不再显示用于发送短信,但我认为消息太长。正常文本消息长度(即 160 个字符)我尝试使用 sendMultipartTextMessagelink发送长短信的代码。是的,这个命令可以工作,我的短信已经发送,但是下次这个命令不发送短信时它会发送一次。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-21
相关资源
最近更新 更多