Android的短信应用。我在不存储发送的手机上的消息 [英] Android SMS app I made not storing sent messages on the phone

查看:124
本文介绍了Android的短信应用。我在不存储发送的手机上的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个短信应用程序,它不存储我送使用的应用程序中的消息!这里是code的发送部分:

I've created an SMS app and it isn't storing the messages i send using the app! Here is the code for the sending part:

package com.pearson.sms;

import java.util.List;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class PearsonSMS extends Activity {
Button btnSendSMS;
EditText txtPhoneNo;
EditText txtMessage;

String phoneNumber;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
    txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo);
    txtMessage = (EditText) findViewById(R.id.txtMessage);
    phoneNumber = "";

    try{
    /*Split the incoming uri to retrieve the phone number*/
    Uri urithing = getIntent().getData();
    phoneNumber = urithing.toString();
    String[] splitUri = phoneNumber.split(":");

    phoneNumber = splitUri[1];
    txtPhoneNo.setText(phoneNumber);
    }
    catch (Error e)
    {
        Toast.makeText(getBaseContext(), 
                "Error:"+e.getMessage(), 
                Toast.LENGTH_SHORT).show();
    }
    catch (Exception e)
    {
        Toast.makeText(getBaseContext(), 
                "Exception:"+e.getMessage(), 
                Toast.LENGTH_SHORT).show();
    }

    btnSendSMS.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
        {
            Toast.makeText(getBaseContext(), "Sending SMS...", 
                    Toast.LENGTH_SHORT).show();
            String phoneNo = txtPhoneNo.getText().toString();
            String message = txtMessage.getText().toString();                 
            if (phoneNo.length()>0 && message.length()>0)                
                sendSMS(phoneNo, message);                
            else
                Toast.makeText(getBaseContext(), 
                    "Please enter both phone number and message.", 
                    Toast.LENGTH_SHORT).show();
            finish();
        }
    });        
}

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;
                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存储在SQLite数据库的短信(这可能是完全错误的),我想我需要在发送的消息传递给它,但谷歌已经不是我的朋友就这一个网...请大家帮忙!

I read somewhere on the net that android stores the sms messages in a sqlite database (that could be totally wrong) I assume i need to pass the sent messages to it but google has not been my friend on this one...please help!

推荐答案

检查这个答案:

的Andr​​oid:发送短信(使用发件箱)

它有一个链接到一个样本项目。

It has a link to a sample project.

这篇关于Android的短信应用。我在不存储发送的手机上的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆