Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.content.SharedPreferences; import android.util.Log; public class Main { public static final String TAG = "SamcodesNotifications"; public static final String SLOT_TAG = "id"; public static final String UTC_SCHEDULED_TIME = "scheduledtime"; public static final String TITLE_TEXT_TAG = "titletext"; public static final String SUBTITLE_TEXT_TAG = "subtitletext"; public static final String MESSAGE_BODY_TEXT_TAG = "messagetext"; public static final String TICKER_TEXT_TAG = "tickertext"; public static final String INCREMENT_BADGE_COUNT_TAG = "incrementbadge"; public static void writePreference(Context context, int slot, Long alertTime, String titleText, String subtitleText, String messageBodyText, String tickerText, boolean incrementBadgeCount) { SharedPreferences.Editor editor = getNotificationSettings(context, slot).edit(); if (editor == null) { Log.i(TAG, "Failed to write notification to preferences"); return; } editor.putInt(SLOT_TAG, slot); editor.putLong(UTC_SCHEDULED_TIME, alertTime); editor.putString(TITLE_TEXT_TAG, titleText); editor.putString(SUBTITLE_TEXT_TAG, subtitleText); editor.putString(MESSAGE_BODY_TEXT_TAG, messageBodyText); editor.putString(TICKER_TEXT_TAG, tickerText); editor.putBoolean(INCREMENT_BADGE_COUNT_TAG, incrementBadgeCount); boolean committed = editor.commit(); if (!committed) { Log.i(TAG, "Failed to write notification to preferences"); } } public static SharedPreferences getNotificationSettings(Context context, int slot) { return context.getSharedPreferences(getNotificationName(slot), Context.MODE_WORLD_READABLE); } public static String getNotificationName(int slot) { return getPackageName() + ".Notification" + slot; } public static String getPackageName() { return "::APP_PACKAGE::"; } }