ç§ã®è³ªåãžã®åçã«åºã¥ããŠããã®ãããã¯ãå ¬éããŸãã ãã¢ã³ãã¹ãã ãã¯ããã®æ®µéã§ã¯éä¿¡è ã®ãã©ãã¯ãªã¹ãã«ãããªããããäœæãããã¢ããªã±ãŒã·ã§ã³ã®ããç¥å床ã®é«ãååã§ãã ãã ããå°æ¥çã«ã¯èªåãã£ã«ã¿ãªã³ã°ã§æ¬åœã«ã¹ãã 察çãè¡ãäºå®ã§ãã 以äžã®è³æã¯ãAndroidã®éçºã«å°ãªããšãå°ã粟éããŠãããç¬èªã®ã¢ããªã±ãŒã·ã§ã³ãéçºããããã«å°ãªããšãããã€ãã®æé ãèžãã 人åãã«èšèšãããŠããŸããéèŠãªãã€ã³ãã 誰ãæ°ã«ããªããç«ãžããããã
ã©ã®ããã«å§ãŸã£ãã®ãèŠããŠããŸããïŒ
å°ãåæ çãªäœè«ã ããã¯ãã¹ãŠãã©ããã§æºåž¯é»è©±çªå·ãæŒããããšããäºå®ããå§ãŸããŸããã ç§ãšåããµã€ãã«ç»é²ããå人ãåãã¹ãã ã¡ãã»ãŒãžãåæã«åä¿¡ãããããç§ã¯æ£ç¢ºã«ã©ãã«ããã®ãããçããŸãã ããããä»ã¯ããã«ã€ããŠã§ã¯ãããŸããã éææ¥ã«ãç§ã¯ããŸããŸãªã¯ã©ãããåºåãåãåãå§ããæ¯é±æ¯é±ã¡ãã»ãŒãžã®æµããå¢ããŸããã ç§ã¯Android OSããŒã¹ã®é»è©±ã®ææè ã«ãªã£ãã®ã§ããã®äžåèªã«å¯ŸåŠããã¢ããªã±ãŒã·ã§ã³ãäœæããããšã«ããŸããã ããã°ã©ããŒã¯ç°¡åãªæ¹æ³ãæ¢ãããšã¯ãããŸãããã¢ãã€ã«ãªãã¬ãŒã¿ãŒã«é£çµ¡ããããããŸããã§ãããããã«ãAndroidåãã®éçºãéå§ããããšãã£ãšæã£ãŠããŸããã
ã¢ããªã±ãŒã·ã§ã³ã®ã¢ãŒããã¯ãã£ãšã¬ã€ã¢ãŠã
ã¢ããªã±ãŒã·ã§ã³ã¯3ã€ã®éšåã§æ§æãããŠããŸãã
- å®éã«ã¯ãSMSã¡ãã»ãŒãžãåä¿¡ããŠââãã£ã«ã¿ãªã³ã°ãããã£ã«ã¿ãŒã
- éä¿¡è ãšéä¿¡è ããåä¿¡ããã¡ãã»ãŒãžã®ãã©ãã¯ãªã¹ããä¿åããããŒã¿ããŒã¹ã
- ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ãŒã¹
ã©ã®ããã«æ©èœããŸããïŒ ãŠãŒã¶ãŒã¯ãåä¿¡ãã¬ã€ãŸãã¯é£çµ¡å ããéä¿¡è ã®ãã©ãã¯ãªã¹ãã«è¿œå ããŸãã ãã£ã«ã¿ãŒããªã³ã«ããŠãã¢ããªã±ãŒã·ã§ã³ãéããŸãã ã¡ãã»ãŒãžãåä¿¡ãããšãã¢ããªã±ãŒã·ã§ã³ã¯éä¿¡è ãåæãããã©ãã¯ãªã¹ãã«èŒã£ãŠããå Žåããããããªããžããªã«ã¡ãã»ãŒãžãé 眮ããŠããŠãŒã¶ãŒããã£ã«ã¿ãŒãããã¡ãã»ãŒãžãåŸã§èŠãããšãã§ããããã«ããŸãã éä¿¡è ããã¯ãªãŒã³ãã®å ŽåãSMSã¯ãåä¿¡ããã¯ã¹ããã©ã«ããŒã«ãããŸãã
æåã®ãããã¿ã€ã
ããã«èšã£ãŠãã£ãã ããããæåã®ãããã¿ã€ãã®å®è£ ã¯1æ¥ãç¶ããŸããã§ããã å®éãç§ã¯ããã¹ãã¡ãã»ãŒãžãåä¿¡ããã€ãã³ãããã£ããããããšããŸããããã®ã€ãã³ãã®ãã³ãã©ãŒã§ã¯ãéä¿¡è ããã©ãã¯ãªã¹ãã«èŒã£ãŠãããã¹ãŠã®ã¡ãã»ãŒãžãInboxãã©ã«ããŒããåé€ããŸããã åé¡ã¯ãæºåž¯é»è©±ã®ææè ã«SMSã®åä¿¡ãç¥ãããä¿¡å·ãèããããšããããšã§ããåä¿¡ãã¬ã€ãéããŠããæ°ãããã®ã¯è¡šç€ºãããŸããã ãããŠãããã¯ã©ããããããè¯ããããŸããã ãã®ãããåä¿¡ãã¬ã€ã«å ¥ãåã§ãã£ãŠããã¡ãã»ãŒãžãååããæ¹æ³ãæ¢ãå§ããŸããã
ã¡ãã»ãŒãžã®åå
Android OSã¯ãSMSã®åä¿¡ãWI-FIã®ãªã³ãæ¥ç¶ã®å é»ãªã©ã®ã€ãã³ããããããŒããã£ã¹ããä»ããŠã¢ããªã±ãŒã·ã§ã³ã«éç¥ããããã«èšèšãããŠããŸãã ãã®ã¡ã«ããºã ãšAndroidã®äžè¬çãªã¢ãŒããã¯ãã£ã®è©³çŽ°ã«ã€ããŠã¯ã ãã¡ãïŒ4ã€ã®ç¿»èš³ïŒãã芧ãã ãã ã ãã®ãããªã·ã¹ãã ãããŒããã£ã¹ãçšã®ã¬ã·ãŒããŒïŒãªã¹ããŒïŒãäœæããã«ã¯ã次ã®ããšãè¡ãå¿ èŠããããŸãã
- BroadcastReceiverããç¶æ¿ããç¬èªã®ã¯ã©ã¹ãäœæããonReceiveã¡ãœããããªãŒããŒããŒãããŸãã
- ã·ã¹ãã ã«ç»é²ããã©ã®ã¿ã€ãã®ãã¥ãŒã¹ã¬ã¿ãŒãåãåããããã瀺ããŸãã
ãªã¹ããŒãäœæãã
public class SMSReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); if (pdus.length == 0) { return; } Sms sms = Sms.fromPdus(pdus, context); SmsDatabase db = null; try { db = SmsDatabase.open(context); if (Filter.filter(context).isSpam(sms, db)) { abortBroadcast(); db.messages().save(sms); } } finally { if (db != null) db.close(); } } }
onReceiveã¡ãœããã¯ãSMSã¡ãã»ãŒãžãé»è©±ã«å°çãããã³ã«ããªã¬ãŒãããŸãã intentãã©ã¡ãŒã¿ãŒããå¿ èŠãªæ å ±ããã¹ãŠæœåºã§ããŸãã 泚æäºé ã«ãããšãããã¥ã¡ã³ãã«ãããšãBroadcastReceiverããç¶æ¿ãããã¯ã©ã¹ã¯ãonReceiveã¡ãœããã®å®è¡äžã«ã®ã¿é¢é£ããŸãã ããã¯ãæå®ãããã¡ãœããã®å®è¡ãçµäºãããšããã«ãã·ã¹ãã ãã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãç Žæ£ã§ããããšãæå³ããŸãã ããã¯ãã¯ã©ã¹ã®ééçãã£ãŒã«ãã«æ å ±ãä¿åããªãããšãæå³ããŸãã
æåã®2è¡ã§ã¯ã PDUæ å ±ãååŸããŸãã 倧ãŸãã«èšãã°ãããã¯ãçã®ã圢åŒã®SMSã§ãã 空ãã©ããã確èªããåŸãSmsèªå·±èšè¿°ã¯ã©ã¹ã®éçfromPdusïŒïŒã¡ãœããã䜿çšããŠã¡ãã»ãŒãžæ å ±ãæœåºããããšããŸããããã«ã€ããŠã¯åŸè¿°ããŸãã
次ã«ãFilterã¯ã©ã¹ã䜿çšããŠãåä¿¡ããSMSã¡ãã»ãŒãžã®éä¿¡è ããã©ãã¯ãªã¹ãã«èŒã£ãŠãããã©ããã確èªããŸãã ããŒã¿ããŒã¹ã«ã¡ãã»ãŒãžãä¿åããabortBroadcastïŒïŒã¡ãœããã䜿çšããŠãããŒããã£ã¹ããäžæããããšãããã£ãå Žåã ããã¯ãSMSã«é¢ããéç¥ãåä¿¡ããããã«ç»é²ãããåªå 床ã®äœããã¹ãŠã®åä¿¡è ã¯ããã®ãããªã€ãã³ããçºçããããšããç¥ããªãããšãæå³ããŸãã ã¹ãã ã¡ãã»ãŒãžãåä¿¡ããå Žåã«ãŠãŒã¶ãŒã®éªéã«ãªããªãããã«ãåä¿¡è ã«æé«ã®åªå é äœãèšå®ããŸãïŒããã€ã¹ã§é³ãç«ãŠãŠæ¯åããåä¿¡è ãããé«ãïŒã 以äžã®åªå é äœã«ã€ããŠãèªã¿ãã ããã
ã¢ããªã±ãŒã·ã§ã³ã®ä»¥åã®ããŒãžã§ã³ã§ã¯ãonReceiveã¡ãœããã§ãããŒã¿ããŒã¹ãžã®æ¥ç¶ã2åéãããŸããã1åç®ã¯ã¡ãã»ãŒãžããã§ãã¯ãããšãã®Filterã¯ã©ã¹ã§ã2åç®ã¯SMSãããŒã¿ããŒã¹ã«æžã蟌ããšãã§ãã ãã ããonReceiveã¡ãœããã®å®è¡æéã¯10ç§ã«å¶éãããŠããã2ã€ã®æ¥ç¶ãé£ç¶ããŠéãããšã«ã¯æå³ããªãããããã®ã¢ãããŒããæŸæ£ããã³ãŒãã®ãçŸãããã®èŠ³ç¹ããã³ãŒãããããå°ãäžæ£ç¢ºãã«ããŸããã çµå±ãã¡ãœãããå²ãåœãŠãããæéãæºãããŠããªãå ŽåãAndroidã¯æ¬¡ã®åä¿¡è ã®ã¡ãœãããåŒã³åºãããŠãŒã¶ãŒã¯SMSã®åä¿¡ã«ã€ããŠéç¥ãããŸãã
ãªã¹ããŒç»é²
ãªã¹ããŒãäœæããŸããã 圌ã®ã·ã¹ãã ãç»é²ããããšã¯æ®ã£ãŠããŸãã ãããè¡ãã«ã¯2ã€ã®æ¹æ³ããããŸãã
- ããã°ã©ã ã§registerReceiverïŒïŒã¡ãœããã䜿çšããŸãã ãã®å Žåãåä¿¡è ã¯ããããç»é²ããã³ã³ããŒãã³ããçåããŠããéã®ã¿çåããŸãïŒéåžžãããã¯ã¢ã¯ãã£ããã£ã§ãïŒã
- AndroidManifestã䜿çšããŸãã ãã®å Žåãã¢ããªã±ãŒã·ã§ã³ãéããããŠããŠããããã«é»è©±ãåèµ·åãããŠããåä¿¡è ã¯çãç¶ããŸãïŒ
æããã«ã2çªç®ã®ãªãã·ã§ã³ã®æ¹ãåãå ¥ããããŸãã å®è£ æ¹æ³ãèŠãŠã¿ãŸãããã
<application android:label="@string/app_name" android:icon="@drawable/app_icon"> âŠâŠâŠâŠâŠ. âŠâŠâŠâŠâŠâŠâŠ.. <receiver android:name=".SMSReceiver" android:enabled="false"> <intent-filter android:priority="1000"> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> </application>
ããã§ã¯ãã¹ãŠãéåžžã«ç°¡åã§ãã åä¿¡è ã¯ã©ã¹ã®ååïŒandroidïŒnameïŒãæå®ãã次ã«intent-filterã¿ã°ã䜿çšããŠåªå 床ïŒandroidïŒpriorityã1000ãæ倧å€ã§ããæ¯åããŠé³ãåºãæšæºåä¿¡è ã®å Žåãåªå 床ã¯999ïŒãšè³Œèªããã€ãã³ãïŒ android.provider.Telephony.SMS_RECEIVEDïŒã
ãªã¹ããŒã®ãªã³ãšãªããåãæ¿ãã
åä¿¡è ã¯ããã©ã«ãã§ãªãã«ãªã£ãŠãããšèšãå¿ èŠããããŸãã ãã®çµæããŠãŒã¶ãŒã¯SMSåä¿¡è ãã¢ã¯ãã£ããŸãã¯éã¢ã¯ãã£ãã«ããããšã«ããããã£ã«ã¿ãŒããªã³ãŸãã¯ãªãã«ããããšãã§ããŸãã Filterã¯ã©ã¹ã«ã¯ãããã«å¯Ÿå¿ããã¡ãœããonïŒïŒãoffïŒïŒãenabledïŒïŒããããŸãã
ã¡ãªã¿ã«ãFilterã¯ã©ã¹ã¯ã·ã³ã°ã«ãã³ã¯ã©ã¹ã§ããã³ã³ããã¹ãã«äŸåãããšããäºå®ã«ãããããããã¢ããªã±ãŒã·ã§ã³å šäœã«å¯ŸããŠ1ã€ã®ãã£ã«ã¿ãŒãå¿ èŠã«ãªãããã§ãã SMSReceiverã¯ã©ã¹ã§ã¯ãéçãã£ã«ã¿ãŒïŒïŒã¡ãœãããä»ããŠãã£ã«ã¿ãŒã€ã³ã¹ã¿ã³ã¹ã«ã¢ã¯ã»ã¹ããæ¹æ³ã確èªã§ããŸãããã®ã¡ãœããã¯ãContextã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ããã©ã¡ãŒã¿ãŒãšããŠåãåããŸãã
private static Filter _filter; public static Filter filter(Context context) { if (_filter == null || !_filter._context.equals(context)) { _filter = new Filter(context); } return _filter; }
ãã®ãããªå®è£ ãå¯äžã®çã®å®è£ ã§ãããšäž»åŒµããããšã¯ãããŸããã ããè¯ããœãªã¥ãŒã·ã§ã³ãæäŸã§ããå Žåã¯ãåãã§æ€èšããŸãã
Filterã¯ã©ã¹ã®ã³ã³ã¹ãã©ã¯ã¿ãŒã§ãäœæ¥ã«å¿ èŠãªããŒã¿ãåæåããŸãã
private final ComponentName componentName; private final PackageManager packageManager; private Context _context; private Filter(Context context) { _context = context; String packageName = context.getPackageName(); String receiverComponent = packageName + ".SMSReceiver"; componentName = new ComponentName(packageName, receiverComponent); packageManager = context.getPackageManager(); }
componentNameã¯ãã¢ããªã±ãŒã·ã§ã³ã³ã³ããŒãã³ãïŒãã®å Žåã¯åä¿¡è ïŒã®å®å šä¿®é£Ÿåã§ãããã±ãŒãžåãšã¯ã©ã¹åïŒSMSReceiverïŒãå«ãŸããŸãã
packageManager-ååããããããã¢ããªã±ãŒã·ã§ã³ã³ã³ããŒãã³ãã管çããããã®ã¯ã©ã¹ã§ããããšã¯æããã§ãã
ãã£ã«ã¿ãŒãå«ãã¡ãœãããèããŠã¿ãŸãããïŒ
public void on() { if (!enabled()) { packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else { Util.showMessage(_context.getString(R.string.alreadyStarted), _context); } }
ããã§ã¯ãã¹ãŠãç°¡åã§ãã ã³ã³ããŒãã³ããæ¢ã«æå¹ã«ãªã£ãŠããå ŽåïŒenabledïŒïŒã¯èªå·±èšè¿°ã¡ãœããã§ããå°ãåŸã§æ€èšããŸãïŒããŠãŒã¶ãŒã«éç¥ãããªãã«ãªã£ãŠããå Žåã¯ãªã³ã«ããŸãã Utiléçã¯ã©ã¹ã¯èªå·±èšè¿°åã§ãããããŸããŸãªãã«ããŒé¢æ°ãå«ãŸããŠããŸãã ãã®å ŽåãshowMessageã¡ãœããã¯æšæºã®Toastã¯ã©ã¹ã䜿çšããŠç»é¢ã«ã¡ãã»ãŒãžã衚瀺ããŸãã
ãã£ã«ã¿ãŒãç¡å¹ã«ããoffïŒïŒã¡ãœããã¯ãPackageManager.COMPONENT_ENABLED_STATE_DISABLEDãã©ã°ã䜿çšããããã£ã«ã¿ãŒãæ¢ã«ãªãã«ãªã£ãŠããå Žåã察å¿ããã¡ãã»ãŒãžã衚瀺ãããããšãé€ããŠãonïŒïŒã¡ãœãããšå®å šã«äŒŒãŠããŸãã
ãã£ã«ã¿ãŒã®ç¶æ ããã§ãã¯ããã¡ãœããã¯ããã«åçŽã«èŠããŸãã
public boolean enabled() { int enabled = packageManager.getComponentEnabledSetting(componentName); return (enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); }
ã·ã©ãã®ç¢ºèª
Filterã¯ã©ã¹ã«ã¯ããŸã 説æãããŠããªãã¡ãœããããã1ã€æ®ã£ãŠããŸãã ããã¯isSpamïŒïŒã¡ãœããã§ãå®éã«ã¯ã¢ããªã±ãŒã·ã§ã³ã®ã¡ã€ã³ã¿ã¹ã¯ãå®è¡ããŸãã ãã®æ¹æ³ã¯éåžžã«ç°¡åã§ãã 圌ã¯SMSããéä¿¡è ã¡ãã»ãŒãžãæœåºããããŒã¿ããŒã¹ã§åœŒãèŠã€ããããšããŸãã ããå Žåãã¡ãã»ãŒãžã¯ã¹ãã ãšèŠãªãããŸãã
public boolean isSpam(Sms sms, SmsDatabase db) { Sender sender = sms.sender(); return db.senders().exists(sender); }
SMSã¯ã©ã¹
Smsã¯ã©ã¹ã¯ãã§ã«2åèšåãããŠããŸãã 圌ã«ã€ããŠããå°ã話ãå¿ èŠããããŸãã ãã®ã¯ã©ã¹ã¯ãã¢ããªã±ãŒã·ã§ã³å ã®SMSã¡ãã»ãŒãžãè¡šããŸãã 次ã®ãã£ãŒã«ããå«ãŸããŸãã
private String _body; private Sender _sender; private long _timestamp;
_bodyã¯ã¡ãã»ãŒãžã®æ¬æã_senderã¯ã¡ãã»ãŒãžã®éä¿¡è ã_timestampã¯ã¡ãã»ãŒãžãUNIXã¿ã€ã ã¹ã¿ã³ããšããŠåä¿¡ãããæå»ã§ãã
éä¿¡è ã¯ã©ã¹ã¯Androidã®æšæºã§ã¯ãããŸããã ææžãã§äœæãããéä¿¡è ã®é»è©±ãä¿åã§ããŸãããŸããå¿ èŠã«å¿ããŠãé»è©±åž³ããéä¿¡è ã®ååãæœåºã§ããŸãã 詳现ã¯æ€èšããŸããã
Smsã¯ã©ã¹ã«ã¯ãPDUããã¡ãã»ãŒãžæ å ±ãååŸããéçfromPdusïŒïŒã¡ãœãããããããšããã§ã«ããã£ãŠããŸãã ãã®ã³ãŒããèŠãŠã¿ãŸãããïŒ
public static Sms fromPdus(Object[] pdus, Context context) { Sms result = new Sms(); for (int i = 0; i < pdus.length; i++) { SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdus[i]); result._body += sms.getMessageBody(); } SmsMessage first = SmsMessage.createFromPdu((byte[]) pdus[0]); result._sender = new Sender(first.getOriginatingAddress(), context); result._timestamp = first.getTimestampMillis(); return result; }
äžèŠãããšããã®æ¹æ³ã¯è€éã«èŠãããããããŸããã ããããããã¯ããã§ã¯ãããŸããã å¯äžã®é£ç¹ã¯ã1ã€ã®è«çSMSã¡ãã»ãŒãžãè€æ°ã®ç©ççãªSMSã¡ãã»ãŒãžã«åå²ã§ããããšã§ãã ãã®ç¹ã§ãç§ã¯ããªãã®ããã«ã¢ã¡ãªã«ãçºèŠããããšã¯ãªããšæããŸãã ãã®ç¹æ®å¹æã¯ãã§ããã ãå€ãã®æ å ±ã1ã€ã®SMSã«æŒã蟌ãã§ãéãç¯çŽããããã«ãåžžã«ã¹ããŒã¹ãªãã§æžã蟌ã¿ãè¡ããã¹ãŠã®äººã«ããç¥ãããŠããŸãã
ãããã£ãŠããµã€ã¯ã«ã§ã¯ãã¡ãã»ãŒãžæ¬æãæççã«åéããæåã®SMSã¡ãã»ãŒãžããå¿ èŠãªæ å ±ãæœåºããŸãã äžè¬ã«ãSmsã¯ã©ã¹ã䜿çšããŠãããçµäºã§ããŸãã
ããŒã¿ããŒã¹ã«ã€ããŠå°ã
æ ¢ãªã¹ãããŒã®ãã©ãã¯ãªã¹ããšèªèãããŠããªãäœæ¥ã®çµæãããŒã¿ããŒã¹ã«ä¿åãããŸãã ããã¯ããŠãŒã¶ãŒãããã§å¥œããªãã®ãèŠãããšãã§ããããã«ããããã«å¿ èŠã§ãã çè«çã«ã¯ããŠãŒã¶ãŒã¯é£çµ¡å ããé»è©±çªå·ããã©ãã¯ãªã¹ãã«è¿œå ããããšãã§ããææè ãšä»²çŽãããåŸãåä¿¡ããSMSãèªãããšãã§ããŸãã
幞ããªããšã«ãAndroidã«ã¯ããã«äœ¿ããSQLite DBMSããããŸãã æšæºã®JAVAã¯ã©ã¹ãšSQLã¯ãšãªã䜿çšããŠãããŒã¿ããŒã¹ãæäœããããžãã¯å šäœãå®è£ ããŸããã æå°æªã®æ³åã«ããã°ãã¢ããªã±ãŒã·ã§ã³ã®ãã®éšåãçµããåŸãHabréã®AndroidåãORMã«é¢ããèšäºãèªã¿ãŸãã ã
ç§ã¯ãæ¥ç¶ãéã-ããŒã¿ãæäœãã-æ¥ç¶ãéãããšããååã«åºã¥ããŠããŒã¿ããŒã¹ãæäœããŸããã ãã®DBMSã¯ãã¡ã€ã«ã·ã¹ãã ã§ãããèªã¿åããŸãã¯æžã蟌ã¿æäœäžã«ããããã³ã°ãçºçããå¯èœæ§ãããããããã®æ¹æ³ã¯SQLiteã«ç¹ã«é©ããŠããŸãã ãã®ãããé·æéã®æ¥ç¶ãç¶æããªãããã«ããŸãã
ããŒã¿ããŒã¹ã®ãã¹ãŠã®ã©ãããŒã¡ãœãããæ€èšãããã¯ãããŸãããå€ãã®ã¡ãœããããããèšäºã¯ãŽã ã§ã¯ãªãããã§ãã ããã«ããããã¯ãã¹ãŠåãåã§ãããããæ¬è³ªãç解ããããã«ãSMSReceiverã¯ã©ã¹ã®onReceiveã¡ãœããã§äœ¿çšããã¡ãœããã®ã¿ãæ€èšããŸãã
ãšã³ããªãdb.messagesïŒïŒãSaveïŒsmsïŒãã¯ãdbæ¥ç¶ã®äžéšãšããŠããã£ã«ã¿ãŒåŠçãããã¡ãã»ãŒãžãæ ŒçŽããã¡ãã»ãŒãžããŒãã«ã«ç§»åããsaveïŒïŒã¡ãœããã䜿çšããŠæ°ããsmsã¡ãã»ãŒãžãè¿œå ããããšã瀺ããŠããŸãã ãã¹ãŠã®ã¯ã©ã¹ãšã¡ãœããã¯èªå·±èšè¿°åã§ããããšãç¹°ãè¿ããŸãã
public void save(Sms sms) { if (!Preferences.get(_context).storeSms()) return; int maxCount = Preferences.get(_context).storedSmsAmount(); if (count() >= maxCount) trim(maxCount - 1); SQLiteStatement insert = _db.compileStatement( "INSERT INTO Messages(Phone, Timestamp, Body)" + "VALUES (?, ?, ?)"); insert.bindString(1, sms.sender().phone()); insert.bindLong(2, sms.timestamp()); insert.bindString(3, sms.body()); insert.execute(); }
ã³ãŒãã®æåã®è¡ã§ã¯ãã¢ããªã±ãŒã·ã§ã³èšå®ã«ã¢ã¯ã»ã¹ããŠãã©ã°ã確èªããŸããããã¯ããã£ã«ã¿ãŒåŠçãããã¡ãã»ãŒãžãä¿åãããŠãŒã¶ãŒã®èŠæã«å¯Ÿå¿ããŸãã ãŠãŒã¶ãŒãã¹ãã¬ãŒãžãæåŠããå Žåã¯ãçµäºããŸãã
次ã«ãåã³èšå®ããããŠãŒã¶ãŒãèšå®ãããã£ã«ã¿ãŒåŠçãããSMSã¹ãã¬ãŒãžã®ãµã€ãºãæœåºããŸãã ãŸããçŸåšã®ã¡ãã»ãŒãžæ°ããã®ãµã€ãºãè¶ ããå Žåãåä¿¡ããé åºãèæ ®ããŠãå€ãã¡ãã»ãŒãžããªããžããªããåé€ããŸãã ã€ãŸããæåã«åä¿¡ããã¡ãã»ãŒãžãæåã«åé€ãããŸãã ã¯ã©ã·ãã¯ã©ã€ã³ãããã
ãããã®ãžã§ã¹ãã£ã®åŸãMessagesããŒãã«ã«ããŒã¿ãæ¿å ¥ãããªã¯ãšã¹ããäœæããåä»ãbindïŒïŒã¡ãœããã䜿çšããŠãçæããããªã¯ãšã¹ãã«ããŒã¿ããã€ã³ãããŸãã æåŸã«ããªã¯ãšã¹ããå®è¡ããŸãã
ãã¹ããšãããã°
ãã¹ãŠæºåãã§ããŠããããã§ãã å°ããªã¹ããããæ®ã£ãŠããŸãã åé¡ã¯ãã¢ããªã±ãŒã·ã§ã³ãæ£ããæ©èœããŠããããšãã©ã®ããã«ç¢ºèªãããã§ãã åä¿¡è ã¯å°ãªããšãäœããåãåããŸãããããŒã¿ããŒã¹ã¯äœããä¿åããŸããïŒ ããã¯å¥ã®å€§ããªãããã¯ã®ãããã¯ã§ãããããAndroidã®åäœãã¹ãã¢ããªã±ãŒã·ã§ã³ã®æ©èœã«ã€ããŠã¯èª¬æããŸããã ãšãã¥ã¬ãŒã¿ã§SMSã®åä¿¡ãã·ãã¥ã¬ãŒãããæ¹æ³ã®ã¿ã説æããŸãã
ãããè¡ãã«ã¯ãTelnetã¯ã©ã€ã¢ã³ããéããŸãã æ°åã«å¿ããŠãWindows 7ã§PuttyãŸãã¯æšæºã¯ã©ã€ã¢ã³ãã䜿çšããŸãïŒæåã«æå¹ã«ããå¿ èŠããããŸãïŒã localhostã«æ¥ç¶ããããŒããšããŠãšãã¥ã¬ãŒã¿ã®ãŠã£ã³ããŠã¿ã€ãã«ã«è¡šç€ºãããããŒããæå®ããŸãã ååãšããŠãããã¯5554ã§ããèšããŸã§ããªããåæã«ãšãã¥ã¬ãŒã¿ãå®è¡ããå¿ èŠããããŸãã æšæ¶ãèªãã åŸãã³ãã³ãã®å ¥åãéå§ã§ããŸãã
å€ãã®ããŒã ããããŸãã ãããã®ãªã¹ãã¯ãhelpã³ãã³ããå ¥åããŠååŸã§ããŸãã ãããã®ã³ãã³ãã䜿çšããŠãé»è©±æ©ã§çºçããå¯èœæ§ã®ããå€ãã®ã€ãã³ããã·ãã¥ã¬ãŒãã§ããŸãã ãã ããSMSã¡ãã»ãŒãžã®åä¿¡ã®ã·ãã¥ã¬ãŒã·ã§ã³ã«ã®ã¿é¢å¿ããããŸãã
ãããã·ãã¥ã¬ãŒãããã«ã¯ãåã«ã³ãã³ããå ¥åããŸã
sms send _ _
ããã§ãphone_numberã¯ã+ãèšå·ã§å§ãŸãå¯èœæ§ã®ããæ°åã®ã·ãŒã±ã³ã¹ã§ãããmessage_textã¯ãéåžžSMSã§èšè¿°ããã¹ããŒã¹ããã®ä»ã®æåãå«ãã¡ãã»ãŒãžã³ã³ãã³ãã§ãã
ã·ãã¥ã¬ãŒã·ã§ã³ãæåããå Žåãtelnetã¯ã©ã€ã¢ã³ã端æ«ã«ãOKããšããã¡ãã»ãŒãžã衚瀺ãããŸãã
ãããã«
ãã®ãããã¯ã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã®äž»ãªæè¡ç詳现ãæããã«ããèœãšãç©ŽãšAndroidãã©ãããã©ãŒã ã®ããã€ãã®æ©èœã«æ³šæãæããŸããã ã¢ããªã±ãŒã·ã§ã³ã®ææ°ããŒãžã§ã³ã¯ãGoogle Playããç¡æã§ããŠã³ããŒãã§ããŸãã
ã質åããææ¡ããããŸããããã³ã¡ã³ãããã©ã€ããŒãã¡ãã»ãŒãžã§ãã®ããšã«ã€ããŠãé£çµ¡ããã ããã°å¹žãã§ãã 建èšçãªæ¹å€ã¯å€§æè¿ã§ãã ãæž èŽããããšãããããŸããïŒ
PSïŒã¹ã¯ãªãŒã³ã·ã§ãããæ¿å ¥ããªãããšããizeã³ããŸãã ãã®ãããå€ãã®è³æãèŠã€ãããŸãããã説æãããŠãããã®ã®ã©ããã°ã©ãã£ãã¯ã®èª¬æãå¿ èŠãšããã®ãããããŸããã ããªããç§ã«åæããªãå Žåãç§ã¯ééããªããããã¯ãä¿®æ£ããŸãã