Can compass be used to separate linear acceleration from gravity with accelerometer?

by Dan » Fri, 04 Feb 2011 05:22:11 GMT

Sponsored Links

I want to be able to detect vertical movement (relative to the z-axis)
on an Android phone. This can be done with just the accelerometer with
some degree of accuracy. However, I see that in Android 2.3 there are
now separate Gravity and Linear acceleration "virtual sensors", that
apparently will use the gyroscope (when available) to separate
accelerometer data into gravity (useful for detecting orientation) and
linear acceleration (useful for detecting movement).

The phone I'm using does not have a gyroscope, but only an
accelerometer and compass. Is it at all possible to use the compass to
separate linear acceleration from gravity in the accelerometer signal?

High-pass filters are a bit simplistic for my intended use, because
they don't really help detect whether movement is up or down and using
raw accelerometer data leads to orientation changes looking very
similar to linear movements.


Other Threads

1. Android 1.5 upgrade

I am new to the android OS with my HTC Eris phone on the Verizon
network. My understanding is that Android 2.0 offers some improvements
such as turn by turn navigation for google maps. I have heard that
there may be an update for 1.5 to the 2.0 OS. Is there any truth to
this and if so any projected date?


2. Communication between AppWidgetProvider and Configuration Activity

I have a widget whose appearance will depend on information gained
from the user in the configuration activity. However, I'm uncertain
how (and in what section of code) to act on the information gained
from the user in the config.

Here is the target functionality from the user's perspective:

   When the user creates the widget, the config activity prompts for a
string (with an EditText). The user types it in and presses the submit
button. The config activity goes away and the widget appears on the
homescreen displaying the text the user entered. When the user touches
the widget, the browser is opened and goes to a particular URL that is
determined in part by the string the user entered.

Here is what I have implemented so far:

The config activity lets the user enter data and happily displays it
to me as a Toast message. Then the config goes away as desired and the
widget appears with the default widget icon. If you touch the widget,
it goes to a hardcoded URL. (code below)

My question:

How do I "connect" the info from the config activity with the code
that displays the widget itself? If I put the user's string in a
putExtra of the intent sent in setResult(), where do I write the code
to retrieve that extra? It seems like it ought to put it somewhere in
the AppWidgetProvider code, but where? (Or is there a better way to do

Here are the relevant portions of my code:

public class Widget extends AppWidgetProvider
    public void onReceive(Context context, Intent intent)
        String action = intent.getAction();
        if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action))
                //Toast.makeText(context, "onReceive()",
            RemoteViews views = new RemoteViews(context.getPackageName
(), R.layout.widget);

            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse
            i.setComponent(new ComponentName("",
            PendingIntent pendingIntent = PendingIntent.getActivity
(context, 0, i, 0);
            views.setOnClickPendingIntent(, pendingIntent);

// end of

public class WidgetConfiguration extends Activity {

    EditText myEditText;

        public void onCreate(Bundle icicle) {

        Intent intent = new Intent();
        intent = getIntent();
        Bundle extras = intent.getExtras();
        int appWidgetId = extras.getInt

        // Set the view layout resource to use.

        // Find the EditText
        myEditText = (EditText)findViewById(;

            View.OnClickListener mOnClickListener = new View.OnClickListener
() {
                public void onClick(View v) {

                        Intent intent = new Intent();
                        intent = getIntent();
                        setResult(RESULT_OK, intent);
                        Toast.makeText(getBaseContext(), myEditText.getText(),

        // Bind the action for the submit button.

        // If they gave us an intent without the widget id, just bail.
        if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
//end of


3. Querying Media Artists, coming up 1 short

4. Task List

5. Installing APK from Internet?

6. Bersama si "Buram"

7. (Wta) push email di hero