android - (Android) 为什么我使用 SmsManager.getDefault().sendTextMessage 但应用程序不发送短信?

标签 android methods smsmanager

我使用了 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);
            }
}

下一行//先发送短信

我用

SmsManager.getDefault().sendTextMessage(OpsPhoneNumber, null, DescribeText, null,null);

在我的 list 文件中我有:

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

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

最佳答案

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("", null, "< message body>", null, null);

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

关于android - (Android) 为什么我使用 SmsManager.getDefault().sendTextMessage 但应用程序不发送短信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18139514/

相关文章:

android - 等到谷歌地图在 MapFragment 中有大小

java - Android反编译的.class文件不显示相应.java文件的所有方法

Android删除已发件箱中的短信

java - 有什么方法可以保存显示从 url 检索到的图像的 imageView 的状态吗?

android - 第二次通知无效

android - 使用 iPod/iPhone 测试 Android 方向

c# - 有人可以向我解释为什么这不起作用吗?

c# - 如何在 C# 中创建使用对象名称的方法?

java - 我似乎不知道如何打印分配给对象的值

android - 如何使用SmsManager.importMultimediaMessage()?如何在 Android 的数据库中导入彩信?