Android:Run Time Removal of Sim Card for HTC One V
<p>I want a notification at run time removal of sim card from android phone .</p>

<p>My Application is running on GingerBread while it is not running on HTC One V which runs on ICS and above.
Here is my code :</p>

<p>1)  Receiver Class</p>

<pre><code>package com.TestIt;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class SimEventReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent systemIntent) {
    // TODO Auto-generated method stub
    Intent intent=new Intent(context, SimService.class);
    context.startService(intent);
}

}
</code></pre>

<p>2)Service Class</p>

<pre><code>package com.TestIt;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class SimService extends Service {
TelephonyManager tele;
@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    Log.d("Kanishk", "In Service OnCreate");


    int simState = tele.getSimState();
    switch (simState)
    {
    case TelephonyManager.SIM_STATE_ABSENT:
        Log.d("kanishk", "onCreate1");
        TestItActivity.simState(this);
        break;
    case TelephonyManager.SIM_STATE_READY:
        Log.d("kanishk", "onCreate2");
        Toast.makeText(this, "Now Sim is ok", Toast.LENGTH_LONG).show();
        break;
    case TelephonyManager.SIM_STATE_UNKNOWN:
        Log.d("kanishk", "onCreate3");
        Toast.makeText(this, "not Known", Toast.LENGTH_LONG).show();
        break;
    }
}

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

}
</code></pre>

<p>3)Activity
    package com.TestIt;</p>

<pre><code>import android.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;

public class TestItActivity extends Activity {
/** Called when the activity is first created. */
private  static final String tag = "Activity";
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    Log.d(tag, "OnCreate");
    setContentView(R.layout.main);
}
public static void simState()
{
    Log.d(tag, "Sim State");
}
}
</code></pre>

<p>4)Manifest.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.systemEvent"
android:versionCode="1"
android:versionName="1.0" &gt;

&lt;uses-sdk android:minSdkVersion="14" /&gt;

&lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;

&lt;application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" &gt;
    &lt;activity
        android:name=".SystemEventActivity"
        android:label="@string/app_name" &gt;
        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.MAIN" /&gt;

            &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;

    &lt;receiver
        android:name=".BroadCastReceiverS"
        android:enabled="true"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED" &gt;
        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;

            &lt;category android:name="android.intent.category.DEFAULT" /&gt;
        &lt;/intent-filter&gt;
    &lt;/receiver&gt;

    &lt;service android:name=".MyService" &gt;
    &lt;/service&gt;
&lt;/application&gt;

&lt;/manifest&gt;
</code></pre>
