我正在尝试更新在以下位置找到的首选 APN 数据库表的“名称”列:content://telephony/carriers/preferapn。但是,我的应用程序的 ContentResolver.update() 始终返回 0,这意味着没有更新任何行。我已经拥有该应用程序的 root 访问权限,并在运行 update() 之前以编程方式对其进行了确认。
可以在此处和此处找到有关表格列的详细信息。我还确保参考有关如何调用更新函数的文档。
更新方法:
public boolean setAPN(String newAPN, TextView t){
//get URI objects for the tables
final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");
final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
//Confirm permissions
PackageManager pm = getPackageManager();
if (pm.checkPermission(permission.WRITE_APN_SETTINGS, getPackageName()) == PackageManager.PERMISSION_GRANTED) {
//Update name field
ContentResolver resolver = this.getContentResolver();
ContentValues values = new ContentValues();
values.put("name", newAPN);
long rc = resolver.update(PREFERRED_APN_URI, values, null, null);
//Display the row contents (always has the original fields, doesn't update)
Cursor c = getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
c.moveToFirst();
int index = c.getColumnIndex("_id"); //getting index of required column
Short id = c.getShort(index); //getting APN's id from
index = c.getColumnIndex("name");
String name = c.getString(index);
index = c.getColumnIndex("mcc");
String mcc = c.getString(index);
index = c.getColumnIndex("mnc");
String mnc = c.getString(index);
index = c.getColumnIndex("numeric");
String numeric = c.getString(index);
t.setText(" ID:" + id + "\n" +
" APN Name: " + name + "\n" +
" MCC: " + mcc + "\n" +
" MNC: " + mnc + "\n" +
" Numeric: " + numeric + "\n"
);
} else {
t.setText(" You don't have permission to do this. ");
}
return true;
}
如前所述,我在清单文件中也有权限:“android.permission.WRITE_APN_SETTINGS”:
我是否出于特定目的错误地调用了更新函数?或者是使用 update() 错误的方式来解决这个问题?