可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a problem reading APNs in Android v4.2 (Yes reading, not writing APNS), it is throwing a security exception:
No permission to write APN settings: Neither user 10068 nor current process has android.permission.WRITE_APN_SETTINGS.
Same code used to work on all previous platforms, does anyone know of any work around to this?
Thanks!
回答1:
This appears to be an intentional change. The git commit where they added this defense includes the following comment:
Since the DB may contain corp passwords, we should secure it. Using the same permission as writing to the DB as the read is potentially as damaging as a write.
It is conceivable that your issue will cause them to consider adding a separate read permission, but at least for the time being, this is a regression in 4.2.
回答2:
If you want to Read APN for Android 4.2 and more they are a change to do. I tested and it's work.
In Android 4.1 and below use this :
Cursor c = getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), null, null, null, null);
And for Android 4.2 and above use this code :
private static final String[] APN_PROJECTION = { Telephony.Carriers.TYPE, // 0 Telephony.Carriers.MMSC, // 1 Telephony.Carriers.MMSPROXY, // 2 Telephony.Carriers.MMSPORT // 3 };
And this line :
final Cursor apnCursor =SqliteWrapper.query(context, this.context.getContentResolver(), Uri.withAppendedPath(Carriers.CONTENT_URI, "current"), APN_PROJECTION, null, null, null);
The SQLiteWrapperClass is hidden (found this class in internet)
import android.database.sqlite.SqliteWrapper;
My English is not quite good, sorry for this.
回答3:
You can read default settings from /etc/apns-conf.xml:
private boolean getSettingsFromApnsFile(Context context, String apnName) { FileReader reader = null; boolean sawValidApn = false; try { reader = new FileReader("/etc/apns-conf.xml"); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(reader); TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); String simOperator = telephonyManager.getSimOperator(); if (TextUtils.isEmpty(simOperator)) { logger.warn("unable to get sim operator - so unable to get mms config"); return false; } int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG && xpp.getName().equals("apn")) { HashMap attributes = new HashMap(); for (int i=0; i
回答4:
I have the situation too, my solution is don't access android_assets in AsyncTask. "Make sure that only your main thread have the permission to access you app's assets dir"
I got the problem when I coding like this:
@Override protected void onResume() { super.onResume(); //mWebView.loadUrl("file:///android_asset/95306.html"); new LoadUrlTask().execute("file:///android_asset/95306.html"); } ... class LoadUrlTask extends AsyncTask { // progressDialog = new ProgressDialog(LoadActivity.this); @Override protected String doInBackground(String... strings) { mWebView.loadUrl(strings[0]); return ""; } @Override protected void onPostExecute(String s) { super.onPostExecute(s); //progressDialog.dismiss(); } @Override protected void onPreExecute() { super.onPreExecute(); //progressDialog.setMessage("loading..."); //progressDialog.show(); } }
and I fix it by:
@Override protected void onResume() { super.onResume(); mWebView.loadUrl("file:///android_asset/95306.html"); //new LoadUrlTask().execute("file:///android_asset/95306.html"); }
hope that will help you!