开发者

Get SMS Messages from SIM card

开发者 https://www.devze.com 2023-01-16 14:40 出处:网络
I want to save the SMS I have on my old Samsung SGH-D500. Since the software for it doesn\'t save the time for exported messages, I copied messages to the SIM card and backuped them on Android using t

I want to save the SMS I have on my old Samsung SGH-D500. Since the software for it doesn't save the time for exported messages, I copied messages to the SIM card and backuped them on Android using the following code:

    Cursor c = getContentResolver().query(Uri.parse("content://sms"), null, null, null, null);
    startManagingCursor(c);
    String text = "";
    for(String name : c.getColumnNames()){
        text += name+"\t";
    }
    text += "\n";
    while(c.moveToNext()){
        for(int i=0; i<c.getColumnCount(); i++){
            text += c.getString(i)+"\t";
        }
        text += "\n";
    }
    Log.d("sms", text);
    File root = Environment.getExternalStorageDirectory();
    if(root.canWrite()){
        File export = new File(root, "sms.txt");
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(export));
            bw.write(text);
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

The first problem is that it only gets the messages that are on the phone. So I have to copy each message (there's no copy all) to the phone first.

The second problem is that Android doesn't even recognize sent messages I put on the SIM card开发者_开发问答 (SIM card is full but Android shows nothing).

I looked into the Sim Toolkit, but didn't really know where to start. Isn't there something like "content://icc/adn" (contacts) just for SMS?

Thanks

Ralf


I played around with the sms api a long time ago. I don't have the code that retrieved all messages but I found some code that added a message to the sent messages list

ContentValues values = new ContentValues(); values.put("address", number); values.put("body", message); getContentResolver().insert(Uri.parse("content://sms/sent"),values);

From memory I think content://sms/inbox retrieves all messages in inbox. I can't comment whether that gets messages both on the phone and on the sim. I use the following software to send messages through my phone from my computer http://www.fjsoft.at/en/. It also shows all text messages and allows you to export them. Again i'm not sure if this is messages on the phone or sim or both. But it's worth a try and is a nice piece of software.

0

精彩评论

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

关注公众号