4

I'm new at Android development and I have a question.

I'm creating a notification for the user. That's all OK. The problem is that when I change the device language, my notification doesn't updates yourself. I don't know if there are any native method to do that on Android.

For now, my solution is: when creating the notification, I create a thread that verifies if the language has changed. If so, it updates my notification. The thread is stoped when the user cleans the notification.

So, I don't know if it's a good pratice, or if there's another whay to to that.

PS: The application has lots of strings.xml files to translate strings. I'm using Thread class to create the thread.

Thanks in advance and sry for the bad english!

Felps
  • 43
  • 1
  • 3

2 Answers2

0

In your application class, you can keep reference of the Notification Ids currently showing along with their info. You can detect language change in onConfigurationChanged(Configuration newConfig) and update your notifications there.

public class App extends Application {
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        //update your notifications there is no need for a Thread
    }
}

Another Solution (Real one)

Add Receiver for locale Change

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        //retrieve the list of notifications
        //update them (no need for thread)
    }
}

Add to your manifest:

<receiver android:name="MyReceiver">
    <intent-filter>
        <action android:name="android.intent.action.LOCALE_CHANGED">
        </action>
    </intent-filter>
</receiver>
Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106
  • Hello Sherif, thanks for the answer, but it didnt work. Should I write something in manifest.xml? Just to complement, I'm firing this notification from an AsyncTask Class. I don't know if it makes any difference. – Felps Oct 31 '13 at 17:38
  • When you send a notification, you will need to save the id of the notification in the Application instance. Then onConfigurationChanged, you need to update the notifications with these ids. – Sherif elKhatib Oct 31 '13 at 19:57
  • I understood that, but it still isn't the point. I can't save the notificationId in my app, cause i won't have an app to update the notification. User can stop application before changing the device language, so, in this scenario, notification won't be updated eighter. I can't imagine another whay of doing that but doing a service. But I dont know if it would be viable doing a service just to update a notification. – Felps Oct 31 '13 at 23:28
  • Why the hell, in that scenario, a user will change the language of their phone? – ramaral Nov 01 '13 at 12:20
  • Well, there isnt a reason, but it can happens. I just want to know if there are any whay to do what I want. As I told you, I think that the only whay is making a service to handle that, but i'd like to know if there's another whay... Actually, try take a screenshot on your device, then change the language. Thats the same issue. – Felps Nov 01 '13 at 12:33
  • You think the screenshot should change after changing the language? I didn't get what you mean! – Sherif elKhatib Nov 01 '13 at 12:36
  • Not the image but the notification title and text. The notification wich says "Screenshot captured". If I change language, it shoud change too. – Felps Nov 01 '13 at 12:54
0

Most likely I would not have understood your question correctly.

Since you has lots of strings.xml files to translate strings.
You only need to put them in the appropriate folders:

res/values-pt-rPT //For Portuguese Portugal
res/values-fr-rFR // For French France
res/values-fr-rCA // For French France Canada

And so on.

ramaral
  • 6,149
  • 4
  • 34
  • 57
  • 1
    Hello ramaral. I'll try to explain again. Imagine you have an appliation. Than this app fires a notification. This notification stays there in the statusBar. Well, you let it there, close you application. The notification continues there. Now, try to go toconfigurations and change the device language. In this point, the device is updated and get the new language. Go and see the notification that was there. It didnt change. It continued with the last language. Sry if I'm not clear. – Felps Oct 31 '13 at 19:16