Launching The package installer - android

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);

Related

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.

Phonegap how to download and open pdf file in android app

recently i am working on a android apps build in phonegap, i am quite new with mobile development and this i smy first appsbut, and i am stuck when try to download some documents (pdf, doc, jpg) to local storage and open it, after search through google and i tried to follow this solution.
I followed the exact code in the example and below is how i call the plugins:
window.plugins.downloader.downloadFile(url,'/sdcard/download/', 'test.pdf', true, downloadOkCallbak, downloadErCallbak);
window.plugins.pdfViewer.showPdf('/sdcard/download/test.pdf');
The url is my remote file, when i execute it, i got error: "TypeError: window.plugins is undefined". Anyone help is appreciated.
[update] My code of showPdf function:
public String showPdf(String fileName) {
File file = new File(fileName);
if (file.exists()) {
try {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//intent.setData(Uri.parse(fileName));
this.ctx.startActivity(intent);
return "";
} catch (android.content.ActivityNotFoundException e) {
System.out.println("PdfViewer: Error loading url "+fileName+":"+ e.toString());
return e.toString();
}
}else{
return "file not found";
}
}
[Update 2] I got below error in web console: Uncaught ReferrenceError: LocalFileSystem is not defined at ...
What could be the issue?
I had the same problem as the OP and many unsuccessful approaches later I came to the following solution (tested with Cordova 3.1.0-3.3.0 & Samsung Galaxy S3 & iOS 7):
Solution
First, get the file by requesting the file system and then download it from your server with fileTransfer.download(). After completing the download call the FileOpener (which will open a pop up where to choose from apps like Adobe Reader). Note: Make sure to include the FileTransfer feature via CLI/Terminal: cordova plugin add org.apache.cordova.file
Navigate to your project folder
Open CLI/Terminal and type in: cordova plugin add https://github.com/don/FileOpener.git
After successful download and storage of your file on the device (see above) you open it with: window.plugins.fileOpener.open("file:///sdcard/Android/data/com.example.application/document.doc") or the appropriate path on iOS.
That's it! Good luck!
Make sure you've had these lines in your manifest.xml :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
You can find help here How to download a pdf file in Android?
Make sure
You should install git and install file plugins(cordova 3.0+)
File and file transfer plugin
$ cordova plugin add org.apache.cordova.file
$ cordova plugin add org.apache.cordova.file-transfer
Ps. Try plugin fileOpener2
https://build.phonegap.com/plugins/1117
Try this to open any kind of documents from URL using following steps:
install this plugin : cordova plugin add https://github.com/ti8m/DocumentHandler
use this code :
handleDocumentWithURL(function() { console.log('success'); }, function(error) { console.log('failure'); if (error == 53) { console.log('No app that handles this file type.'); } }, 'http://www.example.com/path/to/document.pdf');
It works for me both on Android and IOS. I used it for open images and PDF files.
Android : It opens files using system apps if available, otherwise it give an error, which you can handle.
IOS : It opens files in popup like view with Done button and Option button.
It doesn't show your docs URL.
Source is available here : https://github.com/ti8m/DocumentHandler

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);}

Android Load and run apk file on sdcard

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

Categories

Resources