0

I am currently developing a simple application in which i needed to send data from mobile to watch which is working perfectly ... i have done this by using shared preference way..but problem is when device is in not sleep condition then it will show previous data so i have to make some move and have to call onresume method then it will perfectly .... so what i want basically is triggering smart watch (forcefully show screen) when i click on the button of android app and also what i want is quit from app when i leave app from the mobile .... here is code which is working for me on resume event

    @Override
    public void onResume()
    {
            Log.d("watch on ", "onResume");
            setScreenState(Control.Intents.SCREEN_STATE_ON);
            SharedPreferences pref = mContext.getSharedPreferences("text", Context.MODE_PRIVATE);
            String text = pref.getString("textToDisplay", "test");
            Bundle bundle1 = new Bundle();
            bundle1.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.txtvSWText);
            bundle1.putString(Control.Intents.EXTRA_TEXT, text);
            Bundle[] bundleData = new Bundle[1];
            bundleData[0] = bundle1;
            showLayout(R.layout.sample_control_2, bundleData);
    }

if u still have doubts let me know...i will try to explain more... any help on this will be appreciated

Thanks

user2800219
  • 73
  • 1
  • 10
  • Have you tried placing the above in the onCreate method so that is is displayed when the activity is created. – auracool Oct 28 '14 at 16:56
  • oncreate ? you are saying that for android side ? i want this for watch side i not think there is any method for watch on create is it ? or i have missed some part ? – user2800219 Oct 28 '14 at 19:31

1 Answers1

0

How about using a broadcast receiver

//Send with this
Intent intent = new Intent("com.yourApp.yourAppAction");
intent.setPackage("com.yourApp.yourMainApp");
intent.putExtra("event", "updateDisplay");
ctxt.sendBroadcast(intent);

//And then receive it and update the display in the control extension

registerBroadcastReceiver(this);

private void registerBroadcastReceiver(Context context) {
    IntentFilter iF = new IntentFilter();
    iF.addAction("com.yourApp.yourAppAction");
    context.registerReceiver(mReceiver, iF);            
}

private BroadcastReceiver mReceiver = new BroadcastReceiver() { 
    @Override
    public void onReceive(Context context, Intent intent)
    {
        String event = intent.getStringExtra("event");
        if (event.equals("updateDisplay")) {
            showBitmap(yourUpdatedBitmap);
        }
    }
};
pg316
  • 1,380
  • 1
  • 8
  • 7
  • l i think it should work but question is isn't we have to use Intent intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT); intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "com.example.package"); String hostAppPackageName = intent .getStringExtra(Registration.Intents.EXTRA_AHA_PACKAGE_NAME); intent.setPackage(hostAppPackageName); sendBroadcast(intent, Registration.HOSTAPP_PERMISSION); this is how we supposed to wakeup ControlExtension right ? but u have used broadcast receiver this will wake up control extension ? – user2800219 Oct 29 '14 at 07:29
  • ok I think I misunderstood your question. Yes you have to wake up the extension first as you mentioned – pg316 Oct 29 '14 at 15:47
  • k i have waked up extension but how i know that my app extension is in wake up mode and now i should use receiver ?and where i register receiver in constructor of the control extension or what?because in constructor it will call every time and it will created every time new receiver ? do u get my point ? please provide better way – user2800219 Oct 29 '14 at 16:01
  • Sorry let me try to better understand your question. So you have an app that runs on the phone. You want to click a button on the phone app and have the watch display update right. Actually if everything is in the same package this could all be done a lot easier. I think that there are a few ways in addition to a broadcast receiver that you can make this happen. For instance setting a static variable and function to communicate. But again you want to press a button, launch the watch app if not launched, perform an action right? – pg316 Oct 29 '14 at 18:00
  • yea exactly i want to do same thing and i needed to close app when i leave app from the mobile. – user2800219 Oct 29 '14 at 18:16
  • ok, one way you can do this is to have a static variable in your smartwatch app like appActive. set it to false by default, true when the watch app is active and false when the watch app exits. Then on your phone app you can check to see the state of the variable. Then you can launch the app on the watch if the appActive variable is false and then begin to update the display. This may be one way, but I will check to see if there is a better way. – pg316 Oct 29 '14 at 22:38
  • k i have solved with a interface and it works on smart watch 2 thing is i think there is not support for smart watch ?is it true or it should work on smart watch also control Extension...and i want to close smart watch app from mobile is it possible ? – user2800219 Oct 30 '14 at 16:16
  • can we change programattically background color or have to use bitmap? – user2800219 Oct 30 '14 at 16:43
  • ok as it turns out the best way to start your app is to use startReqest. Here is a post showing how it works: http://stackoverflow.com/questions/25945384/how-to-show-a-screen-if-sony-smartwatch-is-locked. Also if you want to stop the app you can use ControlExtension.stopRequest. As far as changing the background color, in a control extension you have total control of the screen so it is up to you to create and update your color background in your smartwatch app. – pg316 Oct 30 '14 at 17:31