I need to install apk file without any user prompt like Google PlayStore does. I know this question has been asked many times but still i didn't found any solvable answer. I am just installing app from my sdcard and i tried following way,
public void getInstall(Context context) {
File file = new File(Environment.getExternalStorageDirectory()
+ "/Demo.apk");
Uri mPackageURI = Uri.fromFile(file);
ApplicationManager appMgr = null;
try {
appMgr = new ApplicationManager(context);
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NoSuchMethodException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int installFlags = 1;
PackageManager pm = context.getPackageManager();
Method method = null;
try {
method = pm.getClass().getMethod(
"installPackage",
new Class[] { android.net.Uri.class,
android.content.pm.IPackageInstallObserver.class,
Integer.TYPE, String.class });
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String installerPackageName = "com.myapp.demo";
PackageInstallObserver observer = appMgr.new PackageInstallObserver();
try {
method.invoke(pm, new Object[] { mPackageURI, observer,
installFlags, installerPackageName });
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
But I am getting error Neither user 10057 nor current process has android.permission.INSTALL_PACKAGES
even though i added this permission in my manifest file.
My device is not rooted and i want it to do without rooting , In many answers i found that it is not possible as per security reason they are not allowing but if it is possible with PlayStore and AndroidLost app then why not with us?
Please i need help if it is possible !
Thank you,