从Android应用程序访问收件箱消息

时间:2012-03-03 04:18:27

标签: android sms

我需要Android sms应用程序的帮助。我正在从我的Android应用程序向手机号码发送消息。我需要检查邮件是否已从我的应用程序中在该手机号码的INBOX中传送。我需要检查发送到手机号码的消息是否已经发送。 IE浏览器。 Desitnation匹配。如何从Android应用程序访问INBOX messge。请指导我这个问题。如果有人帮我提供示例工作示例,那将会很有帮助。

提前致谢。

3 个答案:

答案 0 :(得分:1)

如何从Android应用程序访问INBOX消息,答案如下,

Uri uri = Uri.parse("content://sms/inbox");
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
while (cursor.moveToNext()) 
{
  // Retrieve sms
  // see column "address" for comparing

  // Then update the sms and set the column "read" to 1
}

答案 1 :(得分:0)

试试这个

 public static final Uri SMS_INBOX_CONTENT_URI = Uri.parse("content://sms/inbox");

 Cursor cursor = managedQuery(SMS_INBOX_CONTENT_URI, new String[]{TextSmsColumns.ID, TextSmsColumns.ADDRESS,
            TextSmsColumns.DATE, TextSmsColumns.BODY}, null, null, TextSmsColumns.DATE + " DESC");

    cursor.moveToFirst();
    StringBuilder builder = new StringBuilder();
    for(int i = 0 ; i < cursor.getCount(); i++)
    {
        builder.append("         ID-"+i);
        String s= "  Address:  "+cursor.getString(cursor.getColumnIndexOrThrow(TextSmsColumns.ADDRESS))
        + "  Body:  "+cursor.getString(cursor.getColumnIndexOrThrow(TextSmsColumns.BODY))
        + "  Date:  "+cursor.getString(cursor.getColumnIndexOrThrow(TextSmsColumns.DATE));
        builder.append(s);
        cursor.moveToNext();
    }

答案 2 :(得分:0)

试试这种方式

在AndroidManifest.xml文件中,添加以下权限:

android.permission.RECEIVE_SMS

android.permission.SEND_SMS


// Demo source code to sends an SMS and notify status

private void send(String number,  String message)
{        

// notify 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(), "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_RADIO_OFF:
                Toast.makeText(getBaseContext(), "RADIO_OFF!", 
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NULL_PDU:
                Toast.makeText(getBaseContext(), "ERROR_NULL_PDU!", 
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
                Toast.makeText(getBaseContext(), "ERROR_NO_SERVICE!", 
                        Toast.LENGTH_SHORT).show();
                break;
        }
    }
}, new IntentFilter("SMS_SENT"));

// notify when the SMS has been delivered

registerReceiver(new BroadcastReceiver(){
    @Override
    public void onReceive(Context arg1, Intent arg2) {
        switch (getResultCode())
        {
            case Activity.RESULT_CANCELED:
                Toast.makeText(getBaseContext(), "Not delivered", 
                        Toast.LENGTH_SHORT).show();
                break; 
            case Activity.RESULT_OK:
                Toast.makeText(getBaseContext(), "Delivered", 
                        Toast.LENGTH_SHORT).show();
                break;                       
        }
    }
}, new IntentFilter("SMS_DELIVERED"));        



PendingIntent sentPendingIntent = PendingIntent.getBroadcast(this, 0,
    new Intent("SMS_SENT"), 0);

PendingIntent deliveredPendingIntent = PendingIntent.getBroadcast(this, 0,
    new Intent("SMS_DELIVERED"), 0);

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendTextMessage(number, null, message, sentPendingIntent,     deliveredPendingIntent);        
}