sharepreference不同应用之间进行读写

Android 码拜 8年前 (2015-11-13) 988次浏览
急….急….急….本人需要在一个应用A里面些另外一个应用B里面的sharepreference.xml文件的一项。但是本人在A里面写完之后,到B应用的xml文件中查看时值一直没有变。但是在A中读出来的是已经变的。代码如下:A代码如下:

try{
				otherAppsContext = MainActivity.this.createPackageContext("com.example.sharepreferencewww", Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences otherSharedPreferences = otherAppsContext.getSharedPreferences("bbb",Context.MODE_WORLD_WRITEABLE);
Editor otherEditor = otherSharedPreferences.edit();
					otherEditor.putString("aaa", "sssdd");
					otherEditor.commit();
			}catch(Exception e){
//				Log.d("kk",""+e.printStackTrace());
				e.printStackTrace();
			}

在B中已经设置了Context.MODE_WORLD_WRITEABLE属性。
求指导阿

解决方案:20分
…. 假如你想改变xml文件内容  你必须解析xml 读写的方式改变啊~    otherEditor.commit();方法只能改变当前缓存中的数据值  不能直接改变xml中的内容的
解决方案:5分
原来也遇到过这个问题 后来改用contentprovider了,期待解决。
解决方案:5分
otherAppsContext = MainActivity.this.createPackageContext(“a的包”, Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences otherSharedPreferences = otherAppsContext.getSharedPreferences(“bbb”,Context.MODE_WORLD_WRITEABLE);写在B里面吧
解决方案:5分
假如是这样的话,你设置修改了Setiings中铃声  则发送一个广播去通知相应的应用去改变  反之  一样
解决方案:5分
楼上的方法就可以的,进程间的通信以前用过aidl,后来发现逻辑上有问题,就又用广播了

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明sharepreference不同应用之间进行读写
喜欢 (0)
[1034331897@qq.com]
分享 (0)