PhoneFinder--寻找丢失的手机

时间:2022-05-03
本文章向大家介绍PhoneFinder--寻找丢失的手机,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

    手机丢了怎么办?那就打电话给手机,如果运气好的话,捡到的好心人能够把手机还给你。如果手机是被偷的,那就没有办法了,即使手机开着,估计小偷也不会接电话。当然,我们继续下面讨论的前提就是:手机是掉了,而且被好心人捡到,但是他不知道怎么还;或者是手机处在silent状态,你打电话人家听不到。Googlepage上有这么一个类似的应用,也叫PhoneFinder,不过这个软件是要收钱的。在windows mobile 6 SDK自带的例子中,有一个PhoneFinder的应用,通过它,你可以在手机上设置一定的信息,如果你通过SMS,发送这个信息到手机上,手机就会弹出提示框,显示主人的信息,同时播放一段声音,以引起注意。

    开发这样的应用程序,我们首先需要了解一下几方面的内容:

1. State and Notifications Broker API

2. Pocket Outlook Object Model Application Development for Windows Mobile-based Devices

3. MessageInterceptor

    在应用程序的主界面上,我们可以让用户输入信息内容,并且设置应用是否允许。这样,在设备接收到含有预先设定的短信之后,就会做出相应的动作,如弹出提示框,播放声音等等。其中,开启短信拦截的关键代码段如下:

Code
 interceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete);
 
 interceptor.MessageCondition = new MessageCondition();
 
 interceptor.MessageCondition.CaseSensitive = true;
 
 interceptor.MessageCondition.ComparisonType = MessagePropertyComparisonType.Equal;
 
 interceptor.MessageCondition.ComparisonValue = pin.Text;
 
 interceptor.MessageCondition.Property = MessageProperty.Body;
 
 interceptor.EnableApplicationLauncher(ruleName);
 

播放声音使用PlaySound方法,通过PInvoke得到:

Code
PlaySound#region PlaySound
[System.Runtime.InteropServices.DllImport("coredll.dll")]
static extern int PlaySound(string pszSound, IntPtr hMod, int fdwSound);
const int SND_FILENAME = 0x20000;
const int SND_SYNC = 0x0;
const int SND_ASYNC = 0x1;
const int SND_LOOP = 0x8;
#endregion
 

主人信息通过SystemState获得:

Code
 string owner = SystemState.OwnerName;
 
 string email = SystemState.OwnerEmail;
 
 string phone = SystemState.OwnerPhoneNumber;
 

测试这个应用程序我们可以使用Device Emulator和Cellular Emulator。首先,打开设备模拟器和蜂窝模拟器,并将它们建立联系,具体步骤参考《Ring Tone Manager on Windows Mobile》。然后将程序部署到设备进行调试。调试时,应用程序的主界面如下图1所示:

图1:应用程序主界面

    在Pin的text中设置好相应的文字以后,点击“Enabled”,启动短信拦截,然后点击左下方的Exit退出界面。这时候,我们在蜂窝模拟器里面给设备模拟器发送字符串“1234”,如下图2所示:

图2:蜂窝模拟器中的SMS发送界面

    这时候,我们就可以在设备模拟器中看到相应的消息框,并听到声音了。如下图3所示:

图3:设备模拟器中看到的提示消息框

参考链接:

Google:PhoneFinder

MSDN:

1. State and Notifications Broker API

2. Pocket Outlook Object Model Application Development for Windows Mobile-based Devices

3. MessageInterceptor