开发者

read / write from sim card for android

I've been trying to read/write from sim card but still there's no luck.

here's开发者_JAVA技巧 my code so far:

    //read from sim
public String adding() {
        Uri simUri = Uri.parse("content://icc/adn/"); 
        Cursor cursorSim = this.getContentResolver().query(simUri, null, null,null, null);
        String b = "";

        while (cursorSim.moveToNext()) {           

      b+=   (cursorSim.getString(cursorSim.getColumnIndex("name")));
        b += "\n" + (cursorSim.getString(cursorSim.getColumnIndex("_id")));      
       b+=   "\n" + (cursorSim.getString(cursorSim.getColumnIndex("number")));
        }


    return b;


}

//to write to sim

public void testing4() {
           ContentValues values = new ContentValues();

           values.put( "tag", "test" );

           values.put( "number", "1234" );

           getContentResolver().insert( Uri.parse("content://icc/adn/"); , values

    );  

    }

please let me know if you know something about this.

Thanks


There is some misspelling in the writing to usim.

getContentResolver().insert(Uri.parse("content://icc/adn"), values);

Also the permission should be added in the AndroidManifest.

(Side question) In the simsalabim's source code, I don't know the meaning of the class variable "Contact". I can't find the package which can be imported. In the eclipse, there are errors in the "Contact" lines.

The source code says that the file content://icc/adn is for the android version over 1.6, for 1.5 content://sim/adn.

(Side result) I found the size of "number" field can be over 64 characters. In the read process, the correct value can be retrieved. But the real phone screen can't show the full characters.


Have you added the permissions to the AndroidManifest?

You should have:

<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>

You can also get some ideas from simsalabim's source code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜