0

我正在开发一个安卓应用程序。我想将收件箱短信保存到 sql 数据库服务器。这是我的安卓代码

public void onReceive(Context context, Intent intent) {
        final Bundle bundle = intent.getExtras();
        try {
            if (bundle != null) {
                final Object[] pdusObj = (Object[]) bundle.get("pdus");
                for (int i = 0; i < pdusObj.length; i++) {
                    SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                    String phoneNumber = currentMessage.getDisplayOriginatingAddress();
                    String senderNum = phoneNumber;
                    String message = currentMessage.getDisplayMessageBody();
                    DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
                    DateFormat df2 = new SimpleDateFormat("HH:mm");
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTimeInMillis(currentMessage.getTimestampMillis());
                    String cDate = df1.format(calendar.get(Calendar.DATE));
                    String cTime = df2.format(calendar.get(Calendar.HOUR_OF_DAY));
                    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                    String ime = tm.getDeviceId();
                    useGet(ime, cDate, cTime, "0", senderNum, message);
                }
            }
        } catch (Exception e) {
            Log.e("SmsReceiver", "Exception smsReceiver" +e);
        }
    }

通过useGet(ime, cDate, cTime, "0", senderNum, message);方法,我点击了一个 url,并希望将所有点击的短信保存在我的 sql 数据库中。

4

0 回答 0