本文整理汇总了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);
}