android - How to change text in host application from sony smartwatch 2? -


I'm trying to trigger a button click on a smartwatch and then want to change the text in the host application in Android phone . I tried to send a broadcast intent to the broadcast receiver and started a service that includes a way to change the text in a host application. However, the changeText () method is not working. I am able to start a service, but I am not able to change the text. Please see what is wrong with my code. It would be nice if you can give a brief example of how to broadcast the host application from smartwatch to the best practice.

My control extension class

  class SampleControlSmartWatch2 provides control extension {// Other code Object Elements on Public Zero (ControlObjectClickEvent Event) {Intentional Intent = New Intent (Sample Connection Service .INTENT_ACTION_BROADCAST); Intent.putExtra ("name", "something"); MContext.sendBroadcast; }}   

My broadcast receiver

  extends the public class extension ratio broadcasts receiver {@ Override on public blank recipient (final reference reference, final purpose Intent) {intent.setClass (reference, host server service); Context.startService (intent); }}   

My host application service

  Expands the public class host service service {// Other code @ Override Creates at Public Zero { Super.onCreate (); ChangeText (); } Public Zero Transformation Text () {Layout Inflator Inflator = (Layout Inflator) This .get System System (Reference. LEOUT_INFLATER_SERVICE); Seeouthost = inflator.flat (r layout.activ_man, empty); TextView textView = (TextView) layouthost.findvibid (ridtextebbank); Logs. I (tag, textview.gettext) .toString ()); // It shows the "original" textView.setText ("converted text"); Logs. I (tag, textview.gettext) .toString ()); // This shows "changed text"}}   

My AndroidManist XML

  & lt; Application & lt ;! - other specialty - & gt; & Lt; Service Android: name = "com.sony.samplecontrol.Notification.SampleExtensionService" /> & Lt; Service Android: name = "com.sony.samplecontrol.Notification.HostService" /> & Lt; Receiver Android: name = "com.sony.samplecontrol.Notification.ExtensionReceiver" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "com.sony.samplecontrol.Notification.BROADCAST" /> & Lt ;! - Other actions - & gt; & Lt; / Intent-Filter & gt; & Lt; / Receiver & gt; & Lt; / Application & gt;    

Not sure that this is the best way, but in this way I solved it Is:

In my activity:

  Private Mistake mService; Last Messenger mMessenger = New Messenger (new incoming handler (this)); @ Override Safe void onStart () {super.onstart (); Intent = intent to mean (this, MyService.class); Binseva (Intent, Mconction, Context, BIFAATOOCRert); } Private service connection mConnection = New service connection () {@OverrideServiceConnected on Public Zero (ComponentName className, IBinder service) {local bunker typing = (local billing) service; MService = binder.getService (); MService.RegisterMessenger (mMessenger); MBound = true; } @ Override public service on disconnected (ComponentName arg0) {mBound = false; }}; Public Static Class Expands Incoming Handler Handler {Private Final Week Reference & lt; My Activity & gt; Activity; Inherent movement (Myactivity activity) {this.activity = new WeakReference & lt; MyActivity & gt; (Activity); } @ Override Public Wide Hands (Message Message) {MyActivity dialog = activity.get (); Bundle Data = msg.getData (); // TODO: see updates here}};   


In my service:

  Private Arrestists & lt; Messenger & gt; Envoys = New Arsuachi & lt; Messenger & gt; (); Public class increases the LocalBuilder Brander (Public MySewice Missseva service) (Back to MyService.}} Public Zero Registered Manager (messenger);} Public Class Myreasevar Expands Broadcast Receiver {@ Override Public Recorded On Reserves (intended for context reference) {For Messenger Messenger: Messenger} {Message = New Message (); Bundle Data = New Bundle (); // TODO: Add message to message here messenger.send (m ) ;   

Some parts are missing (cancellation of Messenger unbound service), but this should be the main part.

If you have problems registering a broadcast receiver, The post can help:

Perhaps you can do this without having to do a service by creating a broadcast receiver as an internal class of your activity.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -