检查手机是否连接网络,sim的存在以及是否支持NFC功能

代码如下:

/*** 检查sim卡是否存在* @return*/private boolean checkPhoneNet(){TelephonyManager mTelephonyManager=(TelephonyManager) this.getSystemService(Service.TELEPHONY_SERVICE);if(mTelephonyManager.getSimState()!=TelephonyManager.SIM_STATE_READY) //SIM卡没有就绪{MessageBox.alert(getApplicationContext(), "SIM卡没有就绪");return false;}else{ConnectivityManager cManager=(ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo info = cManager.getActiveNetworkInfo();if (info != null && info.isAvailable()){         //能联网
//               MessageBox.alert(getApplicationContext(), "能联网");return true;}else{//do somethingMessageBox.alert(getApplicationContext(), "不能联网");//不能联网return false;}}}/*** 判断手机是否支持NFC功能和OpenMobileAPI* */private boolean isSupportMocam() {boolean isSupportMocam = false;// 判断手机是否有NFC功能PackageManager pm = getPackageManager();boolean hasNfcFeature = pm.hasSystemFeature(PackageManager.FEATURE_NFC);// 如果手机支持NFC,尝试能否加载OpenMobile API的类if (hasNfcFeature) {try {Class.forName("org.simalliance.openmobileapi.SEService");isSupportMocam = true;} catch (ClassNotFoundException e) {e.printStackTrace();MessageBox.alert(getApplicationContext(), "加载OpenMobile失败");Log.d(TAG,"Class not Found:org.simalliance.openmobileapi.SEService");}}else{MessageBox.alert(getApplicationContext(), "您的手机不支持NFC");}return isSupportMocam;}/*** 判断NFC是否打开* * @return*/public boolean hasNFC(){NfcManager manager = (NfcManager) this.getSystemService(Context.NFC_SERVICE);  NfcAdapter adapter = manager.getDefaultAdapter();if (adapter != null && adapter.isEnabled()) {  // adapter存在,能启用  
//           Toast.makeText(getApplicationContext(), "您的手机NFC已打开", 1).show();   return true;  }MessageBox.alert(getApplicationContext(), "您的手机没有打开NFC");return false;}

注释:MessageBox.alert是一个表示弹出对话框,一个封装工具


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部