How to send notification messages from Windows apps to Android apps

Source: Internet
Author: User

Mobile apps can be used as a tool for desktop apps to receive status information for desktop apps. Here's how to implement a simple Android program to receive the working status of a Windows scanner app.

Reference: How to Push notifications to Android applications from Windows

Ideas
    1. Creating a socket connection for application communication

    2. Start the background service on Android to receive information

    3. After receiving the message, the backend service sends the push message to the Android app

Socket message Sending

Using TcpListener to create a socket connection, the relevant content can be consulted:Wireless TWAIN Document scanning on Android

Start Stop Android Service

To create a service Notificationservice:

public class notificationservice extends service {     @ Override    public void oncreate ()  {    }       @Override     public void ondestroy ()  {     }      @Override     public ibinder onbind (Intent  intent)  {        return mBinder;     }     private final ibinder mbinder = new binder ( )  {         @Override          protected boolean ontransact (Int code, parcel data, parcel reply,                 int flags )  THROWS REMOTEEXCEPtion {            return  Super.ontransact (code, data, reply, flags);         }     };}

Declare this service in androidmanifest.xml :

<service android:name = "Com.dynamsoft.twain.NotificationService"/>

Start the service in onCreate (Bundle) :

StartService (New Intent (Scanassist.this, Notificationservice.class));

To stop the service in OnDestroy () :

StopService (New Intent (Scanassist.this, Notificationservice.class));

Push Android Notifications

Call Notificationmanager:

Private Notificationmanager MNM = (notificationmanager) getsystemservice (Notification_service);

Create Activity Incomingmessageviewfor content display:

public class incomingmessageview extends activity {      public static final string key_from =  "from";     public  static final String KEY_MESSAGE =  "MESSAGE";     public  static final int NOTIFICATION_ID = R.layout.activity_main;       @Override     protected void oncreate (bundle savedinstancestate)  {        super.oncreate (savedinstancestate);         textview view = new textview (This);         view.settext (Getintent (). Getcharsequenceextra (Key_from)  +  ": "  +  getintent (). Getcharsequenceextra (key_message));          Setcontentview (view); &NBSP;&NBSP;&Nbsp;      notificationmanager nm =  (NotificationManager)   Getsystemservice (Notification_service);         nm.cancel (NOTIFICATION_ ID);     }}

Declare activity in androidmanifest.xml :

<activity android:name= "Com.dynamsoft.twain.IncomingMessageView" android:label= "@string/app_name" ></activity>

Send a message and display it on the status bar:

Intent notifyintent = new Intent (this, incomingmessageview.class); Notifyintent.putextra (Incomingmessageview.key_ From, from); Notifyintent.putextra (Incomingmessageview.key_message, MESSAGE); Pendingintent pendingintent = pendingintent.getactivity (this, 0, notifyintent, Pending Intent.flag_one_shot); Notification Notif = new Notification.builder (this). Setcontenttitle ("TWAIN Scanner Status"). Setcontenttext (Message). Setsmallicon (R.drawable.ic_launcher). Setcontentintent (pendingintent). Setticker (Message). build (); Notif.defaults = Notification.default_all; Mnm.notify (incomingmessageview.notification_id, Notif);
Case
    1. Run Android app, start service

    2. Apps switch to the background to manipulate other applications, such as opening a browser

    3. To manipulate apps on Windows, click File Scan

    4. After the scan is successful, the message is sent to the phone

Source

Https://github.com/DynamsoftRD/ScanAssist

git clone https://github.com/DynamsoftRD/ScanAssist.git


How to send notification messages from Windows apps to Android apps

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.