New text message on mobile phone, remind me via computer

Posted by beginneratphp on Fri, 07 Jun 2019 19:32:35 +0200

Generally, I use the mobile phone for less time, more time with the computer, mobile phone light users, the computer is heavy, after work or home, the computer is basically in use, so often there will be mobile phone not at hand or charging situation, listening to the song is hi mobile phone calls or text messages will rarely be detected, when the phone is still good to say, text messages will vibrateOnce, it may have been a long time before you go to use your mobile phone. I think if there is a text message coming from your mobile phone and you can tell me directly via the computer if not, then you won't miss it, so I want to remind me of this function on my computer when there is a new text message on my mobile phone.

Next, check if there is any such software, and find that there are so few that can fulfill this requirement, but there are a few functions, one of which is inside the software.

Finally, I decided to write a function by myself. One reason is that I still like the simple function. The second is that it is more dangerous to read text messages. If you don't feel confident about other people's software, you can write by yourself. At least what you know is inside.

The last thing that happens is that there's a new text message on your phone, just pop up a window in my notebook and tell me it's OK.

Think about the process you want to achieve should be a program on your mobile phone, to achieve the function of receiving text messages and to send the text message content and sender to my computer after receiving the text messages. When the computer receives the text messages, pop up a window in the lower right corner.That's all.

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

Rough Flowchart

 

Step by step, the pop-up window function is very good, that is, a Winform program, two labels above, a title and a content, which has been used before, can be used directly, when you start, two parameters will show your content in the past.

Then how the mobile phone sends messages to the computer, there are many ways to achieve this. With TCP or UDP, write a program to monitor the port on the computer, and the mobile APP will send directly there.

However, I have a lot of work to write, I still like to use it. Now the system usually has its own IIS server, and it also starts automatically, which is hardly a special state for myself.In this way, you can directly set up a site on IIS, write a dynamic page, open the pop-up program when you have the request, mobile APP can directly POST the data to this page, and then open the pop-up program on the page. I feel OK.

Then there's the problem with APP on your mobile phone, how does APP receive text messages, and how does it go to POST data on your computer?

There is a function of SMS broadcasting in android system. When a new text message comes, it will issue a broadcast. You can write a SMS broadcasting receiver yourself. When there is a new text message, the system will call your broadcasting receiver, and then you can get the text message content. Then you can send the content to the computer with http function. This is the general process below.

Just follow this line of thought, step on a lot of pits, and then go on to some key parts of the code

1, New Android Project

Set Get 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" />

New 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 messages and send them to your 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 contents of a text message
            final String body = smsMessage.getDisplayMessageBody();
            //Sender getting text messages
            final String address = smsMessage.getDisplayOriginatingAddress();
            //Time to get SMS
            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. Set up 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 exe program
            _ProcessUtil.CreateProcessAsUser(@"E:\codeProjects\Projects\showmsg\msg\bin\Debug\msg.exe", mm, _ProcessUtil._SESSION_TYPE.SessionFromActiveConsoleSessionId);
            Response.Write("1");
        }
    }

Microsoft has set up a session isolation mechanism behind the vista system. IIS is a background service and belongs to the Session 0 level. Messages cannot be exchanged through windows between different sessions, so you can't see the interface if you use System.Diagnostics.Process.Start in C#to call EXE directly.

Looking at the solution below, you can call a system's API method CreateProcessAsUser to create a process.

This is the APP interface after final improvement

 

 

Pop-up program

Topics: Android Mobile network IIS