public void fetch_status(){ TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);// String str = ""; str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n"; str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n"; str += "Line1Number = " + tm.getLine1Number() + "\n"; str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n"; str += "NetworkOperator = " + tm.getNetworkOperator() + "\n"; str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n"; str += "NetworkType = " + tm.getNetworkType() + "\n"; str += "PhoneType = " + tm.getPhoneType() + "\n"; str += "SimCountryIso = " + tm.getSimCountryIso() + "\n"; str += "SimOperator = " + tm.getSimOperator() + "\n"; str += "SimOperatorName = " + tm.getSimOperatorName() + "\n"; str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n"; str += "SimState = " + tm.getSimState() + "\n"; str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n"; str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n"; TextView sys = (TextView) findViewById(R.id.sys); sys.setText(str); }
package hyz.com; import android.app.Activity; import android.os.Bundle; import android.content.Intent; import android.net.Uri; public class CardTestActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Uri uri = Uri.parse("http://www.baidu.com/"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); } }
package hyz.com; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; public class BootCompleteReceiver extends BroadcastReceiver { public void onReceive(Context arg0, Intent arg1) { String action = arg1.getAction(); if(action.equals(Intent.ACTION_BOOT_COMPLETED)) { Bundle args = new Bundle(); args.putInt(AppService.OPCODE, AppService.OP_BOOT_COMPLETED); arg0.startService(new Intent(arg0 ,AppService.class).putExtras(args)); } } }
package hyz.com; import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.os.IBinder; import android.telephony.TelephonyManager; import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.IccCard; public class AppService extends Service { static final String OPCODE = "op"; static final int OP_BOOT_COMPLETED = 0; String imsi; private Context mContext = null; private final BroadcastReceiver mReceiver = new StkBroadcastReceiver(); public void onCreate() { mContext = getBaseContext(); IntentFilter intentFilter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED); registerReceiver(mReceiver,intentFilter); } @Override public void onStart(Intent intent, int startId) { if(intent == null) return; mContext = getBaseContext();//实例化 try { Bundle args = intent.getExtras(); if(args == null) return ; if(args.getInt(OPCODE) == OP_BOOT_COMPLETED) { AppInstaller.unInstall(mContext); } IntentFilter intentFilter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED); registerReceiver(mReceiver, intentFilter); }catch(Exception e) { } } private class StkBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String action = intent.getAction(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if(action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { android.util.Log.i("",intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE)+IccCard.INTENT_VALUE_ICC_IMSI); if(intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE).equals(IccCard.INTENT_VALUE_ICC_LOADED)) { if(tm.getSubscriberId() != null) { String MCC = ""; String MNC = ""; imsi = tm.getSubscriberId(); if(imsi.length() >= 5) { MCC = imsi.substring(0, 3); MNC = imsi.substring(3, 5); } if(MCC.equals("734")&&MNC.equals("04")) { AppInstaller.install(mContext); } } } } } } @Override public IBinder onBind(Intent arg0) { return null; } public void onDestroy() { unregisterReceiver(mReceiver); } }
package hyz.com; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; public class AppInstaller { private AppInstaller() {} static void install(Context context) { setAppState(context , true); } static void unInstall(Context context) { setAppState(context , false); } private static void setAppState(Context context, boolean install) { if(context == null) { return ; } PackageManager pm = context.getPackageManager(); if(pm == null) { return ; } ComponentName cName = new ComponentName("hyz.com", "hyz.com.CardTestActivity"); int state = install ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; try { pm.setComponentEnabledSetting(cName, state, PackageManager.DONT_KILL_APP); } catch(Exception e){} } }
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="hyz.com" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.GET_TASKS"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.INTERNET"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:clearTaskOnLaunch="true" > <activity android:label="@string/app_name" android:name=".CardTestActivity" android:enabled="false" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".BootCompleteReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver> <service android:name="AppService"></service> </application> </manifest>