views:

47

answers:

1

I try work with NETWORK and GPS location provider simultaneously. In main activity I register location update request for each available provider:

        for (String provider : m_lm.getProviders(false)) {
            Intent intent = new Intent(GpsMain.this, GpsTestReceiver.class);
            PendingIntent pi = PendingIntent.getBroadcast(GpsMain.this,0, intent, 0);

            m_lm.requestLocationUpdates(provider, 60000, 10, pi);
        }

In my BroadcastReceiver (GpsTestReceiver) do incoming Intent handling:

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Bundle ex = intent.getExtras();
    if (ex.containsKey(LocationManager.KEY_STATUS_CHANGED)) {
        int status = (Integer)ex.get(LocationManager.KEY_STATUS_CHANGED);
        String str_status;
        switch (status) {
        case 1:
            str_status = "TEMPORARILY_UNAVAILABLE";
            break;
        case 2:
            str_status = "AVAILABLE";
            break;
        default:
            str_status = "OUT_OF_SERVICE";
            break;
        }
        String provider_name = ???;
        s = provider_name+": change status into "+str_status+"\n";
    }

}

Question is: how to determine from which provider arrived this intent? (String provider_name = ???;)

I try at registration moment include in the intent provider name as a payload like this:

                intent.putExtra("local.home.gpstest.PROVIDER", provider);

but unsuccessfully: incoming intent from provider erase my data...

A: 

I found solution. It was a misunderstanding how Android work with PendingIntents. Indeed solution with payload extra's is working, but if previously has been made some requests for PendingIntents without payload data, application receive old intents without payload data. It is necessary reload device or make new request for PendingIntent with flag:

            PendingIntent pi = PendingIntent.getBroadcast(GpsMain.this,0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

After that incoming intent will carry information about provider name.

lswa