private void sss () {
PackageManager pm = this.getPackageManager ();
try {
/ / Get the hidden function
by reflection/ / GetDeclaredMethod () to get the class defines methods
Method movePackage = null;
Method [] methods = pm.getClass () getDeclaredMethods ();.
/ / Field
. / / Move_external_dedia = pm.getClass () getDeclaredField ("MOVE_EXTERNAL_MEDIA");
/ / Call the function, and to assign parameter, callback
AppsMoveObserver class upon completion of the call flowfor (int i = 0; i
movePackage = methods [i];
}
}
movePackage.setAccessible (true);
movePackage.invoke ("com.tencent.qqgame",
new PackageMoveToMemoryObserver (), 2);
} Catch (Exception ex) {
ex.printStackTrace ();
}
}
class PackageMoveToMemoryObserver extends IPackageMoveObserver.Stub {
@ Override
public void packageMoved (String packageName, int returnCode)
throws RemoteException {
/ / TODO Auto-generated method stub
}
}
/ / IPackageMoveObserver.aidl
package android.content.pm;
/ **
* Callback for moving package resources from the Package Manager.
* @ Hide
* /
oneway interface IPackageMoveObserver {
void packageMoved (in String packageName, int returnCode);
}
Looking for a day post by reflex. Can move the program to the SD card .. erroneous results. Said
java.lang.IllegalArgumentException: expected receiver of type android.app.ApplicationPackageManager, but got java.lang.String
IPackageMoveObserver also defines a String. Could not be defined as android.app.ApplicationPackageManager
How to get it?
or ADB to move to a program in memory SD card
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
movePackage.invoke ("com.tencent.qqgame", new PackageMoveToMemoryObserver (), 2);
Changed movePackage.invoke (pm, "com.tencent.qqgame", new PackageMoveToMemoryObserver (), 1); try, that exception should not be reported, but it will not be successful is unknown
Reply:
What permissions ah
No comments:
Post a Comment