本文整理匯總了Java中android.app.Application.getSharedPreferences方法的典型用法代碼示例。如果您正苦於以下問題:Java Application.getSharedPreferences方法的具體用法?Java Application.getSharedPreferences怎麽用?Java Application.getSharedPreferences使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.Application
的用法示例。
在下文中一共展示了Application.getSharedPreferences方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import android.app.Application; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
final Application application = RuntimeEnvironment.application;
sharedPreferences = application.getSharedPreferences("test", Context.MODE_PRIVATE);
sharedPreferences.edit().clear().apply();
//dataSaver = new SharedPreferencesDataSaver(sharedPreferences);
dataSaver = new PaperDataSaver(application);
dataSaver = spy(dataSaver);
AndroidNoSql.initWith(
dataSaver
);
noSql = NoSql.getInstance();
noSql.reset();
}
示例2: handleChangePolicies
import android.app.Application; //導入方法依賴的package包/類
private void handleChangePolicies(Application application) {
SharedPreferences sharedPref = application.getSharedPreferences(
application.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
Uri sound = getTone(sharedPref);
if (notificationNeeded(application, sharedPref)) {
Log.i("TTM", "Changes found. Would fire!");
switch (sharedPref.getString("onChangeForm", "Banner")) {
case "None":
if (sound != null) {
Ringtone r = RingtoneManager.getRingtone(application.getApplicationContext(), sound);
r.play();
}
break;
case "Banner":
fireBanner(sound);
break;
}
} else {
Log.i("TTM", "Change check negative -> Won't fire any notification for change.");
}
}
示例3: DenbunConfig
import android.app.Application; //導入方法依賴的package包/類
public DenbunConfig(@NonNull Application app) {
nonNull(app);
// default config
this.preference = app.getSharedPreferences(PREF_NAME, MODE_PRIVATE);
this.daoProvider = new Dao.Provider() {
@Override public Dao create(@NonNull SharedPreferences preference) {
return new DaoImpl(nonNull(preference));
}
};
}
示例4: save
import android.app.Application; //導入方法依賴的package包/類
public void save(Gpx2FitOptions options) {
Application app = getApplication();
SharedPreferences mPrefs=app.getSharedPreferences(app.getApplicationInfo().name, Context.MODE_PRIVATE);
SharedPreferences.Editor ed=mPrefs.edit();
Gson gson = new Gson();
ed.putString(options.getClass().getName(), gson.toJson(options));
ed.apply();
}
示例5: load
import android.app.Application; //導入方法依賴的package包/類
public Gpx2FitOptions load() {
Application app = getApplication();
Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().create();
JsonParser parser=new JsonParser();
SharedPreferences mPrefs=app.getSharedPreferences(app.getApplicationInfo().name, Context.MODE_PRIVATE);
String json = mPrefs.getString(Gpx2FitOptions.class.getName(), null);
Gpx2FitOptions opts = null;
if (json != null && json.length() > 0)
opts = gson.fromJson(parser.parse(json).getAsJsonObject(), Gpx2FitOptions.class);
if (opts != null)
return opts;
else
return new Gpx2FitOptions();
}
示例6: getActiveTimetable
import android.app.Application; //導入方法依賴的package包/類
private static String getActiveTimetable(Application a) {
SharedPreferences sharedPref = a.getSharedPreferences(
a.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
for (String key : sharedPref.getAll().keySet()) {
// filter for timetables
if (key.startsWith("t#")) {
return sharedPref.getString(key, "undefined");
}
}
return "undefined";
}
示例7: onApplicationCreate
import android.app.Application; //導入方法依賴的package包/類
/**
* application onCreate最前麵調用
*
* @param application Application
* @param defaultEnv 默認環境
*/
public void onApplicationCreate(Application application, Env defaultEnv) {
try {
SharedPreferences sharedPreferences = application.getSharedPreferences(KEY, Context.MODE_PRIVATE);
String persistEnv = sharedPreferences.getString(KEY, defaultEnv.name());
this.env = Env.valueOf(persistEnv);
} catch (Exception e) {
e.printStackTrace();
this.env = Env.RELEASE;
}
}
示例8: providesSharedPreferences
import android.app.Application; //導入方法依賴的package包/類
@Provides
@Singleton
public SharedPreferences providesSharedPreferences(Application application){
return application.getSharedPreferences("user", Context.MODE_PRIVATE);
}
示例9: providesSharedPreferences
import android.app.Application; //導入方法依賴的package包/類
@Provides
@Singleton
SharedPreferences providesSharedPreferences(Application application) {
return application.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
}
示例10: provideSharedPreferences
import android.app.Application; //導入方法依賴的package包/類
@Provides @Singleton SharedPreferences provideSharedPreferences(Application app) {
return app.getSharedPreferences("superglue", MODE_PRIVATE);
}
示例11: provideSharedPreferences
import android.app.Application; //導入方法依賴的package包/類
@Provides @Singleton SharedPreferences provideSharedPreferences(Application app) {
return app.getSharedPreferences("{{packageName}}", MODE_PRIVATE);
}
示例12: MessageStateStorage
import android.app.Application; //導入方法依賴的package包/類
@Inject
MessageStateStorage(Application application) {
this.preferences = application.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
}
示例13: RNPushNotificationHelper
import android.app.Application; //導入方法依賴的package包/類
public RNPushNotificationHelper(Application context) {
this.context = context;
this.scheduledNotificationsPersistence = context.getSharedPreferences(RNPushNotificationHelper.PREFERENCES_KEY, Context.MODE_PRIVATE);
}
示例14: initData
import android.app.Application; //導入方法依賴的package包/類
public void initData(Application ctx) {
data = new Programdata();
grunddata = new Grunddata();
// Indlæsning af grunddata/stamdata.
// Først tjekkes om vi har en udgave i prefs, og ellers bruges den i raw-mappen
// På et senere tidspunkt henter vi nye grunddata
grunddata_prefs = ctx.getSharedPreferences("grunddata", 0);
for (Backend backend : App.backend) try {
Log.d("Initialiserer backend "+backend);
String grunddataStr = grunddata_prefs.getString(backend.getGrunddataUrl(), null);
if (grunddataStr == null || App.EMULATOR) { // Ingen grunddata fra sidste start - det er nok en frisk installation
grunddataStr = Diverse.læsStreng(backend.getLokaleGrunddata(ctx));
}
if (grunddataStr != null) {
backend.initGrunddata(grunddata, grunddataStr);
}
grunddata.kanaler.addAll(backend.kanaler);
} catch (Exception e) { Log.e(""+backend, e); }
// undgå crash
if (grunddata.json == null) grunddata.json = new JSONObject();
if (grunddata.android_json == null) grunddata.android_json = new JSONObject();
if (grunddata.forvalgtKanal == null) grunddata.forvalgtKanal = grunddata.kanaler.get(0); // Muzaiko / P1
try {
String kanalkode = prefs.getString(FORETRUKKEN_KANAL, null);
// Hvis brugeren foretrækker P4 er vi nødt til at finde underkanalen
kanalkode = tjekP4OgVælgUnderkanal(kanalkode);
Kanal aktuelKanal = grunddata.kanalFraKode.get(kanalkode);
if (aktuelKanal == null || aktuelKanal == Grunddata.ukendtKanal) {
aktuelKanal = grunddata.forvalgtKanal;
Log.d("forvalgtKanal=" + aktuelKanal);
}
if (!Udseende.ESPERANTO && !aktuelKanal.harStreams()) { // ikke && App.erOnline(), det kan være vi har en cachet udgave
aktuelKanal.getBackend().hentKanalStreams(aktuelKanal, Request.Priority.HIGH, NetsvarBehander.TOM);
}
if (aktuelKanal instanceof EoKanal && aktuelKanal.getUdsendelse()==null) {
Log.rapporterFejl(new IllegalArgumentException("Ingen udsendelser for "+aktuelKanal+" - skifter til "+grunddata.kanaler.get(0)));
aktuelKanal = grunddata.kanaler.get(0); // Problemet er at afspiller forventer en udsendelse på kanalen
}
afspiller.setLydkilde(aktuelKanal);
talesyntese.init(ctx);
} catch (Exception ex) {
Log.rapporterFejl(ex);
}
}
示例15: providesSharedPreferences
import android.app.Application; //導入方法依賴的package包/類
@Provides
@Singleton
SharedPreferences providesSharedPreferences(Application application) {
return application.getSharedPreferences(PREFS_DEFAULT, Context.MODE_PRIVATE);
}