Unregistering a statically defined BroadcastReceiver in code?

by Akbur » Sun, 02 Nov 2008 23:22:11 GMT


Sponsored Links
 Dear all,

I've registered my BroadcastReceiver in my application manifest like
this:

    <application android:icon="@drawable/icon" android:label="@string/
app_name" android:debuggable="true">
        <receiver android:enabled="true" android:name=".SMSReceiver">
            <intent-filter>
                <action
android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>
    </application>

Suppose I wish to make an Activity which is able to unregister this
BroadcastReceiver.  I know there is a method called
unregisterReceiver(BroadcastReceiver receiver) however I am not sure
how I can pass the correct receiver instance to it?  Has any one done
this?  If so, would you care to share? :-)

Thanks!
Akbur

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



Unregistering a statically defined BroadcastReceiver in code?

by Jason Parekh » Mon, 03 Nov 2008 02:32:19 GMT


 Hi Akbur,

You can't "unregister" this receiver, but you can disable it.  Check out
PackageManager.setComponentEnabledSetting.

jason





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


Sponsored Links


Unregistering a statically defined BroadcastReceiver in code?

by Akbur » Mon, 03 Nov 2008 19:14:47 GMT


 This looks as though it should do the trick.  Thanks Jason. :-)

Akbur




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



Other Threads

1. Stopped unexpectedly on a real phone but not on the simulator

Hi all, I have an MapView app downloaded from internet, when I tested
it on the simulator, everything is fine, but when I installed it on my
phone, the app stopped unexpectedly. Here is the code

public class CurrentLocationWithMap extends MapActivity {

    MapView map;

    MapController ctrlMap;
    Button inBtn;
    Button outBtn;
    ToggleButton switchMap;

    @Override
        protected boolean isRouteDisplayed() {
                return false;
        }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        map = (MapView)findViewById(R.id.myMapView);
        List<Overlay> overlays = map.getOverlays();
        MyLocationOverlay myLocation = new
MyLocationOverlay(this,map);
        myLocation.enableMyLocation();
        overlays.add(myLocation);

        ctrlMap = map.getController();
        inBtn = (Button)findViewById(R.id.in);
        outBtn = (Button)findViewById(R.id.out);
        switchMap = (ToggleButton)findViewById(R.id.switchMap);

        OnClickListener listener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                case R.id.in:
                    ctrlMap.zoomIn();
                    break;
                case R.id.out:
                    ctrlMap.zoomOut();
                    break;
                default:
                    break;
                }
            }
        };
        inBtn.setOnClickListener(listener);
        outBtn.setOnClickListener(listener);

        //=======================================

        switchMap.setOnCheckedChangeListener(new
OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton cBtn, boolean
isChecked) {
                if (isChecked == true) {
                    map.setSatellite(true);
                } else {
                    map.setSatellite(false);
                }
            }
        });

        LocationManager locationManager;
        String context = Context.LOCATION_SERVICE;
        locationManager = (LocationManager)getSystemService(context);
        //String provider = LocationManager.GPS_PROVIDER;

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        String provider = locationManager.getBestProvider(criteria,
true);

        Location location =
locationManager.getLastKnownLocation(provider);
        updateWithNewLocation(location);
        locationManager.requestLocationUpdates(provider, 2000, 10,
                        locationListener);
    }
   private final LocationListener locationListener = new
LocationListener() {
        public void onLocationChanged(Location location) {
        updateWithNewLocation(location);
        }
        public void onProviderDisabled(String provider){
        updateWithNewLocation(null);
        }
        public void onProviderEnabled(String provider){ }
        public void onStatusChanged(String provider, int status,
        Bundle extras){ }
    };
    private void updateWithNewLocation(Location location) {
        String latLongString;
        TextView myLocationText;
        myLocationText = (TextView)findViewById(R.id.myLocationText);
        if (location != null) {
            double lat = location.getLatitude();
            double lng = location.getLongitude();
            latLongString = "Latitude:" + lat + "\nLongtitude:" + lng;

            ctrlMap.animateTo(new GeoPoint((int)(lat*1E6),(int)
(lng*1E6)));
        } else {
            latLongString = "Position not found";
        }
        myLocationText.setText("Current location:\n" +
        latLongString);

    }
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
        android:id="@+id/myLocationText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <Button
        android:id="@+id/in"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Zoom in" />
    <Button
        android:id="@+id/out"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Zoom out" />
</LinearLayout>
<ToggleButton
    android:id="@+id/switchMap"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textOff="satelliteoff"
    android:textOn="satellite on"/>
<com.google.android.maps.MapView
        android:id="@+id/myMapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="0sHYAwyCrlo-VN0Au3pKZnNg6XqNUc8xf1hyyEQ"
     />
</LinearLayout>

-- 

2. Menawarkan HTC Tattoo

Teman kantor ingin menjual HTC Tattoo nya.
Minta 2,9jt.
Baru 2 bulan pakai. Komplit.
Screen protector.
Silakan email ke danieltum...@gmail.com
Thank you.



-- 
Regards,


Daniel Tumiwa

Sent from The TumiwaDroid Nexus One

-- 
"Indonesian Android Community [id-android]" 

3. how to avoid running of multiple process

4. Help: Magic 32A, setelah join latitude maps jadi force close

5. using internal class that is not shipped with android SDK

6. Wrap title of activity with dialog theme?

7. Error "- exec '/system/bin/sh' failed: No such file or directory (2) -"