What's the trick to making ProximityAlerts work?

by Faber Fedor » Sun, 08 Mar 2009 08:14:04 GMT


Sponsored Links
 I think I'm doing everything right wrt ProximityAlerts but I only get
notified in about 1 in a 100 times.

When I switch to Map Mode in my app, I gt a list of locations, map them and
send each one as a ProximityAlert via this code:

                  Intent intent = new Intent(TYW_PROXIMITY_ALERT);
                  PendingIntent proximityIntent =
PendingIntent.getBroadcast(MainMap.this, 1000, intent, 0) ;
                  myLocationManager.addProximityAlert(dLat, dLong,
proximityRadius, 100000000, proximityIntent);
                  Log.i(TAG, "Added ProximityIntent for" + ""+dLat +","+
""+dLong);

I have an IntentReceiver setup like this:

   public class ProximityIntentReceiver extends BroadcastReceiver {

        @Override
        public void onReceive (Context context, Intent intent) {

            String intentAction = intent.getAction();
            Toast.makeText(MainMap.this,
                    intentAction.toString(),
                    Toast.LENGTH_SHORT).show();
           // stuff about Vibrators and Notifications elided
           }
        }

I set up an IntentFilter programmatically:

    private void setIntentFilters() {
        IntentFilter proxFilter = new IntentFilter(TYW_PROXIMITY_ALERT);
        registerReceiver(new ProximityIntentReceiver(), proxFilter);
    }

which I call in onCreate().

I've set the minimum distance/time to check for updates to be ridiculously
low (10 feet, 5 secs, 0 for each, etc.).

I assumed I didn't actually have to move to see a ProximityAlert fired but
maybe I do, so today I set up three PAs and walked right past the
locations.  The GPS followed right along but I never got a Notification.

What's the magic to get it to work?  Or does it work in some manner I don't
yet grok?


-- 

Faber Fedor
Linux New Jersey
 http://linuxnj.com 
faberfedor.blogspot.com

--~--~---------~--~----~------------~-------~--~----~



What's the trick to making ProximityAlerts work?

by Mark Murphy » Sun, 08 Mar 2009 08:29:20 GMT


 


That may be your problem.

You want proximityRadius to be *big*, not small. A 10-foot proximity
radius means you need to be within 10 feet of the target location before
you will get an alert.

Also, FWIW, the radius is in meters.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Android Training in Sweden --  http://www.sotrium.com/training.php 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. getRuntime().exec("su do seomthing") fails (exit code)

hi
I work on rooted unlocked G1, latest JS firmware ADP1.5
I wrote some application that perform some root actions in the /system
of course, when messing up /system requires to remount that partition
but that's not my issue.

the code is fairly simple (attached at bottom of this message).
however when running a command as root (for example executeAsRoot("su
ls -l /system")) I get exit code 255 (i.e. -1 or failure)
when running that command as non-root - it runs ok with exit code 0.
The strange thing that this happens only in the real G1 . On the
emulator, root commands work just fine.
if i open a terminal on the G1 and perform su - I get the
"allow"/"deny" screen but after that I am able to perform actions as
root.
How can I debug the reason for the application process failure ?


private int executeAsRoot(String command) {
                Process process = null;
                int exitVal = -1;
                try {
                        process = Runtime.getRuntime().exec(command);
                        process.waitFor();
                        exitVal = process.exitValue();
                        m_logsView.append("\nexecuted:"+command +" 
->"+((exitVal==1)?
"success" : exitVal));
                        Log.i("executeAsRoot","Exit value is:"+exitVal);
                } catch (IOException e) {
                        m_logsView.append("\nexecuted:"+command +" 
->"+e.getLocalizedMessage
());
                        Log.e("executeAsRoot",e.getLocalizedMessage(), e);
                } catch (InterruptedException e) {
                        m_logsView.append("\nexecuted:"+command +" 
->"+e.getLocalizedMessage
());
                        Log.e("executeAsRoot",e.getLocalizedMessage(), e);
                } finally {
                        if (process != null) {
                                process.destroy();
                        }
                }
                return exitVal;

        }

--~--~---------~--~----~------------~-------~--~----~

2. ActivityInfo is null in Intrumentation class

@Override
    public void onStart() {
        super.onStart();
_intent = new Intent(Intent.ACTION_MAIN);
_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
_intent = _intent.setClass(getTargetContext(), ClassUnderTest.class);
ActivityInfo ai = _intent.resolveActivityInfo(getTargetContext
().getPackageManager(), 0);
        if (ai != null) {
                   ClassUnderTest activity = (ClassUnderTest)
startActivitySync(_intent);
        }
}


This a part of my code in my Instrumentation class. Earlier, i got a
run time Exception,Quote:
java.lang.RuntimeException: Unable to resolve activity for: Intent
{ flags=0x10000000 comp={com.android.test.ui/
com.android.test.ui.ClassUnderTest} }.

Later on, i checked the activity info which is always null. How to set
the ActivityInfo..? What is required to update in the code?

--~--~---------~--~----~------------~-------~--~----~

3. where to download android 1.5 r1 source code ?

4. how to know whether an app is installed or not

5. webView: How to click a web link and display in my WebView app

6. where to download android 1.5 r1 source code ?

7. About SQLite (query)