当前位置: 首页>>代码示例>>Java>>正文


Java Application.getSharedPreferences方法代码示例

本文整理汇总了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();
}
 
开发者ID:florent37,项目名称:Android-NoSql,代码行数:17,代码来源:SharedPrefsTest.java

示例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.");
    }
}
 
开发者ID:dhbw-timetable,项目名称:dhbw-timetable-android,代码行数:23,代码来源:TimetableManager.java

示例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));
    }
  };
}
 
开发者ID:YukiMatsumura,项目名称:denbun,代码行数:12,代码来源:DenbunConfig.java

示例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();
}
 
开发者ID:gimportexportdevs,项目名称:gexporter,代码行数:9,代码来源:MainActivity.java

示例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();
}
 
开发者ID:gimportexportdevs,项目名称:gexporter,代码行数:15,代码来源:MainActivity.java

示例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";
}
 
开发者ID:dhbw-timetable,项目名称:dhbw-timetable-android,代码行数:12,代码来源:TimetableManager.java

示例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;
    }
}
 
开发者ID:lizhangqu,项目名称:support-application,代码行数:17,代码来源:EnvironmentCompat.java

示例8: providesSharedPreferences

import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
public SharedPreferences providesSharedPreferences(Application application){
    return application.getSharedPreferences("user", Context.MODE_PRIVATE);
}
 
开发者ID:florent37,项目名称:DaggerAutoInject,代码行数:6,代码来源:AppModule.java

示例9: providesSharedPreferences

import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
SharedPreferences providesSharedPreferences(Application application) {
    return application.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
}
 
开发者ID:micromasterandroid,项目名称:androidadvanced,代码行数:6,代码来源:PhotoFeedAppModule.java

示例10: provideSharedPreferences

import android.app.Application; //导入方法依赖的package包/类
@Provides @Singleton SharedPreferences provideSharedPreferences(Application app) {
  return app.getSharedPreferences("superglue", MODE_PRIVATE);
}
 
开发者ID:rogues-dev,项目名称:superglue,代码行数:4,代码来源:DataModule.java

示例11: provideSharedPreferences

import android.app.Application; //导入方法依赖的package包/类
@Provides @Singleton SharedPreferences provideSharedPreferences(Application app) {
  return app.getSharedPreferences("{{packageName}}", MODE_PRIVATE);
}
 
开发者ID:rogues-dev,项目名称:superglue,代码行数:4,代码来源:DataModule.java

示例12: MessageStateStorage

import android.app.Application; //导入方法依赖的package包/类
@Inject
MessageStateStorage(Application application) {
  this.preferences = application.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
}
 
开发者ID:ashdavies,项目名称:eternity,代码行数:5,代码来源:MessageStateStorage.java

示例13: RNPushNotificationHelper

import android.app.Application; //导入方法依赖的package包/类
public RNPushNotificationHelper(Application context) {
    this.context = context;
    this.scheduledNotificationsPersistence = context.getSharedPreferences(RNPushNotificationHelper.PREFERENCES_KEY, Context.MODE_PRIVATE);
}
 
开发者ID:zzzkk2009,项目名称:react-native-leancloud-sdk,代码行数:5,代码来源:RNPushNotificationHelper.java

示例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);
  }
}
 
开发者ID:nordfalk,项目名称:EsperantoRadio,代码行数:51,代码来源:App.java

示例15: providesSharedPreferences

import android.app.Application; //导入方法依赖的package包/类
@Provides
@Singleton
SharedPreferences providesSharedPreferences(Application application) {
    return application.getSharedPreferences(PREFS_DEFAULT, Context.MODE_PRIVATE);
}
 
开发者ID:bojanb89pa,项目名称:OAuth2Android,代码行数:6,代码来源:DataModule.java


注:本文中的android.app.Application.getSharedPreferences方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。