A new text message is sent to your mobile phone. You can use your computer to remind me of the new text message.

Source: Internet
Author: User

A new text message is sent to your mobile phone. You can use your computer to remind me of the new text message.

Generally, I spend less time using my mobile phone, more time using my computer, and more lightweight users of my mobile phone. My computer is very heavy. I usually use my computer after I go to work or go home from work, therefore, there are often situations where the mobile phone is not at hand or is being charged. It is seldom noticed that the mobile phone is being hashed in or sent to a text message, it may have been a long time before you go to use your mobile phone. I think it would be nice to tell me via computer if a text message is sent on your mobile phone, so I want a new text message on my mobile phone and remind me of this function on my computer.

Check whether such software is available and find that there are a few of them that can meet this requirement, but there are a lot of functions, one of which is a function in the software.

Finally, I decided to write a function by myself. One reason is that I still like the function to be simpler, and the other is that reading text messages is dangerous, if you don't trust other people's software, you can trust it. At least you know what it is.

After the final function is implemented, there is a new text message on the mobile phone. Just pop a window in my notebook and let me know.

After thinking about how to implement the process, there should be a program on the mobile phone. To realize the function of receiving the text message and sending the text message content and the sender to my computer, after receiving the text message, A window pops up in the lower right corner. That's all.

The premise is that the mobile phone network and the computer network are in the same network.

General Flowchart


 

One step at a time, the pop-up window function is very good, it is a Winform program, the above two labels, a title and a content, already available, can be used directly, when you start the service, pass two parameters in the past to display the content you sent.

There are also many implementation methods for sending messages to the computer by the mobile phone. You can use TCP or UDP to write a program to listen to the port on the computer, and then the mobile APP will send messages directly to it.

However, I have a lot of work to write on my own, and I still like to use it. The current system usually comes with an IIS server, and it also starts automatically at startup, for myself, there is almost no need to worry about it. In this way, you can directly create a site on IIS and write a dynamic page. When there is a request, you can open the pop-up window program. The mobile APP can directly POST data to this page, when the pop-up window program is opened again on the page, I feel very OK.

Then there is a problem with the APP on the mobile phone end. How does the APP receive text messages and POST data to the computer.

The android system has a text message broadcast function. When a new text message comes, a broadcast is sent. You can write a text message broadcast receiver by yourself, when there is a new text message, the system will call your broadcast receiver, and then you will be able to get the text message content. Then you can use the http function to send the content to your computer, the general process is as follows.


Follow this line of thinking and step on a lot of pitfalls. Next we will introduce some key code

1. Create an android Project

Set related Permissions

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Create an SMS broadcast Receiver

 <receiver android:name=".Smsrecever">
            <intent-filter android:priority="1000">
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

Get text message content and send it to computer

public class Smsrecever extends BroadcastReceiver {

    @Override
    public void onReceive (Context context, Intent intent) {
        final String url = DataHelper.GetUrl (context);
        if ("" .equals (url)) {
            return;
        }
        Bundle bundle = intent.getExtras ();
        Object [] objects = (Object []) bundle.get ("pdus");
        for (Object obj: objects) {
            SmsMessage smsMessage = SmsMessage.createFromPdu ((byte []) obj);
            // Get the content of the text message
            final String body = smsMessage.getDisplayMessageBody ();
            // Get the sender of the SMS
            final String address = smsMessage.getDisplayOriginatingAddress ();
            // Get SMS time
            long date = smsMessage.getTimestampMillis ();
            SimpleDateFormat format = new SimpleDateFormat ("yyyy-MM-dd hh: mm: ss");
            format.setTimeZone (TimeZone.getTimeZone ("GMT + 8"));
            final String dateStr = format.format (date);
            new Thread (new Runnable () {
                @Override
                public void run () {
                    common.SendMsg (url, address, body + "[" + dateStr + "]");
                }
            }). start ();
        }
    }
}

2. Establish a WEB site to receive text messages

Add An aspx page

public partial class showmsg: System.Web.UI.Page
     {
         protected void Page_Load (object sender, EventArgs e)
         {
             // Accept title and content parameters
             string mm = HttpUtility.UrlEncode (Request ["t"]) + "" + HttpUtility.UrlEncode (Request ["b"]);
             // Open the exe program
             _ProcessUtil.CreateProcessAsUser (@ "E: \ codeProjects \ Projects \ showmsg \ msg \ bin \ Debug \ msg.exe", mm, _ProcessUtil._SESSION_TYPE.SessionFromActiveConsoleSessionId);
             Response.Write ("1");
         }
     } 

Microsoft implemented a session isolation mechanism in the vista system. IIS is a background service and belongsSession 0,Different sessions cannot send messages through the window. Therefore, if you use System. Diagnostics. Process. Start in C # To directly call EXE, you cannot see the interface.

After checking the solution, you can call the system API method CreateProcessAsUser to create a process.

After the final improvement, the effect APP interface is as follows:


 

 

Pop-up window Program



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.