0% found this document useful (0 votes)
36 views6 pages

Finding Errors

This Java code defines a service class called MyService that extends the Android Service class. The service gets the device's location using LocationManager and compares it to a preset boundary. If the boundary is crossed, an SMS message is sent to a phone number. The service handles sending and receiving SMS broadcasts, playing an alarm sound, and scheduling periodic location updates every 6 seconds.

Uploaded by

vinoth1128
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views6 pages

Finding Errors

This Java code defines a service class called MyService that extends the Android Service class. The service gets the device's location using LocationManager and compares it to a preset boundary. If the boundary is crossed, an SMS message is sent to a phone number. The service handles sending and receiving SMS broadcasts, playing an alarm sound, and scheduling periodic location updates every 6 seconds.

Uploaded by

vinoth1128
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

package com.map.alarm; //sending msg prgm// import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import android.app.Activity; import android.app.

endingIntent; import android.app.!ervice; import android.content."roadcast#eceiver; import android.content.$ontext; import android.content.Intent; import android.content.IntentFilter; import android.location.Location; import android.location.LocationListener; import android.location.Location%anager; import android.media.Audio%anager; import android.media.%edia layer; import android.media.#ingtone%anager; import android.net.&ri; import android.os."undle; import android.os.'andler; import android.os.I"inder; import android.os.!trict%ode; import android.telep(ony.!ms%anager; import android.util.Log; import android.)idget.*oast; pu+lic class %y!ervice extends !ervice implements LocationListener , private -inal 'andler (andler . ne) 'andler/0; Intent intent; int counter . 12 alarmcount . 1;; !ession%anager s%anager; // -lag -or 3 ! status +oolean is3 !Ena+led . -alse; // -lag -or net)ork status +oolean is4et)orkEna+led . -alse; // -lag -or 3 ! status +oolean can3etLocation . -alse; Location location; // location dou+le latitude2 complatitude2longitude2 complongitude; // latitude // *(e minimum distance to c(ange &pdates in meters private static -inal long %I45DI!*A4$E5$'A43E5FO#5& DA*E! . 61; // 61 meters // *(e minimum time +et)een updates in milliseconds private static -inal long %I45*I%E5"75& DA*E! . 6111 8 91 8 6; // 6 minute // Declaring a Location %anager protected Location%anager location%anager; :Override pu+lic int on!tart$ommand/Intent intent2 int -lags2 int startId0 , // *ODO Auto;generated met(od stu+ i- /android.os."uild.<E#!IO4.!D=5I4* > ?0 , !trict%ode.*(read olicy policy .ne) !trict%ode.*(read olicy."uilder/0.permitAll/0.+uild/0; !trict%ode.set*(read olicy/policy0; @ int i . 1;

sec

)(ile /i A 6160 , i- /i > 6110 , t(is.onDestroy/0; @ else , counter . i; iBB; (andler.remove$all+acks/send&pdates*o&I0; (andler.postDelayed/send&pdates*o&I2 6 8 61110; // 6 @ @ return super.on!tart$ommand/intent2 -lags2 startId0;

@ :Override pu+lic void on$reate/0 , // *ODO Auto;generated met(od stu+ super.on$reate/0; s%anager . ne) !ession%anager/App.context0; // intent . ne) Intent/"#OAD$A!*5A$*IO40; @ :Override pu+lic void onDestroy/0 , // *ODO Auto;generated met(od stu+ super.onDestroy/0; i- /send&pdates*o&I C. null0 , (andler.remove$all+acks/send&pdates*o&I0; @ @ :Override pu+lic I"inder on"ind/Intent intent0 , // *ODO Auto;generated met(od stu+ return null; @ private #unna+le send&pdates*o&I . ne) #unna+le/0 , pu+lic void run/0 , getLocation/0; compLocation/0; (andler.postDelayed/t(is2 6 8 61110; // 6 sec @ @;

0;

pu+lic Location getLocation/0 , try , location%anager . /Location%anager0 App.context .get!ystem!ervice/LO$A*IO45!E#<I$E0; // getting 3 ! status is3 !Ena+led . location%anager .is roviderEna+led/Location%anager.3 !5 #O<IDE# // getting net)ork status is4et)orkEna+led . location%anager .is roviderEna+led/Location%anager.4E*7O#=5 #O<IDE#0; i- /Cis3 !Ena+led DD Cis4et)orkEna+led0 , // no net)ork provider is ena+led @ else ,

t(is0;

t(is.can3etLocation . true; // First get location -rom 4et)ork rovider i- /is4et)orkEna+led0 , location%anager.reEuestLocation&pdates/ Location%anager.4E*7O#=5 #O<IDE#2 %I45*I%E5"75& DA*E!2 %I45DI!*A4$E5$'A43E5FO#5& DA*E!2 i- /location%anager C. null0 , location . location%anager .getLast=no)nLocation/Locatio i- /location C. null0 , latitude . location.getLatitude/0; longitude . location.getLongitude/0; @

n%anager.4E*7O#=5 #O<IDE#0;

@ @ // i- 3 ! Ena+led get lat/long using 3 ! !ervices i- /is3 !Ena+led0 , i- /location .. null0 , location%anager.reEuestLocation&pdates/ Location%anager.3 !5 #O<IDE#2 %I45*I%E5"75& DA*E!2

%I45DI!*A4$E5$'A43E5FO#5& DA*E!2 t(is0; i- /location%anager C. null0 , location . location%anager .getLast=no)nLocation/L ocation%anager.3 !5 #O<IDE#0; i- /location C. null0 , latitude .location.getLatitude/0; longitude . location.getLongitude/0; @ @ @ @ @ @ catc( /Exception e0 , e.print!tack*race/0; @ return location; @ dou+le round*)oDecimals/dou+le d0 , DecimalFormat t)oDecimals . ne) DecimalFormat/FG.GGGGGGF0; return Dou+le.valueO-/t)oDecimals.-ormat/d00; @ pu+lic void compLocation/0 , complatitude . round*)oDecimals/s%anager.getDou+le/FsetLatF2 100; complongitude . round*)oDecimals/s%anager.getDou+le/FsetLongF2 100; dou+le roundlong.round*)oDecimals/longitude0; dou+le roundlat.round*)oDecimals/latitude0; i- /complatitude .. roundlat HH complongitude .. roundlong0 , try ,

+eepalram/0; send!%!/FIJKI69JLK?F2 Fyour reac(ed dangerous +orderC please dont go -urt(erF0; @ catc( /Illegal!tateException e0 , // *ODO Auto;generated catc( +lock e.print!tack*race/0; @ catc( /IOException e0 , // *ODO Auto;generated catc( +lock e.print!tack*race/0; @@@ :Override pu+lic void onLocation$(anged/Location location0 , // *ODO Auto;generated met(od stu+@ :Override pu+lic void on roviderDisa+led/!tring provider0 , // *ODO Auto;generated met(od stu+@ :Override pu+lic void on roviderEna+led/!tring provider0 , // *ODO Auto;generated met(od stu+@ :Override pu+lic void on!tatus$(anged/!tring provider2 int status2 "undle extras0

// *ODO Auto;generated met(od stu+@ /8 !ending !%! met(od 8/ private void send!%!/!tring p(one4um+er2 !tring message0 , !ms%anager sms%anager . !ms%anager.getDe-ault/0; !tring !E4* . F!%!5!E4*F; !tring DELI<E#ED . F!%!5DELI<E#EDF; !ms%anager sms . !ms%anager.getDe-ault/0; ArrayListA!tring> parts . sms.divide%essage/message0; int message$ount . parts.siMe/0; Log.i/F%essage $ountF2 F%essage $ountN F B message$ount0;O ArrayListA endingIntent> deliveryIntents . ne) ArrayListA endingIntent>/0; ArrayListA endingIntent> sentIntents . ne) ArrayListA endingIntent>/0; endingIntent sent I . endingIntent.get"roadcast/t(is2 12 ne) Intent/ !E4*02 10; endingIntent delivered I . endingIntent.get"roadcast/t(is2 12 ne) Intent/DELI<E#ED02 10; -or /int j . 1; j A message$ount; jBB0 , sentIntents.add/sent I0; deliveryIntents.add/delivered I0; @ // ;;;)(en t(e !%! (as +een sent;;; register#eceiver/ne) "roadcast#eceiver/0 , :Override pu+lic void on#eceive/$ontext arg12 Intent arg60 , s)itc( /get#esult$ode/00 , case Activity.#E!&L*5O=N *oast.make*ext/get"ase$ontext/02 F!%! sentF2 *oast.LE43*'5!'O#*0.s(o)/0; +reak;

-ailureF2

case !ms%anager.#E!&L*5E##O#53E4E#I$5FAIL&#EN *oast.make*ext/get"ase$ontext/02 F3eneric *oast.LE43*'5!'O#*0.s(o)/0; +reak; case !ms%anager.#E!&L*5E##O#54O5!E#<I$EN *oast.make*ext/get"ase$ontext/02 F4o serviceF2 *oast.LE43*'5!'O#*0.s(o)/0; +reak; case !ms%anager.#E!&L*5E##O#54&LL5 D&N *oast.make*ext/get"ase$ontext/02 F4ull D&F2 *oast.LE43*'5!'O#*0.s(o)/0; +reak; case !ms%anager.#E!&L*5E##O#5#ADIO5OFFN *oast.make*ext/get"ase$ontext/02 F#adio o--F2 *oast.LE43*'5!'O#*0.s(o)/0; +reak; @

deliveredF2

@ @2 ne) IntentFilter/!E4*00; // ;;;)(en t(e !%! (as +een delivered;;; register#eceiver/ne) "roadcast#eceiver/0 , :Override pu+lic void on#eceive/$ontext arg12 Intent arg60 , s)itc( /get#esult$ode/00 , case Activity.#E!&L*5O=N *oast.make*ext/get"ase$ontext/02 F!%!

deliveredF2

*oast.LE43*'5!'O#*0.s(o)/0; +reak; case Activity.#E!&L*5$A4$ELEDN *oast.make*ext/get"ase$ontext/02 F!%! not +reak; *oast.LE43*'5!'O#*0.s(o)/0;

@ @ @2 ne) IntentFilter/DELI<E#ED00; sms%anager.send*ext%essage/p(one4um+er2 null2 message2 null2 null0; @ private void +eepalram/0 t(ro)s Illegal!tateException2 IOException , &ri sound&ri . #ingtone%anager .getDe-ault&ri/#ingtone%anager.*P E54O*IFI$A*IO40; %edia layer m%edia layer . ne) %edia layer/0; m%edia layer.setData!ource/t(is2 sound&ri0; -inal Audio%anager audio%anager . /Audio%anager0 t(is .get!ystem!ervice/$ontext.A&DIO5!E#<I$E0; i- /audio%anager.get!tream<olume/Audio%anager.!*#EA%5ALA#%0 C. 10 , m%edia layer.setAudio!tream*ype/Audio%anager.!*#EA%5ALA#%0; m%edia layer.setLooping/true0; m%edia layer.prepare/0; m%edia layer.start/0; @@@

You might also like