I have error when refer to LogCat. I have store the storedsimcard(1st) and compare with currentsimcard(2nd), if sim serial is different, logcat will print out sim changed. But i had problem with my service when i run it. Below is my code
LogCat showing
Tag SimSerial:: 8944110065486249080
Tag Current Sim Serial:: 8944110065486249080
Tag Sim Status Sim no changed !!!
Tag SimSerial:: 8944110065486249080
Tag Current Sim Serial:: 8944110065486249080
Tag Sim Status Sim changed !!!
First part is correct, but the second part Sim Status should no "Sim no changed" as well.
Does anyone know where is the error ?
BootCompleteReceiver
public class BootCompleteReceiver extends BroadcastReceiver {
Context context;
SharedPreferences settings;
public static final String PREFS_NAME = "MyPrefsFile";
#Override
public void onReceive(Context context, Intent intent) {
Intent service = new Intent(context, MyService.class);
context.startService(service);
}
}
MyService
public class MyService extends Service {
String storedSimSerial;
String currentSimSerial;
#Override
public void onCreate() {
super.onCreate();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
TelephonyManager telephoneMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
storedSimSerial = telephoneMgr.getSimSerialNumber();
Log.e("SimSerial::",storedSimSerial);
TelephonyManager tmMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
currentSimSerial = tmMgr.getSimSerialNumber();
Log.e("Current Sim Serial::",currentSimSerial);
if(currentSimSerial==storedSimSerial)
{
Log.e("Sim Status","Sim no changed !!!");
}
else
Log.e("Sim Status","Sim changed !!!");
return Service.START_STICKY;
}
#Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroy", Toast.LENGTH_LONG).show();
}
#Override
public IBinder onBind(Intent arg0) {
return null;
}
}
Write your if like this:
if(currentSimSerial.equals(storedSimSerial))
{
Log.e("Sim Status","Sim no changed !!!");
}
else
Log.e("Sim Status","Sim changed !!!");
When you use == you compare Object references, not content which rarely works for Strings.
Related
I am using following UsbSerial example from below link https://github.com/felHR85/SerialPortExample. I want receive data from over usb from the device shown in the photo.
Device is basically a counter machine which is sending counter data over serial port.
I am able to connect device and open port from it but unable to read data stream from it. Below is the code used. code is not giving any error
Mainactivity class
public class MainActivity extends AppCompatActivity {
/*
* Notifications from UsbService will be received here.
*/
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case UsbService.ACTION_USB_PERMISSION_GRANTED: // USB PERMISSION GRANTED
Toast.makeText(context, "USB Ready", Toast.LENGTH_SHORT).show();
break;
case UsbService.ACTION_USB_PERMISSION_NOT_GRANTED: // USB PERMISSION NOT GRANTED
Toast.makeText(context, "USB Permission not granted", Toast.LENGTH_SHORT).show();
break;
case UsbService.ACTION_NO_USB: // NO USB CONNECTED
Toast.makeText(context, "No USB connected", Toast.LENGTH_SHORT).show();
break;
case UsbService.ACTION_USB_DISCONNECTED: // USB DISCONNECTED
Toast.makeText(context, "USB disconnected", Toast.LENGTH_SHORT).show();
break;
case UsbService.ACTION_USB_NOT_SUPPORTED: // USB NOT SUPPORTED
Toast.makeText(context, "USB device not supported", Toast.LENGTH_SHORT).show();
break;
}
}
};
private UsbService usbService;
private TextView display;
private EditText editText;
private MyHandler mHandler;
private final ServiceConnection usbConnection = new ServiceConnection() {
#Override
public void onServiceConnected(ComponentName arg0, IBinder arg1) {
usbService = ((UsbService.UsbBinder) arg1).getService();
usbService.setHandler(mHandler);
}
#Override
public void onServiceDisconnected(ComponentName arg0) {
usbService = null;
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mHandler = new MyHandler(this);
display = (TextView) findViewById(R.id.textView1);
editText = (EditText) findViewById(R.id.editText1);
Button sendButton = (Button) findViewById(R.id.buttonSend);
sendButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!editText.getText().toString().equals("")) {
String data = editText.getText().toString();
if (usbService != null) { // if UsbService was correctly binded, Send data
display.append(data);
usbService.write(data.getBytes());
}
}
}
});
}
#Override
public void onResume() {
super.onResume();
setFilters(); // Start listening notifications from UsbService
startService(UsbService.class, usbConnection, null); // Start UsbService(if it was not started before) and Bind it
}
#Override
public void onPause() {
super.onPause();
unregisterReceiver(mUsbReceiver);
unbindService(usbConnection);
}
private void startService(Class<?> service, ServiceConnection serviceConnection, Bundle extras) {
if (!UsbService.SERVICE_CONNECTED) {
Intent startService = new Intent(this, service);
if (extras != null && !extras.isEmpty()) {
Set<String> keys = extras.keySet();
for (String key : keys) {
String extra = extras.getString(key);
startService.putExtra(key, extra);
}
}
startService(startService);
}
Intent bindingIntent = new Intent(this, service);
bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);
}
private void setFilters() {
IntentFilter filter = new IntentFilter();
filter.addAction(UsbService.ACTION_USB_PERMISSION_GRANTED);
filter.addAction(UsbService.ACTION_NO_USB);
filter.addAction(UsbService.ACTION_USB_DISCONNECTED);
filter.addAction(UsbService.ACTION_USB_NOT_SUPPORTED);
filter.addAction(UsbService.ACTION_USB_PERMISSION_NOT_GRANTED);
registerReceiver(mUsbReceiver, filter);
}
/*
* This handler will be passed to UsbService. Data received from serial port is displayed through this handler
*/
private static class MyHandler extends Handler {
private final WeakReference<MainActivity> mActivity;
public MyHandler(MainActivity activity) {
mActivity = new WeakReference<>(activity);
}
#Override
public void handleMessage(Message msg) {
mActivity.get().display.append("Handle:");
switch (msg.what) {
case UsbService.MESSAGE_FROM_SERIAL_PORT:
String data = (String) msg.obj;
mActivity.get().display.append(data);
break;
}
}
}
}
I know it's bit late, however just to help others who might come across similar issue, did you find solution to your problem? If not, I cannot see the other java file corresponding to the service (USBService.java) as described in the example referred by you. The same file contains following code snippet which you would like to debug to find out what's going wrong (could be a problem with byte to string conversion or so). Hope this helps.
/*
* Data received from serial port will be received here. Just populate onReceivedData with your code
* In this particular example. byte stream is converted to String and send to UI thread to
* be treated there.
*/
private UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback()
{
#Override
public void onReceivedData(byte[] arg0)
{
try
{
String data = new String(arg0, "UTF-8");
if(mHandler != null)
mHandler.obtainMessage(MESSAGE_FROM_SERIAL_PORT,data).sendToTarget();
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
}
};
Backgroud
I am developing an app which makes calls like lollpop. When a call comes it should show a popup on the screen and the default calling screen should not be visible.
What I have done
I have build the broadcast receiver and currently I am able to show a popup every time a call come.
by using this code
public class PhoneCallReceive extends BroadcastReceiver {
Class<?> c;
public static ITelephony telephonyService = null;
TelephonyManager telephony;
Method m;
public static int flag = 0;
public static AudioManager audioManager;
#Override
public void onReceive(Context conk, Intent inter) {
final Context context = conk;
final Intent intent = inter;
Thread pageTimer = new Thread() {
public void run() {
try {
sleep(800);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
try {
telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
c = Class.forName(telephony.getClass().getName());
m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
audioManager = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);
} catch (Exception e) {
e.printStackTrace();
}
if (telephony.getCallState() == 1)
flag = 1;
Log.d("Rec", "reciever");
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
callingscreen("1", context, intent);
}
}
};
pageTimer.start();
}
public void callingscreen(final String type, final Context context,
final Intent intent) {
Intent intentPhoneCall = new Intent(context.getApplicationContext(),
CallerScreen.class);
intentPhoneCall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
intentPhoneCall.putExtra(
"number",
intent.getExtras().getString(
TelephonyManager.EXTRA_INCOMING_NUMBER));
intentPhoneCall.putExtra("type", type);
context.startActivity(intentPhoneCall);
}
} // class
Problem
But the Problem is that this popup is showing over the default calling screen. What I want to show the popup on the user current screen on which he was working.
Question
So the simple question is that how can I get the user current screen with its all functionality below the popup?
Please help:)
This solution works on every version of android, including lollipop
Use this broadcast reciever
class TeleListener extends PhoneStateListener {
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
// CALL_STATE_IDLE;
Toast.makeText(getApplicationContext(), "CALL_STATE_IDLE",
Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
// CALL_STATE_OFFHOOK;
Toast.makeText(getApplicationContext(), "CALL_STATE_OFFHOOK",
Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
// CALL_STATE_RINGING, call intent here
Intent i = null;
i = new Intent(context, My_activity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
break;
default:
break;
}
}
}
and register it like this in onCreate
TelephonyManager TelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
TelephonyMgr.listen(new TeleListener(), PhoneStateListener.LISTEN_CALL_STATE);
And yes, please dont miss
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Cheers! Your problems is solved ;)
Currently i am facing a problem that i dont know how to solve. Basically my application connects to a XMPP chat and keeps notifying the user when a friend's status has changed. Everything working as expected. Today i advanced to the next step which is, keep sending push notifications to the user even if the application is destroyed. I have managed to keep the service running after the application ends, but for some reason, the connection to my XMPP chat ends when the application is terminated. I have no idea why and i would really apreciate some help. Here is my Service Code:
package ...
import ...
public class ChatService extends Service {
private final IBinder mBinder = new ChatBinder();
public static final String F_TAG = "ChatService";
private Context context;
public static LoginCallBack loginCallBack;
public static StatusChangedCallBack statusChangedCallBack;
private String username;
private String server;
private String password;
public ChatServer getChatServer() {
return chatServer;
}
private ChatServer chatServer;
private HashMap<String, ArrayList<Friend>> listDataChild;
private ArrayList<String> listDataHeader;
#Override
public IBinder onBind(Intent intent) {
Log.i("S_TAG", "Service Binded");
return mBinder;
}
#Override
public boolean onUnbind(Intent intent) {
Log.i("S_TAG", "Service Unbinded");
return super.onUnbind(intent);
}
#Override
public void onCreate() {
Log.i("S_TAG", "Service Created");
initListDataHeader();
super.onCreate();
}
#Override
public void onDestroy() {
Log.i("S_TAG", "Service Destroyed");
super.onDestroy();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
SharedPreferences prefs = this.getSharedPreferences(...);
username = prefs.getString("username", null);
password = prefs.getString("password", null);
server = prefs.getString("server", null);
if (username != null && password != null & server != null) {
Log.i("T_TAG", username + password + server);
new Thread(new Runnable() {
#Override
public void run() {
// Connect to the RIOT CHAT XMPP
chatServer = new ChatServer(server);
chatServer.connect();
chatServer.login(username, password);
if (chatServer.isConnected()) { //&& chatServer.isAuthenticated()) {
if (chatServer.isAuthenticated()) {
loginCallBack.onLogin(chatServer.isAuthenticated());
Roster roster = chatServer.getConnection().getRoster();
roster.addRosterListener(new RosterListener() {...});
} else {
// Authentication Error
loginCallBack.onError(1);
}
} else {
loginCallBack.onError(0);
}
}
}).start();
} else {
loginCallBack.onError(2);
stopSelf();
}
return Service.START_STICKY;
}
#Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
LogPrint.print(context, "Started Service");
}
public HashMap<String, ArrayList<Friend>> getListDataChild() {
...
return listDataChild;
}
public ArrayList<String> getListDataHeader() {
return listDataHeader;
}
public void initListDataHeader() {
...
}
public class ChatBinder extends Binder {
public ChatService getService() {
return ChatService.this;
}
}
public FriendHolder findFriend(HashMap<String, ArrayList<Friend>> friends, String user) {
...
}
private HashMap<String, ArrayList<Friend>> swapFriends(HashMap<String, ArrayList<Friend>> listDataChild, String onlineOrOffline, int positionToRemoveUpdate) {...
}
private HashMap<String, ArrayList<Friend>> sendPushToActionBar (Presence p, Friend friend, Presence.Type oldPresenceType){...
}
Any idea about what is causing the issue? I would like any tips that leads me to the right direction as well as tips about wrong implementation and things to improve in the code if possible. Thank you in advanced.
EDIT1: There is missing in the code the part that disables the callbacks if the application is destroyed (because there is nothing to update in the application if there is none running, just send the push notifications), but for now i just want to understand why the connection ends.
EDIT2: I am using aSmack, i could upload the code but i honestly think the problem is somewhere here in the service.
I have found out the solution, although forgot to close the case. The provided code is working as intended, I was just missing an exception that was being happening and it made the service restart itself and thus, lose the connection.
I have asked this question here but it was marked as duplicate -
however I didn't find any solution helpful mentioned in comments.
Here, I am asking again with more details ...
I am doing a sample app (PoC) on HCE and using HostApduService as per Android user guide. I have created two apps
1) ReaderApp - acting as card reader
2) HCEApp - emulating a card
In HCEApp, I have created a class 'MyService' extending HostApduService
public class MyService extends HostApduService {
private int messageCounter;
private final String TAG = "MyService";
Intent mIntent;
#Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "onCreate");
mIntent = new Intent(this, MyActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(mIntent);
}
/**
* returned bytes will be sent as response. This method runs in Main thread
* so return ASAP.
*/
#Override
public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
if (selectAidApdu(apdu)) {
Log.i(TAG, "Application selected");
return getWelcomeMessage();
} else {
Log.i(TAG, "Received: " + new String(apdu));
return getNextMessage();
}
}
private byte[] getWelcomeMessage() {
return "Hello Desktop!".getBytes();
}
private byte[] getNextMessage() {
return ("Message from android: " + messageCounter++).getBytes();
}
private boolean selectAidApdu(byte[] apdu) {
if (apdu != null) {
for (byte b : apdu) {
System.out.printf("0x%02X", b);
}
}
return apdu.length >= 2 && apdu[0] == (byte) 0
&& apdu[1] == (byte) 0xa4;
}
#Override
public void onDeactivated(int reason) {
Log.i(TAG, "Deactivated: " + reason);
}
#Override
public boolean onUnbind(Intent intent) {
return super.onUnbind(intent);
}
}
As you can see in onCreate(), I am launching MyActivity provides user to enter some information and needs to be sent back to MyService.
I think I can not use binding as 'onBind()' is declared final in HostApduService as below
#Override
public final IBinder onBind(Intent intent) {
return mMessenger.getBinder();
}
Please let me know if I am understading it correctly. Appreciate any help.
Thanks
iuq
Whether you can use onBind or not I do not know, but I recently worked with a BroadcastReceiver from which I had to start a Service. You cannot bind a Service from a BroadcastReceiver according to docs, you can only start it. I needed to send some data to the Service from my BroadcastReceiver at some later point, and since the binder techniques was not available to me, I had to find a different way to communicate with the Service, much like your case where you don't have a reference to it.
I did some research but could not find any solution, but then I remembered that you can pass intent data with the startService(intent) call. I start my Service work in onCreate instead, as onCreate is only called once when the Service is created.
In your Activity
public void sendDataToService(){
Intent intent = new Intent(context, MyService.class);
intent.putExtra("message", SOME_DATA);
context.startService(intent);
}
In your Service
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Check if intent has extras
if(intent.getExtras() != null){
// Get message
int message = intent.getExtras().getInt("message");
}
return START_NOT_STICKY;
}
This may be some sort what of a hack since "startService" does not sound like it should be used to send messages, and am not sure if this is exactly what you need, but it worked for me, so I hope it works for you. Cheers
Edit: BTW. I use it to tell a LocationService that a particular activity no longer want location updates.
I ended up taking a different approach to solving this same problem. When I bind to my HostApduService subclass, I grab a handle to the Messenger interface returned by the HostApduService onBind implementation.
Here's some sample code. This would all go in your activity implementation (calling it MyActivity here, communicating with MyHostApduServiceSubclass). Here's what MyActivity would need to include:
private Messenger mAPDUMessenger;
...
#Override
protected void onStart() {
super.onStart();
Context context = getApplicationContext();
Intent apduIntent = new Intent(montext, ContactlessApduService.class);
context.bindService(apduIntent, mAPDUConnection, Context.BIND_AUTO_CREATE);
}
...
private ServiceConnection mAPDUConnection = new ServiceConnection() {
#Override
public void onServiceConnected(ComponentName className, IBinder service) {
// The HostApduService has a final override on the onBind() service method that returns
// an IMessageHandler interface that we can grab and use to send messages back to the
// terminal - would be better to get a handle to the running instance of the service so
// that we could make use of the HostApduService#sendResponseApdu public method
mAPDUMessenger = new Messenger(service);
registerAPDUMessengerIntentFilters();
// ^ This method sets up my handlers for local broadcast messages my BroadcastReceiver processes.
}
...
}
...
private void registerAPDUMessengerIntentFilters() {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(MyActivity.this);
IntentFilter intentFilter = new IntentFilter(MyHostApduServiceSubclass.ACTION_PPSE_APDU_SELECT);
lbm.registerReceiver(apduMessageBroadcastReceiver, intentFilter);
}
...
BroadcastReceiver apduMessageBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(MyHostApduServiceSubclass.ACTION_PPSE_APDU_SELECT)) {
sendResponseApdu(MyActivity.PPSE_APDU_SELECT_RESPONSE_BYTES);
}
}
};
...
public final void sendResponseApdu(byte[] responseApdu) {
Message responseMsg = Message.obtain(null, MyHostApduServiceSubclass.MSG_RESPONSE_APDU);
// ^ Note here that because MSG_RESPONSE_APDU is the message type
// defined in the abstract HostApduService class, I had to override
// the definition in my subclass to expose it for use from MyActivity.
// Same with the KEY_DATA constant value below.
Bundle dataBundle = new Bundle();
dataBundle.putByteArray(MyHostApduServiceSubclass.KEY_DATA, responseApdu);
responseMsg.setData(dataBundle);
try {
mAPDUMessenger.send(responseMsg);
} catch (RemoteException e) {
// Do something with the failed message
}
}
And then your HostApduService subclass would just need to send a broadcast to your activity indicating what APDU command was received. Here is what would need to be included in MyHostApduServiceSubclass:
public static final String ACTION_PPSE_APDU_SELECT = "ACTION_PPSE_APDU_SELECT";
// Abstract super class constant overrides
public static final String KEY_DATA = "data";
public static final int MSG_RESPONSE_APDU = 1;
#Override
public byte[] processCommandApdu(byte[] commandApdu, Bundle extras) {
Context context = getApplicationContext();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
if (Arrays.equals(MyHostApduServiceSubclass.PPSE_APDU_SELECT_BYTES, commandApdu)) {
lbm.sendBroadcast(new Intent(ACTION_PPSE_APDU_SELECT));
}
return null;
// ^ Note the need to return null so that the other end waits for the
// activity to send the response via the Messenger handle
}
I am doing a app on sim tracking but unable to get result
here is the main activity
public class MainActivity extends Activity {
String FILENAME = "old_file.txt";
int simstatus;
String simNo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (simstatus != TelephonyManager.SIM_STATE_ABSENT) {
System.out.println("--------SIM Present:" + simstatus);
simNo = tManager.getSimSerialNumber();
FileOutputStream fos;
try {
fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(simNo.getBytes());
System.out.println("---------Data written to files is:"
+ simNo);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Reciever
public class SimDataReciever extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
System.out.println("Reciever Started");
Intent CompareSimServiceIntent = new Intent(context,demo.class);
context.startService(CompareSimServiceIntent);
}
}
}
and the service..
String FILENAME = "old_file.txt";
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
public int onStartCommand(Intent intent, int flags, final int startId) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
#Override
public void run() {
//run your service
// Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
try {
FileInputStream fis = openFileInput(FILENAME);
InputStreamReader in = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(in);
String data = br.readLine();
System.out.println("---Data Read From File is:" + data);
String newsiminfo = tManager.getSimSerialNumber();
System.out.println("---New SIM no is:" + newsiminfo);
if (data.equals(tManager.getSimSerialNumber())) {
System.out.println("------Old sim Present:");
// Toast.makeText(this, "Old SIM", Toast.LENGTH_LONG).show();
} else {
// Toast.makeText(this, "New SIM", Toast.LENGTH_LONG).show();
SmsManager smsMngr = SmsManager.getDefault();
String destinationaddress = "8281306132";
String scAddress = null;
String text = "New Sim Is Inserted In Your Device";
PendingIntent sentIntent = null;
PendingIntent deliveryIntent = null;
smsMngr.sendTextMessage(destinationaddress, scAddress, text,
sentIntent, deliveryIntent);
System.out.println("-----SMS Send");
}
} catch (Exception e) {
}
}
}, 1*60*1000);
return startId;
}
}
pls help me to find the solution....
I have found similar kind of problem, when working on same kind of project.
I was also not able to track the sim after the device reboot. The problem I found here was that I was invoking the sim tracking immediately after the device reboot. But the system takes 15 to 20 seconds to load resources. The sim was not getting launched immendiately after the device reboot, so my receiver was unable to track the sim.
So, I delayed the sim tracking for 20 seconds after the device reboot. Try to delay the sim tracking and check if it works.
Edit-
Your Receiver should be like this,
public class SimDataReciever extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
System.out.println("Reciever Started");
Log.d("BOOT COMPLETE","Receiver Called");
Intent CompareSimServiceIntent = new Intent(context,demo.class);
context.startService(CompareSimServiceIntent);
}
}
and in Manifest file, replace your code with this,
<receiver android:name=".SimDataReciever"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Now, check whether the messages are shown in the logcat or not.