public void onManageMobilePlanClick() { log("onManageMobilePlanClick:"); mManageMobilePlanMessage = null; Resources resources = getActivity().getResources(); NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo(); if (mTm.hasIccCard() && (ni != null)) { // Get provisioning URL String url = mCm.getMobileProvisioningUrl(); if (!TextUtils.isEmpty(url)) { Intent intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION); intent.putExtra("EXTRA_URL", url); Context context = getActivity().getBaseContext(); context.sendBroadcast(intent); mManageMobilePlanMessage = null; } else { // No provisioning URL String operatorName = mTm.getSimOperatorName(); if (TextUtils.isEmpty(operatorName)) { // Use NetworkOperatorName as second choice in case there is no // SPN (Service Provider Name on the SIM). Such as with T-mobile. operatorName = mTm.getNetworkOperatorName(); if (TextUtils.isEmpty(operatorName)) { mManageMobilePlanMessage = resources.getString(R.string.mobile_unknown_sim_operator); } else { mManageMobilePlanMessage = resources.getString(R.string.mobile_no_provisioning_url, operatorName); } } else { mManageMobilePlanMessage = resources.getString(R.string.mobile_no_provisioning_url, operatorName); } } } else if (mTm.hasIccCard() == false) { // No sim card mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card); } else { // NetworkInfo is null, there is no connection mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet); } if (!TextUtils.isEmpty(mManageMobilePlanMessage)) { log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage); showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID); } }
public void onManageMobilePlanClick() { log("onManageMobilePlanClick:"); mManageMobilePlanMessage = null; Resources resources = getActivity().getResources(); NetworkInfo ni = mCm.getActiveNetworkInfo(); if (mTm.hasIccCard() && (ni != null)) { // Check for carrier apps that can handle provisioning first Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP); List<String> carrierPackages = mTm.getCarrierPackageNamesForIntent(provisioningIntent); if (carrierPackages != null && !carrierPackages.isEmpty()) { if (carrierPackages.size() != 1) { Log.w(TAG, "Multiple matching carrier apps found, launching the first."); } provisioningIntent.setPackage(carrierPackages.get(0)); startActivity(provisioningIntent); return; } // Get provisioning URL String url = mCm.getMobileProvisioningUrl(); if (!TextUtils.isEmpty(url)) { Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER); intent.setData(Uri.parse(url)); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(intent); } catch (ActivityNotFoundException e) { Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e); } } else { // No provisioning URL String operatorName = mTm.getSimOperatorName(); if (TextUtils.isEmpty(operatorName)) { // Use NetworkOperatorName as second choice in case there is no // SPN (Service Provider Name on the SIM). Such as with T-mobile. operatorName = mTm.getNetworkOperatorName(); if (TextUtils.isEmpty(operatorName)) { mManageMobilePlanMessage = resources.getString(R.string.mobile_unknown_sim_operator); } else { mManageMobilePlanMessage = resources.getString(R.string.mobile_no_provisioning_url, operatorName); } } else { mManageMobilePlanMessage = resources.getString(R.string.mobile_no_provisioning_url, operatorName); } } } else if (mTm.hasIccCard() == false) { // No sim card mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card); } else { // NetworkInfo is null, there is no connection mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet); } if (!TextUtils.isEmpty(mManageMobilePlanMessage)) { log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage); showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID); } }