當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。