Please look at the examples in ApiDemos.
2009/8/3 Lutz Schönemann <[email protected]>
>
> I have created a new project focusing on that problem.
> Now the PendingIntent.getBroadcast() method doesn't try to start an
> activity any longer.
>
> But the problem that the LocationManager doesn't fire the intent still
> consists. I have a Activity that creates a PendingIntent and calls the
> addProximityAlert() method. The BroadcastReceiver should only log the
> incomming events. The only event that appears is the broadcast I send
> by my self (sendBroadcast(intent);)
>
> public class MyActivity extends Activity {
>
> private static final String PROXIMITY_ALERT =
> "de.pengingintent.Activity.PROXIMITY_ALERT";
> private static final String TAG = "MyActivity";
>
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
>
> Intent intent = new Intent(PROXIMITY_ALERT);
> PendingIntent pintent =
> PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
>
> // just to test if the broadcast receiver exists
> Log.d(TAG, "testing broadcast receiver");
> sendBroadcast(intent);
>
> LocationManager lm =
> (LocationManager)getSystemService(Context.LOCATION_SERVICE);
> lm.addProximityAlert(1, 1, 200, 20000, pintent);
> }
>
> }
>
> public class MyReceiver extends BroadcastReceiver {
>
> private static final String TAG = "MyReceiver";
> @Override
> public void onReceive(Context context, Intent intent) {
> // TODO Auto-generated method stub
> Log.d(TAG, "received new intent");
> if(intent.getAction() != null)
> Log.d(TAG, intent.getAction());
>
> Bundle extras = intent.getExtras();
> if(extras != null) {
>
> if(extras.containsKey(LocationManager.KEY_PROXIMITY_ENTERING)) {
> Log.d(TAG,
> LocationManager.KEY_PROXIMITY_ENTERING + " is: " +
> Boolean
> .toString(extras.getBoolean(LocationManager.KEY_PROXIMITY_ENTERING)));
> }
> }
> }
>
> }
>
>
> The latitude and longitute I registerd for is 1, 1 and on the terminal
> I run the "geo" command multiple times:
>
> geo fix 3 3
> geo fix 1 1
> ...
>
> What am I doing wrong?
>
>
>
>
> Am 03.08.2009 um 15:12 schrieb Lutz Schönemann:
>
> >
> > Hi,
> >
> > I have more than one problem to use the addProximityAlert() method
> > from the LocationManager class.
> >
> > The first thing is that I want to create a PendingIntent for a
> > broadcast receiver. Therefor I use this code:
> >
> > Intent intent = new Intent("app1.PROXIMITY_ALERT");
> > PendingIntent pintent = PendingIntent.getBroadcast(Activity1.this,
> 1,
> > intent, 0);
> >
> > The problem is, that I get this error message:
> >
> > "No activity found to handle intent { action=app1.PROXIMITY_ALERT }"
> >
> > I'm confused because this should not call an Activity but a
> > BroadcastReceiver.
> > If I send this intent as a broadcast my self, the BroadcastReceiver
> > receives this intent...
> >
> > What is wrong with my code?
> >
> >
> > I tried to create an intent to call an Activity instead and registered
> > it to be send when reaching a location:
> >
> > Intent intent = new Intent(Intent.ACTION_DEFAULT)
> > intent.setType("vnd.app1/activity1");
> >
> > PendingIntent pintent = PendingIntent.getBroadcast(Activity1.this,
> 1,
> > intent, 0);
> >
> > LocationManager lm =
> > (LocationManager)getSystemService(Context.LOCATION_SERVICE);
> > lm.addProximityAlert(latitude, longitude, radius, -1, pintent);
> >
> > The problem is that the Activity is called immediately but NEVER if
> > the registered location is reached.
> >
> >
> > I'm working on a emulator and setting the gps coordinates using the
> > geo fix
> > command.
> >
> >
> > Can anyone help me with this problems
> > thanks
> >
> > >
> >
>
>
> >
>
--
Dianne Hackborn
Android framework engineer
[email protected]
Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails. All such
questions should be posted on public forums, where I and others can see and
answer them.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---