Reputation: 21
I've been trying to read/write from sim card but still there's no luck.
here's 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
Upvotes: 2
Views: 6291
Reputation: 21
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.
Upvotes: 2
Reputation: 93123
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.
Upvotes: 0