开发者

send sms via app and appear in default sms application

开发者 https://www.devze.com 2023-04-01 12:02 出处:网络
how do you send sms and make it appear in the sent items? what i mean is you send an sms via my application and make it appear that i sent it via the default sms app.

how do you send sms and make it appear in the sent items? what i mean is you send an sms via my application and make it appear that i sent it via the default sms app.

i send my SMS using

private 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;
                default:
                    Toast.makeText(getBaseContext(), "Sending Failed.", Toast.LENGTH_SHORT).show();
                    break;
            }
            progDialog.dismiss();
            txtCustomerNumber.setText("");
            txtCustomerNumber.requestFocus();
        }
    }, 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);        
}

how to display it via default sms app?


how to display it via default sms app?

Use ACTION_SEND instead of SmsManager and allow the user to choose whichever SMS client they want. Or, write your own SMS client.

There is no universal "default sms app". Each SMS app can elect to track sent items; if so, those items will be what it sends, since those are the only SMS messages it will know about. Some SMS apps might offer some sort of documented and supported API for manipulating sent items. The Messenger application that is part of the Android Open Source Project does not.

There is an undocumented and unsupported content provider for the Messenger application. Somebody is likely to chime in on this issue and cite using that. Bear in mind that Google just locked down the similarly undocumented and unsupported Gmail content provider. Hence, using undocumented and unsupported APIs like this is risky business.

0

精彩评论

暂无评论...
验证码 换一张
取 消