Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to modify the Manifest file as well.</p> <p>Here is the example that works:</p> <p>These variables and methods are members of Service class:</p> <pre><code>public static final String MOVEMENT_UPDATE = "com.client.gaitlink.AccelerationService.action.MOVEMENT_UPDATE"; public static final String ACCELERATION_X = "com.client.gaitlink.AccelerationService.ACCELERATION_X"; public static final String ACCELERATION_Y = "com.client.gaitlink.AccelerationService.ACCELERATION_Y"; public static final String ACCELERATION_Z = "com.client.gaitlink.AccelerationService.ACCELERATION_Z"; private void announceAccelerationChanges()//this method sends broadcast messages { Intent intent = new Intent(MOVEMENT_UPDATE); intent.putExtra(ACCELERATION_X, accelerationX); intent.putExtra(ACCELERATION_Y, accelerationY); intent.putExtra(ACCELERATION_Z, accelerationZ); sendBroadcast(intent); } </code></pre> <p>And this are the methods from Main activity:</p> <p>You have to register receiver in the onResume method:</p> <pre><code> @Override public void onResume() { IntentFilter movementFilter; movementFilter = new IntentFilter(AccelerationService.MOVEMENT_UPDATE); accelerationReceiver = new AccelerationServiceReceiver(); registerReceiver(accelerationReceiver, movementFilter); startAccelerationService(); super.onResume(); } private void startAccelerationService() { startService(new Intent(this, AccelerationService.class)); } public class AccelerationServiceReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent)//this method receives broadcast messages. Be sure to modify AndroidManifest.xml file in order to enable message receiving { accelerationX = intent.getDoubleExtra(AccelerationService.ACCELERATION_X, 0); accelerationY = intent.getDoubleExtra(AccelerationService.ACCELERATION_Y, 0); accelerationZ = intent.getDoubleExtra(AccelerationService.ACCELERATION_Z, 0); announceSession(); updateGUI(); } } </code></pre> <p>This is the part of AndroidManifest.xml file that has to be set in order to receive broadcast messages:</p> <pre><code>&lt;activity android:name=".GaitLink" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;action android:name="com.client.gaitlink.CommunicationService.action.ACTIVITY_STATUS_UPDATE" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload