哪种方法pferred来存储我的Andr​​oid应用程序设置通过的PhoneGap和java文件来访问它们$ P $ [英] Which way is preferred to store my android application settings to access them via phonegap and java file

查看:155
本文介绍了哪种方法pferred来存储我的Andr​​oid应用程序设置通过的PhoneGap和java文件来访问它们$ P $的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的PhoneGap开发移动应用程序。

I develop a mobile application using phonegap.

我现在面临的主要问题是存储在方式的应用程序设置(显示语言,通知允许,...),让我从Java code和JavaScript的code访问它们

The main Issue I'm facing is to store an application setting (Display language, Notification Allow , ...) in way that allow me to access them from java code and from the javascript code

我发现我要存储这些设置有两种方式:

I found that I have two ways to store those settings:


  1. 使用数据库。

  2. 使用共享preferences。

  3. ???

我没有找到一个合适的科尔多瓦插件,让我来存储和从共享preferences负荷,希望如果有一个现成的插件,它采取行动,

I did not find a suitable cordova plugin that allow me to store and load from sharedPreferences and hopeful if there is a ready plugin to act with it,

和奇迹哪种方式是更好的性能和一般较为常见。

and wonder which way is better in performance and more common in general.

推荐答案

您使用PhoneGap的时候可以使用常规选项菜单和preferenceActivity,可以让您的应用程序可以轻松地将设置存储共享preferences。

You can use the regular options menu and PreferenceActivity when using PhoneGap that will let your app to easily store Settings in the SharedPreferences.

如果你需要从你的网页阅读设置,只需使用JavaScriptInterface网页和本地之间的通信。

If you need to read settings from your web page just use the JavaScriptInterface to communicate between the page and native.

活动的onCreate:

Activity onCreate:

bridge = new PGBridge(this);
appView.addJavascriptInterface(bridge, "bridge");


public static class PGBridge{
private DroidGap droidGap;
    public PGBridge(DroidGap droidGap){
        this.droidGap = droidGap;
    }
    public String getPreference(String preference){
        return PreferenceManager.getDefaultSharedPreferences(droidGap).getString(preference, "");
    }

在JS:

var preference = window.bridge.getPreference("something");

这篇关于哪种方法pferred来存储我的Andr​​oid应用程序设置通过的PhoneGap和java文件来访问它们$ P $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆