기존 APN을 읽으려고하고 나서 내 안드로이드 장치에 custum APN 이름을 써야합니다. 하지만 그것은 내 응용 프로그램을/system/app에 넣고 내 매니페스트에서 사용 권한을 선언하더라도 읽기/쓰기를 허용하지 않습니다. 01 : 17.831 :안드로이드에서 프로그래밍 방식으로 시스템 수준의 사용 권한을 부여하는 방법은 무엇입니까?
오류
이하15 System.err의 발생 (1717)/W :이 java.lang.SecurityException : 10060 어느 사용자도 현재 프로세스 android.permission.MODIFY_PHONE_STATE있다. 01-01 15 : 01 : 17.832 : W/System.err (1717) : android.os.Parcel.readException (Parcel.java:1620) 01-01 15 : 01 : 17.832 : W/System.err (1717) : android.os.Parcel.readException (Parcel.java:1573) 01-01 15 : 01 : 17.832 : System.err (1717) : com.android.internal.telephony.ITelephony $ Stub $에서 Proxy.supplyPin (ITelephony.java:1775) 01-01 15 : 01 : 17.833 : System.err (1717) : com.intel.sunnypoint.headless.HeadlessService.simUnlock (HeadlessService.java:194) 01 -01 15 : 01 : 17.833 : W/System.err (1717) : com.intel.sunnypoint.headless.HeadlessService.onStartCommand (HeadlessService.java:166) 01-01 15 : 01 : 17.833 : W/System. (1717) : android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3032) 01-01 15 : 01 : 17.833 : W/System.err (1717) : android.app.ActivityThread.access $ 2300 (Acti vityThread.java:150) 01-01 15 : 01 : 17.833 : W/System.err (1717) : android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1455) 01-01 15:01 : 17.833 : W/System.err (1717) : android.os.Handler.dispatchMessage (Handler.java:102) 01-01 15 : 01 : 17.833 : W/System.err (1717) : android.os. Looper.loop (Looper.java:148) 01-01 15 : 01 : 17.833 : W/System.err (1717) : android.app.ActivityThread.main (ActivityThread.java:5446) 01-01 : 01 : 17.833 : W/System.err (1717) : java.lang.reflect.Method.invoke (기본 메서드) 01-01 15 : 01 : 17.833 : System.err (1717) : com.android .internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:749) 01-01 15 : 01 : 17.833 : System.err (1717) : com.android.internal.os.ZygoteInit.main (ZygoteInit .java : 639)
다음은 내 코드
공공 INT InsertAPN (문자열 이름) {
//Set the URIs and variables
int id = -1;
boolean existing = false;
final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");
final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
//Check if the specified APN is already in the APN table, if so skip the insertion
Cursor parser = getContentResolver().query(APN_TABLE_URI, null, null, null, null);
parser.moveToLast();
while (parser.isBeforeFirst() == false){
int index = parser.getColumnIndex("name");
String n = parser.getString(index);
if (n.equals(name)) {
existing = true;
Log.d(TAG, "APN already configured.");
break;
}
parser.moveToPrevious();
}
//if the entry doesn't already exist, insert it into the APN table
if (!existing){
//Initialize the Content Resolver and Content Provider
ContentResolver resolver = this.getContentResolver();
ContentValues values = new ContentValues();
//Capture all the existing field values excluding name
Cursor apu = getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
apu.moveToFirst();
//Assign them to the ContentValue object
values.put("name", name); //the method parameter
values.put("apn", "Simple CMW APN");
values.put("type", "default");
values.put("proxy", "");
values.put("port", "");
values.put("user", "");
values.put("password", "");
values.put("server", "");
values.put("mmsc", "");
values.put("mmsproxy", "");
values.put("mmsport", "");
values.put("mcc", "001");
values.put("mnc", "01");
values.put("numeric", "");
//Actual insertion into table
Cursor c = null;
try{
Uri newRow = resolver.insert(APN_TABLE_URI, values);
if(newRow != null){
c = resolver.query(newRow, null, null, null, null);
int idindex = c.getColumnIndex("_id");
c.moveToFirst();
id = c.getShort(idindex);
}
}
catch(Exception e){}
if(c !=null) c.close();
}
return id;
}
//Takes the ID of the new record generated in InsertAPN and sets that particular record the default preferred APN configuration
public boolean SetPreferredAPN(int id){
//If the id is -1, that means the record was found in the APN table before insertion, thus, no action required
if (id == -1){
return false;
}
Uri.parse("content://telephony/carriers");
final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
boolean res = false;
ContentResolver resolver = this.getContentResolver();
ContentValues values = new ContentValues();
values.put("apn_id", id);
try{
resolver.update(PREFERRED_APN_URI, values, null, null);
Cursor c = resolver.query(PREFERRED_APN_URI, new String[]{"name", "apn"}, "_id="+id, null, null);
if(c != null){
res = true;
c.close();
}
}
catch (Exception e){}
return res;
}
방법을 설정하는 나를 인도 해주십시오이다. 미리 감사드립니다.
루트 액세스 사용 –