Friday, July 19, 2013

Java library for retrieving SMS email gateway, mms APN settings

At the time of this post, there is currently no library written in Java for retrieving the SMS email gateways of mobile service providers, or mms APN settings given an mcc/mnc pair, or Country code and operator name. This library uses a comprehensive aggregation of mms APN settings, MCC, MNC, Operator/Carrier names, SMS email gateways, and MMS email gateways from many online sources (xda developers , cm10.1 apns-config, Wikipedia  mobile country code page, and other sms email gateways found online).

Here is the final xml: XML

Here is a download for the library: Droidprism.jar
Javadoc:    Carrier.html    APN.html

Usage:
First add Jsoup to the build path.

import com.droidprism.*;

Carrier c = Carrier.getCarrier("US","Verizon");
if(c != null) {
  String smsemail = c.getsmsemail();  
  String mmsemail = c.getmmsemail();
  System.out.println(smsemail + "   " + mmsemail); 
  //prints vtext.com   vzwpix.com
  com.droidprism.APN apn = c.getAPN();
  if(apn != null) {
     String mmsc = apn.mmsc;
     String mmsproxy = apn.proxy; //"" if none
     String mmsport = apn.port; //0 if none
     System.out.println(mmsc +"  " + mmsproxy + "  " + mmsport); 
     //prints http://mms.vtext.com/servlets/mms   0
    }
}


You can also get the carrier from android with mcc and mnc codes:
TelephonyManager tel = (TelephonyManager) 
                  getSystemService(Context.TELEPHONY_SERVICE);
    String networkOperator = tel.getNetworkOperator();

    if (networkOperator != null) {
        int mcc = Integer.parseInt(
                  networkOperator.substring(0, 3));
        String s = networkOperator.substring(3);
        //remove leading zeroes
        int mnc = Integer.parseInt(
                   s.replaceFirst("^0{1,2}",""));
        Carrier c = Carrier.getCarrier(mcc, mnc);
        c.getsmsemail();
        APN a = c.getAPN(); 
    }