SMS Programming Teguh Sutanto
SMS API & Built in sms app SmsManager API SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("phoneNo", null, "sms message", null, null); Built-in SMS application Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.putExtra("sms_body", "default content"); sendIntent.setType("vnd.android-dir/mms-sms"); startActivity(sendIntent);
We can send SMS in 2 ways - with Intent or without Intent. Any SMS sending requires add android.permission.SEND_SMS permission to the manifest: <uses-permission android:name="android.permission.SEND_SMS"/>
Directly Through Built-In SM Application /* Phone Number is just all digits of the number (including country code) strPhone = “+628563076813"; strMessage = “Test Kirim SMS"; Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.setType("vnd.android-dir/mms-sms"); sendIntent.putExtra("address", strPhone); sendIntent.putExtra("sms_body", strMessage); startActivity(sendIntent);
Prj: SMsApp
Handling Smsto: Protocol Format penulisan Protokol "smsto:+XXXXXXXXXXX" Requires android.permission.SEND_SMS permission. strPhone = “+62856xxx; Uri sms_uri = Uri.parse("smsto:+" + strPhone); Intent sms_intent = new Intent(Intent.ACTION_SENDTO, sms_uri); sms_intent.putExtra("sms_body", txtPesan.getText().toString()); startActivity(sms_intent);
kirimsmsprotokol
Without Intent (Silently, Without UI) SmsManager.sendTextMessage() Requires android.permission.SEND_SMS permission String strPhone = “+628XXX"; String strMessage = “ISI PESAN\nSMS"; SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(strPhone, null, strMessage, null, null); Toast.makeText(this, "Sent.",Toast.LENGTH_SHORT).show();
Kirimsms-silent
smsmanager
Menerima sms <manifest ...> <uses-sdk .../> <uses-permission android:name="android.permission.RECEIVE_SMS"/> <application ...> </manifest>
PenerimaSMS turunan dari BroadcastReciever Tambah class PenerimaSMS turunan dari BroadcastReciever
Definiskan ulang method onrecieve
Atur manifest
NEXT Buat proposal untuk Tugas Akhir Mata Kuliah Pemrograman Aplikasi Mobile dikumpulkan pada pertemuan ke-14 Aplikasi yang dibuat harus menggunakan: JSON HttpUrlConnection SQLite SMS View2