Play Alarm Music
1. Put the music file in the Res/raw file
2. Create a MediaPlayer object
MediaPlayer player = mediaplayer.create (context,r.raw.*);
3. Set the highest sound:
Player.setvolume (1.0f,1.0f);
4. Set the sound for loop playback:
Player.setlooping (TRUE);
Code:
//报警音乐 MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.alarm); //音量调成最高 mediaPlayer.setVolume(1.0f,1.0f); //循环播放 mediaPlayer.setLooping(true); //开始播放 mediaPlayer.start();
GPS Positioning
1. Positioning method:
Positioning GPS positioning based on network positioning base station
(1) network location WiFi 2g 3g
Get an IP address to determine its approximate location based on the IP address
It's a big error.
(2) Base station positioning
The accuracy of the positioning depends on the number of base stations
(3) GPS positioning
by satellite positioning.
Suitable for use in open spaces
A-gps
Shorten positioning time, reduce power consumption, improve positioning sensitivity
High accuracy of about 15m
The code implementation of the positioning function:
1. Create a class: Gpsservice, inherit from service
2. Registering in the manifest list
3. Operations to get positions in the OnCreate () method
-
Create location service
Locationmanager manager = Getsystemservice (location_service);
-
Get the best location provider
-
Set conditions
Criteria = new criteria ();
Criteria.setaccuracy (criteria.accuracy_fine);
-
Get the best location provider
String Provider = Criteria.getbestprovider (criteria,true);
-
Listening position change
Manager.requestlocationupdates ()
• First parameter: Positioning mode ("GPs")
• Second parameter: How often is 60000 (1 minutes) Updated
· Third parameter: How many meters update the
• Fourth parameter: interface, listening position
New locationlistener{
//callback at position change
onlocationchanged ()
{
String Jingdu = "" +location.getlongitude ();
String Weidu = "" +location.getlatitude ();
//Precision
String accuracy = "" +location.getaccuracy ();
}
//callback from on to off when the status changes
Onstatuschanged ()
{
}
//One location provider available
Onproviderenabled ()
//A location provider is not available
onproviderdisabled ()
}
Cancel listener:
OnDestroy () in:
Lm.removeupdates ( Listener);
listener = null;
Permissions: Access_fine_location High precision position
Access_coarse_location Rough Position
Access_mock_location Simulator Location
Mars coordinate system (National security plugin)
Due to the security strategy, GPS positioning results in China will have a certain amount of offset (irregular bias)
Mars Coordinate conversion code: (online Yes, can reduce the offset, improve accuracy)
1.modifyoffset.getinstance (. Class.getresouceadstream (. dat));
2.PointDouble newdouble1 = offset.s2c (new pointdouble (longitude, latitude))
3.longtitude = offset. X
4.latitude = offset. Y
The final code implementation:
Gpsservice.class
Public class gpsservice extends Service{ PrivateSharedpreferences sp;PrivateSharedpreferences.editor Editor;PrivateLocationmanager Manager;PrivateMylocalchangedlistener Listener; Public Gpsservice() { } PublicIBinderOnbind(Intent Intent) {return NewBinder (); } Public void onCreate() {Super. OnCreate (); SP = Getsharedpreferences ("config", mode_private); Editor = Sp.edit (); Listener =NewMylocalchangedlistener ();//Create Location ServicesManager = (Locationmanager) getsystemservice (Location_service);//Set conditionsCriteria =NewCriteria (); Criteria.setaccuracy (Criteria.accuracy_fine);//Get the best location providerString providers = Manager.getbestprovider (criteria,true);//Monitor location changesManager.requestlocationupdates (providers,60000, -, listener); } Public void OnDestroy() {Super. OnDestroy (); Manager.removeupdates (listener); Listener =NULL; } Public class Mylocalchangedlistener implements Locationlistener { callback when//position changed Public void onlocationchanged(Location location) {//1. Obtaining latitude and longitude and accuracy DoubleLongitude = Location.getlongitude ();DoubleLatitude = Location.getlatitude ();//2. Convert normal coordinates to Mars coordinatesInputStream is = GPSService.class.getResourceAsStream ("Axisoffset.dat");Try{Modifyoffset Modify = Modifyoffset.getinstance (IS); Pointdouble pointdouble = modify.s2c (NewPointdouble (Longitude,latitude)); String longitudetrue = pointdouble.x+""; String latitudetrue = pointdouble.y+"";//Save latitude and longitudeEditor.putstring ("Location","Longitude:"+longitudetrue+"\ n Latitude: Latitude"); Editor.commit (); }Catch(Exception e) {E.printstacktrace (); } }//callback when status is changed Public void onstatuschanged(String provider,intStatus, Bundle extras) {}//Location provider available callback Public void onproviderenabled(String Provider) { }//Callback when the location provider is unavailable Public void onproviderdisabled(String Provider) { } }}
In the Smsreceiver
//Get positioningStringNumber = Sp.getstring ("Safenumber",NULL); Intent intent1 =NewIntent (context, gpsservice.class); Context.startservice (INTENT1);StringLocation = Sp.getstring ("Location",NULL);//Send SMSif(Textutils.isempty (location)) {Smsmanager.getdefault (). Sendtextmessage (number,NULL,"location is getting in, please later ..." ",NULL,NULL);}Else{Smsmanager.getdefault (). Sendtextmessage (number,NULL, Location,NULL,NULL);}
Baidu positioning and Google officials seem to have provided a positioning framework, after the project to learn a bit ~ ~ ~
Copyright notice: Just out of the original content of the pot, I hope you have help ~
Mobile Security defender------mobile phone anti-theft page play alarm music &GPS positioning