在后台向自己的电话号码发送短信而不发送出现在消息列表中



可能的重复:
如何在iPhone上编程发送SMS?

我不确定是否可能,但是我想实现的目标是,在被询问用户许可之后,我的应用程序想通过手机通过我的应用程序发送格式化的SMS。我希望它在后台发生,而没有他们看到SMS输入屏幕,我希望已发送的SMS不存在消息列表中,只有格式的已接收消息。

甚至有可能吗?最初,我想在iPhone上实现它,但是后来我想将其扩展到Android和WP7。预先感谢。

在iOS上,不,你不能。

您可以使用第三方服务。

我不知道其他平台,但是在iOS上,如果您的应用程序想要发送SMS,则会要求用户许可,并且将将用户带到SMS接口。苹果对这些非常严格,但在Android中可能是可能的。

在iOS文档上发送短信

编辑:我不知道您要做什么,但是为什么不使用网络呢?如果您要发送一条消息,则用户不知道它不需要的内容或目的地。

您可以以这种方式发送SMS:

在这里,我可以在按钮上使用单击,您可以在后台发送短信不会在用户面前出现屏幕。(注意:如果适用,请返回,否则返回空值。)

获取所有者电话号码:

 TelephonyManager tMgr =(TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
 String number = tMgr.getLine1Number();

写入 Pending Intent 在单击事件上此代码。

String message = "HI THIS IS TEST SMS IN ANDROID.";             
/** Creating a pending intent which will be broadcasted when an sms message is successfully sent */
PendingIntent piSent = PendingIntent.getBroadcast(getBaseContext(), 0, new Intent("sent_msg") , 0);
/** Creating a pending intent which will be broadcasted when an sms message is successfully delivered */
PendingIntent piDelivered = PendingIntent.getBroadcast(getBaseContext(), 0, new Intent("delivered_msg"), 0);
/** Getting an instance of SmsManager to sent sms message from the application*/
SmsManager smsManager = SmsManager.getDefault();                
/** Sending the Sms message to the intended party */
smsManager.sendTextMessage(number, null, message, piSent, piDelivered);

使用SmsNotifications创建类名称extends BroadcastReceiver

/**
 * This class handles the SMS sent and sms delivery broadcast intents
 */
public class SmsNotifications extends BroadcastReceiver{
    /**
     * This method will be invoked when the sms sent or sms delivery broadcast intent is received 
     */ 
    @Override
    public void onReceive(Context context, Intent intent) {
        /**
         * Getting the intent action name to identify the broadcast intent ( whether sms sent or sms delivery ) 
         */
        String actionName = intent.getAction();

        if(actionName.equals("sent_msg")){
            switch(getResultCode()){
                case Activity.RESULT_OK:
                    Toast.makeText(context, "Message is sent successfully" , Toast.LENGTH_SHORT).show();
                    break;
                default:
                    Toast.makeText(context, "Error in sending Message", Toast.LENGTH_SHORT).show();
                    break;              
            }           
        }
        if(actionName.equals("delivered_msg")){
            switch(getResultCode()){
                case Activity.RESULT_OK:
                    Toast.makeText(context, "Message is delivered" , Toast.LENGTH_SHORT).show();
                    break;
                default:
                    Toast.makeText(context, "Error in the delivery of message", Toast.LENGTH_SHORT).show();
                    break;
            }
        }       
    }
}

管理您的清单文件:

权限:

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

 <receiver android:name=".SmsNotifications" >
            <intent-filter >
                <action android:name="sent_msg" />
                <action android:name="delivered_msg" />                                
            </intent-filter>
        </receiver>

我能想到的唯一替代方法是将nshttpurlrequest发送到提供SMS网关的Web服务。您当然可以在后台做,尽管您(开发人员而不是用户)可能会产生发送消息的成本,而发件人似乎不会是用户。

您不能在Windows Phone 7中执行此操作。您必须启动与MFMessageComposeViewController相似的SmsComposeTask。这意味着所有发送逻辑的文本都在其中处理,您只能调整一些参数。

最新更新