ActivityManager am = (ActivityManager)this.getSystemService(this.ACTIVITY_SERVICE);
try {
clearMethod = am.getClass()
.getMethod("clearApplicationUserData", String.class,
IPackageDataObserver.class);
} catch (Exception e) {
Log.e("Error", "Android Error",e);
clearMethod = null;
}
if(clearMethod!=null){
try {
clearMethod.invoke(am,"com.android.browser",new ClearUserDataObserver());
} catch (Exception e) {
Log.e("Error", "Android Exception",e);
}
}
Exception
05-26 08:34:13.056: ERROR/Error(739): java.lang.reflect.InvocationTargetException
05-26 08:34:13.056: ERROR/Error(739): at android.app.ActivityManager.clearApplicationUserData(ActivityManager.java:475)
05-26 08:34:13.056: ERROR/Error(739): at java.lang.reflect.Method.invokeNative(Native Method)
05-26 08:34:13.056: ERROR/Error(739): at java.lang.reflect.Method.invoke(Method.java:521)
05-26 08:34:13.056: ERROR/Error(739): at com.iwidsets.clear.manager.AndClear.onCreate(AndClear.java:34)
05-26 08:34:13.056: ERROR/Error(739): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
05-26 08:34:13.056: ERROR/Error(739): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
05-26 08:34:13.056: ERROR/Error(739): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
05-26 08:34:13.056: ERROR/Error(739): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
05-26 08:34:13.056: ERROR/Error(739): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
05-26 08:34:13.056: ERROR/Error(739): at android.os.Handler.dispatchMessage(Handler.java:99)
05-26 08:34:13.056: ERROR/Error(739): at android.os.Looper.loop(Looper.java:123)
05-26 08:34:13.056: ERROR/Error(739): at android.app.ActivityThread.main(ActivityThread.java:4203)
05-26 08:34:13.056: ERROR/Error(739): at java.lang.reflect.Method.invokeNative(Native Method)
05-26 08:34:13.056: ERROR/Error(739): at java.lang.reflect.Method.invoke(Method.java:521)
05-26 08:34:13.056: ERROR/Error(739): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-26 08:34:13.056: ERROR/Error(739): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
05-26 08:34:13.056: ERROR/Error(739): at dalvik.system.NativeStart.main(Native Method)
05-26 08:34:13.056: ERROR/Error(739): Caused by: java.lang.SecurityException: 739 does not have permission:android.permission.CLEAR_APP_USER_DATA to clear datafor process:com.android.browser
05-26 08:34:13.056: ERROR/Error(739): at android.os.Parcel.readException(Parcel.java:1218)
05-26 08:34:13.056: ERROR/Error(739): at android.os.Parcel.readException(Parcel.java:1206)
05-26 08:34:13.056: ERROR/Error(739): at android.app.ActivityManagerProxy.clearApplicationUserData(ActivityManagerNative.java:2016)
05-26 08:34:13.056: ERROR/Error(739): ... 17 more
这是我的androidManifest.xml文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iwidsets.clear.manager"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndClear"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.CLEAR_APP_USER_DATA"></uses-permission>
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"></uses-permission>
</manifest>
答案 0 :(得分:1)
您无法修改错误。
您缺少权限,请在logcat输出中查看此行:
.SecurityException: 739 does not have permission:android.permission.CLEAR_APP_USER_DATA to clear datafor process:com.android.browser
答案 1 :(得分:0)
正如java API所述:
InvocationTargetException已选中 包装异常的异常 被调用的方法抛出或 构造
似乎在你的方法clearApplicationUserData的某个地方有一个异常
编辑:正如pentium10指出你的clearApplicationUserData方法缺少权限。
答案 2 :(得分:0)
public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
try {
return ActivityManagerNative.getDefault().clearApplicationUserData(packageName,
observer);
} catch (RemoteException e) {
return false;
}
}