小编Uma*_*kar的帖子

当用户选择语言时如何更改应用程序的语言?

我希望我的应用程序支持三种语言西班牙语,葡萄牙语和英语.并选择在app中选择语言.我已经做了

1)3个可绘制的文件夹drawable-es,drawable-pt,drawable.

2)3个值文件夹值-es,values-pt,values.根据语言更改String.xml值.

我有imageView来选择语言.当点击它打开菜单包括选项英语,西班牙语,葡萄牙语.

我通过此代码在选项选择中在应用程序内设置Locale

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.en:
             Locale locale = new Locale("en"); 
             Locale.setDefault(locale);
             Configuration config = new Configuration();
             config.locale = locale;
             getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
             Toast.makeText(this, "Locale in English !", Toast.LENGTH_LONG).show();
             break;

        case R.id.pt:
             Locale locale2 = new Locale("pt"); 
             Locale.setDefault(locale2);
             Configuration config2 = new Configuration();
             config2.locale = locale2;
             getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());

             Toast.makeText(this, "Locale in Portugal !", Toast.LENGTH_LONG).show();
             break;

        case R.id.es:
             Locale locale3 = new Locale("es"); 
             Locale.setDefault(locale3);
             Configuration config3 = new Configuration();
             config3.locale = locale3;
             getBaseContext().getResources().updateConfiguration(config3, …
Run Code Online (Sandbox Code Playgroud)

android localization

92
推荐指数
5
解决办法
17万
查看次数

当应用关闭时,FCM推送通知不起作用

好的,所以我到处都看了,找不到答案。我已经在Android应用程序中实现了推送通知,并且在该应用程序处于运行状态(前景或后台)时,一切正常,但是,如果我关闭该应用程序,则我将停止接收通知。这是我发送通知的PHP代码。

public static function sendNotification($token){
    $url = 'https://fcm.googleapis.com/fcm/send';
    $fields = array(
        'notification' => array("title" => "Test","body" => "Test Message","icon" => "default","sound" => "default"),
        "data" => "test message",
        'to' => $token
    );
    $headers = array(
        'Authorization:key = AIzaSyAKHM3MoMACjmeVK46TDg8-rTj1KoVjzWs',
        'Content-Type: application/json'
    );
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST,true);
    curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);                           
    curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));
    $result = curl_exec($ch);
    if($result === FALSE) {
        throw new errorSendingNotification();
    }
    curl_close($ch);
    // Result returns this
    // {"multicast_id":8978533958735781479,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1468627796530714%7c0e4bee7c0e4bee"}]}
    return $result;
}
Run Code Online (Sandbox Code Playgroud)

php java android curl push-notification

4
推荐指数
1
解决办法
5320
查看次数

标签 统计

android ×2

curl ×1

java ×1

localization ×1

php ×1

push-notification ×1