java - 在 Android 应用程序中添加 IMEI 号码?

标签 java android imei

我必须在这个邮件正文部分添加一个 IMEI 号码。我试过这个方法,但我不能。

TelephonyManager telephonyManager =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId(); 

如何获取和打印 body 部位的 IMEI 号码?

public void sendMail(String body, String sender, String recipients, String scilNo)
        throws Exception {
    try {


        File folder = new File(Environment.getExternalStorageDirectory().toString() + "/TEB/Log");
        folder.mkdirs();
        String extStorageDirectory = folder.toString();

        SimpleDateFormat sdfDate = new SimpleDateFormat("dd-MM-yyyy__HH-mm-ss");
        now = new Date();
        String strDate = sdfDate.format(now);
        File file = new File(extStorageDirectory, strDate + ".txt");

        file.createNewFile();

        String cmd = "logcat -d -v long -f " + file.getAbsolutePath()
                + " *:V";
        Runtime.getRuntime().exec(cmd);

        DataSource source = new FileDataSource(file);

        MimeBodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(file.getName());

        StringBuilder sb = new StringBuilder();
        sb.append(String.format("%10s: %s\n", "Gönderen", scilNo));
        sb.append(String.format("%10s: %s\n", "Mesaj", body ));

        DataHandler handler = new DataHandler(new ByteArrayDataSource(sb.toString().getBytes(), "text/plain"));

        MimeBodyPart messageBodyPart2 = new MimeBodyPart();
        messageBodyPart2.setDataHandler(handler);

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);
        multipart.addBodyPart(messageBodyPart2);

        final MimeMessage message = new MimeMessage(session);
        message.setContent(multipart);
        message.setSender(new InternetAddress(sender));
        message.setSubject("Hata Bildirim Mesajı");


        if (recipients.indexOf(',') > 0) {
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(recipients));
        } else {
            message.setRecipient(Message.RecipientType.TO,
                    new InternetAddress(recipients));
        }

        Thread mySend = new Thread(new Runnable() {

            @Override
            public void run() {
                try {

                    Transport transport = session.getTransport("smtp");
                    transport.connect(mailhost, user, password);
                    transport = session.getTransport("smtp");
                    Transport.send(message, message.getAllRecipients());
                    transport.close();
                    LogUtil.i("Mail SEND DONE");
                } catch (MessagingException e) {
                    LogUtil.e("GMailSender.sendMail.MessagingException", e);
                }
            }

        });
        mySend.start();

    } catch (Exception e) {
        LogUtil.e("GMailSender.sendMail.Exception", e);
    }
}

最佳答案

您需要将其添加到 list 文件中

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

然后试试这个 -

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();

在模拟器中,您可能会得到类似“00000...”的值。如果设备 ID 不可用,getDeviceId() 返回 NULL。

查看this链接供引用。

关于java - 在 Android 应用程序中添加 IMEI 号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24931927/

相关文章:

java - try-with-resources 语句的目的是什么?

java - DB-sqlite android,不工作

mobile - 如何从 IMEI 中检索 TAC?

c++ - 如何在 blackberry 10 native 中获取 IMEI 号码

Java赋值运算符

java - 在没有 NetBeans 的情况下构建 JavaFX 项目

java - java boolean 读取方法的命名策略

java - 在Android中对ArrayList中的单个值下的数据列表进行分类。(参见说明)

Android Studio Cmake 构建错误 : invalid conversion between vector type

android - 如何在 PhoneGap 中获取 IMEI 号码?