Android Load and run apk file on sdcard - android

I have found that some app can load a third part app exist in sdcart just decompression the apk file and run... but I can not finger out how to ...
some body know and give me a help? thanks...

you can install and run the .apk file from your application like below
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
you can fine more information on this in the following link. http://www.anddev.org/viewtopic.php?p=23928 and automatic install of apk

Related

How to run install app in internal files dir?

I have some lines of code and apk file in internal cache dir:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(newFile(context.getCacheDir() + "/update.apk")), "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
But I had a parsing error: "There was a problem parsing the package"
Thank You for helping!
Third-party apps, including the package installer, have no access rights to that file.
On Android N, they have finally fixed the problem with installing apps via a ContentProvider, like FileProvider. For versions prior to that, you can install from external storage, or maybe use MODE_WORLD_READABLE (deprecated, and banned on Android N) to allow that file to be read from internal storage.

How to install application directly to device from web

I have one server, and on that server I have uploaded one apk file. There is a button on my webpage that, when clicked, the application should be directly installed to device instead of being downloaded to local storage.
I need same functionality like we install apps from google play store.
If any one knows this, then it will be appreciated.
I have not found any solutions of this through google.
Thanks.
This is not possible. Fortunately. Imagine the security breach this would be. Any Website could force install apps. This would open the doors for any kind of Virus.
You cannot do that as our friends advised you. I have tried by these ways for installing APK from my own server
You can download the APK from the server and save it in some folder
Add permission in manifest
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Use this demo code for downloading and installing the APK
Downloading APK from server
String PATH = Environment.getExternalStorageDirectory()+ "/yourpath/";
File file = new File(PATH);
if (!file.exists()) {
file.mkdirs();
}
File outputFile = new File(file,
"your.apk");
if (outputFile.exists()) {
outputFile.delete();
}
FileOutputStream fileOuputStream = new FileOutputStream(
outputFile);
fileOuputStream.write(bResponse);
fileOuputStream.close();
Installation of APK after Download completes
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment
.getExternalStorageDirectory()+ "/your path/"+ "yourapkname.apk")),
"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
3.After Installation you can delete the APK from folder location
Any third party cannot install the application of their own on the Android Device directly. Otherwise they need some root permission that should be declared in device Kernel. Google Play can directly install by sending commands to Play Store to install the particular app as Google is in fact the owner of Android and indirectly Device Administrator which have full access to your device kernel.

Programmatically install Android Applications

I have the following problem:
As described at Android: install .apk programmatically, I install an APK file successfully on an Android device. Unfortunately I have the problem that when I try to install a second APK file, get the message: Package not installed.
In the debugger I see:
Asset path / sdcard / myAPK.apk
neither directory nor file
This may help you:
protected void installApkfile(String apkFileName) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(
new File(Environment.getExternalStorageDirectory() + "/download/"
+ apkFileName)), "application/vnd.android.package-archive");
startActivityForResult(intent,0);
}
Here my .apk file is in sd card download folder.
If by "asset path" you really mean that the APK is packaged as an asset, that will not work. The APK must be an actual file on the filesystem, and an asset remains packaged inside of its hosting APK. See: Can We Install an APK From a ContentProvider?

Parse Error - Installing apk programmatically

I am trying to install an apk file programmatically. I referred this site for doing it.
Now the apk file is downloaded from an url and placed in SDCard. When I try to install it on the device using Intent method,
It is popping up following error
Emulator:
"Parse Error - There is a problem parsing the package",
Logcat(W) : "Unable to read AndroidManifest.xml of /mnt/sdcard/download/myapp.apk",
Logcat(W) : "java.ioException: AndroidManifest.xml",
Logcat(W) : "Parse error when parsing manifest. Discontinuing installation".
Logcat(E) : "java.lang.SecurityException",
Logcat(E) : "java.lang.NullPointerException".
Note: 1) I was able to install the same .apk file using adb.
2) I changed this .apk file to .pdf format before sending it to Server Team and then they changed it back to .apk. I am adding this coz there might be chances for error due to format conversion.
Installation can give the specified error at least in following cases:
Name of the package is changed after signing: Use the exact name as
the signed package is (instead, adjust the name in Manifest)
Package is compiled against on higher API level: Correct the API
level in Manifest file
Package is executed from SD-card: Run (install) the apk -file
from phones memory OR use adb command to install it
Please check this code
private void installApk(){
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File("/sdcard/path"));
intent.setDataAndType(uri, "application/vnd.android.package-archive");
startActivity(intent);}

Launching The package installer

I'm looking for a way to automatically start the android Package Installer , after the browser finishes downloading an apk file . Any ideas on this ? Currently after the download is over the list of downloaded files is displayed and clicking on the downloaded apk launches the Package installer . (step which I'd like to automatize)
I've thought on launching the instalation manually with code like this :
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file:///sdcard/downloadedApk"),
"application/vnd.android.package-archive");
startActivity(intent);
,but I'm unable to find when the download completes to execute the snipet above.
You cannot "automatically start the android Package Installer , after the browser finishes downloading an apk file" -- sorry!
Uri uri = Uri.fromParts ( "package", "abc", null);
rtn = new Intent (Intent.ACTION_PACKAGE_ADDED, uri);

Categories

Resources