2016-05-21 9 views
2

このコード言語をデバイスと同じにする必要があります。通知言語を電話言語と同じにするには

Notification.Builder builder = new Notification.Builder(this); 
builder.SetContentTitle("ok"); 
builder.SetContentText("ok"); 
Notification nottt = builder.Build(); 
NotificationManager noeman = GetSystemService(Context.NotificationService) as NotificationManager; 
noeman.Notify (122, nottt); 
StopSelfResult(this, OnStartCommand); 
+0

私の答えは以下の通りです。どうもありがとうございました。 – jzeferino

答えて

0

これは、通知に表示されるテキストをハードコーディングするためです。

Androidにはにstrings.xmlというリソースファイルがあります。

アプリケーションのデフォルト言語が英語であるとします。また、アプリケーションのすべてのテキストをポルトガル語にローカライズしたいとします。

ディレクトリ: この場合は、次の2つの代替のstrings.xmlファイル、ロケール固有のリソースディレクトリに格納されている各作成することができ

res/values/strings.xml 

をファイル:

<?xml version="1.0" encoding="utf-8"?> 
    <resources> 
     <string 
      name="string_name">nome</string> 
    </resources> 

は、(英語が含まれていますアプリケーションの使用するすべての文字列のテキストです。

ディレクトリ:

res/values-pt/strings.xml 

ファイル:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string 
     name="string_name">nome</string> 
</resources> 

は、すべての文字列のためのポルトガル語のテキストが含まれています。

文字列ファイルを作成した後、あなたは、このようにリソースを使用して通知を構築する必要があります。

NotificationCompat.Builder mBuilder = 
    new NotificationCompat.Builder(this) 
     .setSmallIcon(R.drawable.notification_icon) 
     .setContentTitle(getString(R.string.string_name)) 
     .setContentText(getString(R.string.other_string)); 

詳細についてはhereをクリックしてください。

+1

ありがとう@jzeferino – joba

関連する問題