Android跨程序访问SharedPreferences

    xiaoxiao2021-03-25  105

    在4.4上是有效的,高版本不保证

    存储端程序关键代码App1

    SharedPreferences pref = getContext().getSharedPreferences("File", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE); SharedPreferences.Editor editor = pref.edit(); editor.putBoolean("para", true); editor.apply(); 读取端程序关键代码App2

    try { Context app1Context = context.createPackageContext(App1_PACKAGE_NAME, Context.CONTEXT_IGNORE_SECURITY); SharedPreferences sh = app1Context .getSharedPreferences("File", Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS); sh.getBoolean("para", false); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); }

    转载请注明原文地址: https://ju.6miu.com/read-11500.html

    最新回复(0)