实时手机跟踪Word格式.docx
- 文档编号:21544459
- 上传时间:2023-01-31
- 格式:DOCX
- 页数:36
- 大小:2.48MB
实时手机跟踪Word格式.docx
《实时手机跟踪Word格式.docx》由会员分享,可在线阅读,更多相关《实时手机跟踪Word格式.docx(36页珍藏版)》请在冰豆网上搜索。
@Override
publicvoidonCreate(){
lm=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
if(lm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER))
{
Toast.makeText(this,"
GPS模块正常"
Toast.LENGTH_LONG).show();
}else{
请开启GPS!
"
}
super.onCreate();
}
publicintonStartCommand(Intentintent,intflags,intstartId){
Locationlocation=null;
//查找到服务信息
Criteriacriteria=newCriteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
//高精度
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
//低功耗
Stringprovider=lm.getBestProvider(criteria,true);
//获取GPS信息
location=lm.getLastKnownLocation(provider);
//通过GPS获取位置
lm.requestLocationUpdates(provider,2000,10,listener);
returnsuper.onStartCommand(intent,flags,startId);
LocationListenerlistener=newLocationListener(){
@Override
publicvoidonStatusChanged(Stringprovider,intstatus,Bundleextras){
Toast.makeText(GPSService.this,"
StatusChanged"
publicvoidonProviderEnabled(Stringprovider){
ProviderEnabled"
publicvoidonProviderDisabled(Stringprovider){
ProviderDisabled"
publicvoidonLocationChanged(Locationlocation){
doublex=0.0;
doubley=0.0;
if(location!
=null){
x=location.getLatitude();
y=location.getLongitude();
sendData(x+"
|"
+y);
}
经度:
+x+"
纬度:
+y,Toast.LENGTH_LONG).show();
};
publicvoidsendData(Stringdata)
{
//邮件发送
MultiMailSender.MultiMailSenderInfomailInfo=newMultiMailSender.MultiMailSenderInfo();
mailInfo.setMailServerHost("
);
mailInfo.setMailServerPort("
25"
mailInfo.setValidate(true);
mailInfo.setUserName("
403082461@"
mailInfo.setPassword("
***********"
//您的邮箱密码
mailInfo.setFromAddress("
mailInfo.setToAddress("
1027266214@"
mailInfo.setSubject("
GPS"
+data);
mailInfo.setContent(data);
String[]receivers=newString[]{"
};
String[]ccs=receivers;
mailInfo.setReceivers(receivers);
mailInfo.setCcs(ccs);
//这个类主要来发送邮件
MultiMailSendersms=newMultiMailSender();
sms.sendTextMail(mailInfo);
//发送拍照邮件
publicvoidonDestroy(){
lm.removeUpdates(listener);
//listener即为监听器实例
super.onDestroy();
publicIBinderonBind(Intentintent){
returnnull;
}
2.MailSenderInfo类:
/**
*发送邮件需要使用的基本信息
*/
importjava.util.Properties;
publicclassMailSenderInfo{
//发送邮件的服务器的IP和端口
privateStringmailServerHost;
privateStringmailServerPort="
;
//邮件发送者的地址
privateStringfromAddress;
//邮件接收者的地址
privateStringtoAddress;
//登陆邮件发送服务器的用户名和密码
privateStringuserName;
privateStringpassword;
//是否需要身份验证
privatebooleanvalidate=false;
//邮件主题
privateStringsubject;
//邮件的文本内容
privateStringcontent;
//邮件附件的文件名
privateString[]attachFileNames;
/**
*获得邮件会话属性
*/
publicPropertiesgetProperties(){
Propertiesp=newProperties();
p.put("
mail.smtp.host"
this.mailServerHost);
mail.smtp.port"
this.mailServerPort);
mail.smtp.auth"
validate?
"
true"
:
false"
returnp;
}
publicStringgetMailServerHost(){
returnmailServerHost;
publicvoidsetMailServerHost(StringmailServerHost){
this.mailServerHost=mailServerHost;
publicStringgetMailServerPort(){
returnmailServerPort;
publicvoidsetMailServerPort(StringmailServerPort){
this.mailServerPort=mailServerPort;
publicbooleanisValidate(){
returnvalidate;
publicvoidsetValidate(booleanvalidate){
this.validate=validate;
publicString[]getAttachFileNames(){
returnattachFileNames;
publicvoidsetAttachFileNames(String[]fileNames){
this.attachFileNames=fileNames;
publicStringgetFromAddress(){
returnfromAddress;
publicvoidsetFromAddress(StringfromAddress){
this.fromAddress=fromAddress;
publicStringgetPassword(){
returnpassword;
publicvoidsetPassword(Stringpassword){
this.password=password;
publicStringgetToAddress(){
returntoAddress;
publicvoidsetToAddress(StringtoAddress){
this.toAddress=toAddress;
publicStringgetUserName(){
returnuserName;
publicvoidsetUserName(StringuserName){
this.userName=userName;
publicStringgetSubject(){
returnsubject;
publicvoidsetSubject(Stringsubject){
this.subject=subject;
publicStringgetContent(){
returncontent;
publicvoidsetContent(StringtextContent){
this.content=textContent;
4.MultiMailSender类:
importjava.util.Date;
importjavax.activation.CommandMap;
importjavax.activation.DataHandler;
importjavax.activation.FileDataSource;
importjavax.activation.MailcapCommandMap;
importjavax.mail.Address;
importjavax.mail.Authenticator;
importjavax.mail.BodyPart;
importjavax.mail.Message;
importjavax.mail.MessagingException;
importjavax.mail.Multipart;
importjavax.mail.PasswordAuthentication;
importjavax.mail.Session;
importjavax.mail.Transport;
importjavax.mail.internet.InternetAddress;
importjavax.mail.internet.MimeBodyPart;
importjavax.mail.internet.MimeMessage;
importjavax.mail.internet.MimeMultipart;
importjavax.mail.internet.MimeUtility;
importandroid.util.Log;
*发送邮件给多个接收者、抄送邮件
*/
publicclassMultiMailSender{
*以文本格式发送邮件
*@parammailInfo待发送的邮件的信息
publicbooleansendTextMail(MultiMailSenderInfomailInfo){
//判断是否需要身份认证
MultiMailSender.MyAuthenticatorauthenticator=null;
Propertiespro=mailInfo.getProperties();
if(mailInfo.isValidate()){
//如果需要身份认证,则创建一个密码验证器
authenticator=newMyAuthenticator(mailInfo.getUserName(),mailInfo.getPassword());
//根据邮件会话属性和密码验证器构造一个发送邮件的session
SessionsendMailSession=Session.getDefaultInstance(pro,authenticator);
try{
//根据session创建一个邮件消息
MimeMessagemailMessage=newMimeMessage(sendMailSession);
//创建邮件发送者地址
Addressfrom=newInternetAddress(mailInfo.getFromAddress());
//设置邮件消息的发送者
mailMessage.setFrom(from);
//创建邮件的接收者地址,并设置到邮件消息中
Address[]tos=null;
String[]receivers=mailInfo.getReceivers();
if(receivers!
=null){
//为每个邮件接收者创建一个地址
tos=newInternetAddress[receivers.length+1];
tos[0]=newInternetAddress(mailInfo.getToAddress());
for(inti=0;
i<
receivers.length;
i++){
tos[i+1]=newInternetAddress(receivers[i]);
}else{
tos=newInternetAddress[1];
//Message.RecipientType.TO属性表示接收者的类型为TO
mailMessage.setRecipients(Message.RecipientType.TO,tos);
//设置邮件消息的主题
mailMessage.setSubject(mailInfo.getSubject());
//设置邮件消息发送的时间
mailMessage.setSentDate(newDate());
//设置邮件消息的主要内容
MailcapCommandMapmc=(MailcapCommandMap)CommandMap.getDefaultCommandMap();
mc.addMailcap("
text/html;
x-java-content-handler=com.sun.mail.handlers.text_html"
text/xml;
x-java-content-handler=com.sun.mail.handlers.text_xml"
text/plain;
x-java-content-handler=com.sun.mail.handlers.text_plain"
multipart/*;
x-java-content-handler=com.sun.mail.handlers.multipart_mixed"
message/rfc822;
x-java-content-handler=com.sun.mail.handlers.message_rfc822"
CommandMap.setDefaultCommandMap(mc);
MimeMultipartallMultipart=newMimeMultipart("
mixed"
//附件
//设置content里的内容
MimeBodyPartcontentMbp=newMimeBodyPart();
contentMbp.setContent(mailInfo.getContent(),"
charset=GB2312"
allMultipart.addBodyPart(contentMbp);
//添加附件
mailMessage.setContent(allMultipart);
mailMessage.saveChanges();
Transport.send(mailMessage);
//开始发送
returntrue;
}catch(Exceptione)
{
e.printStackTrace();
returnfalse;
publicbooleansendAttachMail(MultiMailSenderInfomailInfo){
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实时 手机 跟踪
![提示](https://static.bdocx.com/images/bang_tan.gif)