小编use*_*156的帖子

BroadcastReceiver没有收到意图Intent.ACTION_LOCALE_CHANGED

我希望我的应用程序在用户更改语言环境时随时都能识别.所以在我的Application班上,我创建了一个receiver听取系统意图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);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我按下主页并转到设置应用程序以更改我的区域设置时,不会显示Toast.在里面设置断点onReceive表明它永远不会被击中.

android broadcastreceiver android-intent

1
推荐指数
2
解决办法
6185
查看次数