First, you have to add permissions to start at bootup, get device id and send sms in AndroidManifest.xml. (More: receive bootup, permission, read imei, send sms)
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SEND_SMS" />
Then you have to add broadcast receiver component to your application in AndroidManifest.xml.
<receiver android:name=".BootReceiverMessageSender">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.NONE" />
</intent-filter>
</receiver>
After that, you need to create the java class.
class BootReceiverMessageSender extends BroadcastReceiver {
private static final String DESTINATION_NUMBER="+..."; /* phone number */
@Override
public void onReceive(Context c, Intent i) {
TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); /* get a TelephonyManager instance */
String deviceId = tm.getDeviceId(); /* get the id of device (gsm: imei, cdma: meid / esn) */
if(deviceId != null) { /* check if not null */
SmsManager smsManager = SmsManager.getDefault(); /* get a SmsManager instance */
smsManager.sendTextMessage(DESTINATION_NUMBER, null, "My ID: " + deviceID, null, null); /* Send SMS */
}
}
}
It's the easiest, but not the best way to do it!