2014-09-12 2 views
0

Мне интересно, как стилизовать push-уведомления на телефонах android, используя службу parse.com. Какие поля доступны, и есть ли возможность стилизовать цвет, изображение и форматы [полужирный, курсив, ...] push-уведомления? СпасибоКак стилизовать push-уведомление от JSON с помощью parse.com [Android]

+0

Просто узнайте, как стилизовать уведомление в Android для этого, потому что все, что помещено на ваше устройство с parse.com, будет отображаться в стиле для пользователя в соответствии с кодом (для уведомления) вашего приложения для Android, но не для синтаксического анализа .com push notification code.Refer [этот учебник] (http://www.tutorialspoint.com/android/android_notifications.htm), чтобы узнать, как бороться с уведомлениями android. –

ответ

0

для Android уведомления толчка, вы можете настроить следующее:

  1. предупреждения: сообщения об уведомлении в.
  2. Действие: Намерение должно быть запущено, когда нажим получен. Если значения заголовка или предупреждения не указаны, Intent будет запущен, но пользователю не будет уведомлено.
  3. название: значение, отображаемое в системном трее Android или уведомлении тоста Windows 8.

Source

Это tutorial, вероятно, будет полезно.

+0

Можно ли изменить форматирование текста ?! например, использовать курсивный стиль для заголовка и так далее? –

+0

Я не думаю, что это возможно. Сожалею. – Dehli

0

Вы можете разработать свой собственный стиль первый: добавить свой нажимной приемник в очевидном Как и дул:

<receiver android:name=".CustomPushReceiver" android:exported="false"> 
<intent-filter> 
    <action android:name="android.intent.action.BOOT_COMPLETED"/> 
    <action android:name="android.intent.action.USER_PRESENT"/> 
    <action android:name="com.parse.push.intent.RECEIVE"/> 
    <action android:name="com.parse.push.intent.DELETE"/> 
    <action android:name="com.parse.push.intent.OPEN"/> 
</intent-filter> 

CustomPushReceiver:

import android.content.Context; 
import android.content.Intent; 
import android.util.Log; 
import android.widget.Toast; 

import com.parse.ParsePushBroadcastReceiver; 

import mainViews.MainPage; 

import org.json.JSONException; 
import org.json.JSONObject; 



/** 
* Created by SadSad on 01/06/15. 
*/ 
public class CustomPushReceiver extends ParsePushBroadcastReceiver { 
    private final String TAG = CustomPushReceiver.class.getSimpleName(); 

    private NotificationUtils notificationUtils; 

    private Intent parseIntent; 

    public CustomPushReceiver() { 
     super(); 
    } 

    @Override 
    protected void onPushReceive(Context context, Intent intent) { 
     super.onPushReceive(context, intent); 

     System.out.println(intent.getExtras().getString("com.parse.Data")); 

     if (intent == null) 
      return; 

     try { 
      JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data")); 

      System.out.println(json); 

      Log.e(TAG, "Push received: " + json); 

      parseIntent = intent; 

      parsePushJson(context, json); 

     } catch (JSONException e) { 
      Log.e(TAG, "Push message json exception: " + e.getMessage()); 
     } 
    } 

    @Override 
    protected void onPushDismiss(Context context, Intent intent) { 
     super.onPushDismiss(context, intent); 
    } 

    @Override 
    protected void onPushOpen(Context context, Intent intent) { 
     super.onPushOpen(context, intent); 
    } 

    /** 
    * Parses the push notification json 
    * 
    * @param context 
    * @param json 
    */ 
    private void parsePushJson(Context context, JSONObject json) { 
     try { 
      System.out.println(json); 
      boolean isBackground = json.getBoolean("is_background"); 
      JSONObject data = json.getJSONObject("data"); 
      String title = data.getString("title"); 
      String message = data.getString("message"); 

      if (!isBackground) { 
       Intent resultIntent = new Intent(context, MainPage.class); 
       showNotificationMessage(context, title, message, resultIntent); 
      } 

     } catch (JSONException e) { 
      Log.e(TAG, "Push message json exception: " + e.getMessage()); 
     } 
    } 


    /** 
    * Shows the notification message in the notification bar 
    * If the app is in background, launches the app 
    * 
    * @param context 
    * @param title 
    * @param message 
    * @param intent 
    */ 
    private void showNotificationMessage(Context context, String title, String message, Intent intent) { 

    // you can use custom notification 
     notificationUtils = new NotificationUtils(context); 

     intent.putExtras(parseIntent.getExtras()); 

     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

     notificationUtils.showNotificationMessage(title, message, intent); 
    } 
} 

на заказ Извещение: This link is useful for custom notification

Смежные вопросы