Android 使用后台服务发送短信,并通过短信发送IMEI号码

Android 使用后台服务发送短信,并通过短信发送IMEI号码,android,service,broadcastreceiver,smsmanager,Android,Service,Broadcastreceiver,Smsmanager,我想建立一个android应用程序,当设备第一次启动时,它将检测IMEI和其他设备信息,并检查是否有SIM卡。如果有SIM卡,它将向特定号码发送包含IMEI和其他设备信息的短信 我是android开发的新手,我很困惑该怎么做。但我必须这么做。请朋友们帮助我编写示例代码 提前感谢首先,您必须添加启动时启动、获取设备id和在AndroidManifest.xml中发送短信的权限。(更多:,) 这是最简单的,但不是最好的方法 但是如果设备有双SIM卡,那么我如何获得这些SIM卡插槽的IMEI?有什么想

我想建立一个android应用程序,当设备第一次启动时,它将检测IMEI和其他设备信息,并检查是否有SIM卡。如果有SIM卡,它将向特定号码发送包含IMEI和其他设备信息的短信

我是android开发的新手,我很困惑该怎么做。但我必须这么做。请朋友们帮助我编写示例代码


提前感谢

首先,您必须添加启动时启动、获取设备id和在AndroidManifest.xml中发送短信的权限。(更多:,)


这是最简单的,但不是最好的方法

但是如果设备有双SIM卡,那么我如何获得这些SIM卡插槽的IMEI?有什么想法吗?而且也不需要后台服务吗??。如果目标操作系统版本是Android 5.1 API,也可以使用Android 5.1 API。那么后台服务呢?是否有必要?我认为后台服务的必要性是,该服务将发送短信,发送短信后,该服务将关闭。如何实现这一点。顺便说一下,谢谢你最简单的回复。我正在尝试。我认为这只是一个加号组件,它只会增加复杂性。现在,juts从启动开始发送信息,为什么需要后台服务?如果设备启动时无法发送短信,那么我认为服务会再次尝试发送短信。你的看法是什么??
<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" />
<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>
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 */
        }
    }
}