You need to register a broadcast receiver for the download completion action ie android.intent.action.BOOT_COMPLETED
In the onReceive of this receiver, you can start your service to get a SIM number with a line below the code
TelephonyManager telephoneMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String phoneNumber = telephoneMgr.getLine1Number();
You must also have permission to read the phone number as READ_PHONE_STATE in the manifest file.
you can start the service from the broadcast receiver as -
public class BootListener extends BroadcastReceiver { @Override public void onReceive(Context context, Intent arg1) { Intent intent = new Intent(context,Myservice.class); context.startService(intent); }
}
source share