zoukankan      html  css  js  c++  java
  • 跨apk访问SharedPreferences

     
    http://xiechengfa.iteye.com/blog/1077355

    //该activity生成一个SharedPreferences

    //1:APK->activity
    //包名:com.test.pkg
    public void onCreate(Bundle savedInstanceState)
     {
      super.onCreate(savedInstanceState);
     SharedPreferences mPrefs = getSharedPreferences("com.test.pkg_preferences ",Context.MODE_WORLD_READABLE );
    //注意这里的  Context.MODE_WORLD_READABLE
    }
     
    //访问上一个activity的SharedPreferences
    //2:APK->activity
    public void onCreate(Bundle savedInstanceState)
     {        
      Context otherAppsContext = null;
      try
      {
       otherAppsContext = createPackageContext(
         "com.test.pkg ", 0);
      }
      catch (NameNotFoundException e)
      {
      }
     SharedPreferences mPrefs = otherAppsContext.getSharedPreferences("com.test.pkg_preferences ",Context.MODE_PRIVATE);
    }
    //备注:不同的APK互相访问对方的资源文件或图片也可以使用此方法(otherAppsContext )。
  • 相关阅读:
    P1127
    CF274D
    BZOJ1477: 青蛙的约会
    BZOJ2770: YY的Treap
    2017-10-湖南套题2
    BZOJ——2697: 特技飞行
    洛谷——P1621 集合
    2017-10-湖南套题1
    项目包结构初始化
    Maven的pom文件配置
  • 原文地址:https://www.cnblogs.com/leaven/p/2613291.html
Copyright © 2011-2022 走看看