Read APNs in Android 4.2?

前端 未结 4 731
情书的邮戳
情书的邮戳 2020-11-27 21:49

I have a problem reading APNs in Android v4.2 (Yes reading, not writing APNS), it is throwing a security exception:

4条回答
  •  野性不改
    2020-11-27 22:11

    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.

提交回复
热议问题