您的位置:首页 > 移动开发 > Android开发

android清除应用缓存数据

2016-06-04 21:20 681 查看
public static boolean clearAppUserData( String packageName )
{
boolean clearStatus = false;
DataOutputStream os = null;
DataInputStream is = null;
Process p = null;
try
{
p = Runtime.getRuntime( ).exec( "su" );
os = new DataOutputStream( p.getOutputStream( ) );
is = new DataInputStream( p.getInputStream( ) );
os.writeBytes( "pm clear " + packageName + " \n" );
os.flush( );
os.writeBytes( "echo test  \n" );// 回显test 并获得test,确保上面的代码已经执行
os.flu
4000
sh( );
String result = is.readLine( );
Log.i( "clearData", result );
if ( result.equals( "test" ) )
{
clearStatus = true;
}
os.writeBytes( "exit\n" );
os.flush( );
os.close( );
p.destroy( );
}
catch ( IOException e )
{
e.printStackTrace( );
}
return clearStatus;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android