lundi 25 mai 2015

BroadcastReceiver does not receive intent Intent.ACTION_LOCALE_CHANGED

I want my app to be aware anytime the user changes the locale. So in my Application class, I create a receiver to listen to the system intent ACTION_LOCALE_CHANGED:

public final class MyApp extends Application {

    private BroadcastReceiver myReceiver = new BroadcastReceiver() {

    @Override public void onReceive(Context context, Intent intent) {
        String locale = Locale.getDefault().getCountry();
        Toast.makeText(context, "LOCALE CHANGED to " + locale, Toast.LENGTH_LONG).show();
    }
    };

    @Override public void onCreate() {
       IntentFilter filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);

       LocalBroadcastManager.getInstance(this).registerReceiver(myReceiver, filter);
    }
}

When I press home and go to the settings app to change my locale, the Toast is not shown. Setting the breakpoint inside onReceive shows it never gets hit.

Aucun commentaire:

Enregistrer un commentaire