检索从SIM卡的短信与Android短信、SIM、Android

由网友(持刀稳场)分享简介:我想知道是否有人知道有关以编程方式获取短信关闭您的手机SIM卡的android平台上的任何东西。我想编写一个程序,让您无论是单个邮件或整个线程保存到SD卡,但环视了一下后,我发现,谷歌决定采取从目前的Andr​​oid SDK的API。我在一些地方,有隐藏的API来此看到了,但没有人知道他们是什么或如何使用它们。I...

我想知道是否有人知道有关以编程方式获取短信关闭您的手机SIM卡的android平台上的任何东西。我想编写一个程序,让您无论是单个邮件或整个线程保存到SD卡,但环视了一下后,我发现,谷歌决定采取从目前的Andr​​oid SDK的API。我在一些地方,有隐藏的API来此看到了,但没有人知道他们是什么或如何使用它们。

I was wondering if anyone knew anything about programmatically getting the sms messages off of your phone's sim card on an android platform. I would like to write a program that allows you to save either individual messages or entire threads to the sd card, but after looking around for a bit, I have discovered that google decided to take out that api from the current android sdk. I saw in a few places that there are hidden apis for this, but no one knew what they were or how to use them.

推荐答案

下面是一个code段,可以让你读的邮件。

Here is a code snippet that lets you read messages.

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.telephony.gsm.SmsManager;
import android.widget.Toast;

public class SMSReceiver extends BroadcastReceiver
{
    public void onReceive(Context context, Intent intent)
    {
        Bundle myBundle = intent.getExtras();
        SmsMessage [] messages = null;
        String from= "";
        String body="";
        boolean inSIM=false;

        if (myBundle != null)
        {
            Object [] pdus = (Object[]) myBundle.get("pdus");
            messages = new SmsMessage[pdus.length];

            for (int i = 0; i < messages.length; i++)
            {
                messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                from = ""+messages[i].getOriginatingAddress();
                body = ""+messages[i].getMessageBody();
                inSIM = (messages[i].getIndexOnSim() != -1);
                if (inSIM)
                {
                    int status = messages[i].getStatusOnSim();
                    if (status == SmsManager.STATUS_ON_SIM_UNREAD)
                    {
                       Toast.makeText(context, "Message Unread on SIM: "+from+": "+body, Toast.LENGTH_SHORT).show();
                    }
                }                
            }            
        }
    }
}
阅读全文

相关推荐

最新文章