20.11.2016 Views

ANDROID APP

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

การใช้งาน SMS<br />

197<br />

หลังจากการใช้คำสั่ง divideMessage() เพื่อตัดข้อความแล้ว เราจะใช้เมธอด sendMulti-<br />

PartMessage() ทำการส่งข้อความชุดดังกล่าว ซึ่งวิธีการใช้งานคำสั่งนี้จะเหมือนกับการใช้คำสั่ง<br />

sendMultipartTextMessage() โดยจะใช้ ArrayList เพื่อเก็บข้อมูลของข้อความที่ส่ง และ<br />

สถานะการรับ-ส่ง ดังนี้<br />

ArrayList multiSMS = mySMS.divideMessage(msg);<br />

ArrayList sentIns = new ArrayList();<br />

ArrayList deliverIns = new ArrayList();<br />

for(int i=0; i< multiSMS.size(); i++){<br />

sentIns.add(sentIn);<br />

deliverIns.add(deliverIn);<br />

}<br />

mySMS.sendMultipartTextMessage(destination, null,<br />

multiSMS, sentIns, deliverIns);<br />

กรรมวิธี: การส่ง SMS แบบอัตโนมัติเมื่อมีการรับข้อความแล้ว<br />

ในกรณีที่ผู้รับได้รับข้อความ SMS แล้ว แต่ยังไม่ได้อ่านข้อความดังกล่าว เราก็สามารถเขียนชุด<br />

คำสั่งเพื่อสั่งให้ระบบส่ง SMS แบบอัตโนมัติเมื่อมีการรับข้อความแล้วได้ ในกรณีนี้เราจะสร้างเซอร์วิส<br />

แบบทำงานแบบเบื้องหลังเพื่อคอยรับข้อความ SMS ที่ส่งเข้ามา<br />

การทำงานของกระบวนการนี้จะต้องมีการกำหนดสิทธิ์ในการใช้งาน โดยกำหนดไว้ในไฟล์<br />

Manifest ดังแสดงในชุดคำสั่งที่ 8.1 ซึ่งมีการประกาศแอคทิวิตี้ SMSResponder ที่จะใช้สร้างระบบ<br />

ตอบกลับแบบอัตโนมัติ และเซอร์วิส ResponderService ซึ่งจะใช้ในการส่งข้อความตอบกลับ<br />

ชุดคำสั่งที่ 8.1 AndroidManifest.xml<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!