超过自己的网站主办的.apk文件 [英] Hosting an .apk file on over own site
问题描述
我的要求托管在一个公共的网站比Android市场或任何其他应用程序商店等我 .apk文件
文件。在Android Market中,后registred到市场downloded .apk文件
将自动移动,无需人工操作安装。所以,我愿意创建一个URL和主机我的 .apk文件
文件中说,想下载该 .apk文件
到Android手机,它有自动安装。
我如何能做到这一点....嘿份额如果有的话code或连接是有改编本。
{
字符串URL =http://www.server.com/yourapp.apk;
字符串PATH = Environment.getExternalStorageDirectory()+/下载/;
档案文件=新的文件(路径);
file.mkdirs();
文件OUTPUTFILE =新的文件(文件,yourapp.apk);
downloadFile(URL,OUTPUTFILE);
installApp(上下文);
}
私有静态无效downloadFile(字符串URL,文件OUTPUTFILE){
尝试 {
网址U =新的网址(URL);
URLConnection的康恩= u.openConnection();
INT CONTENTLENGTH = conn.getContentLength();
的DataInputStream流=新的DataInputStream(u.openStream());
byte []的缓冲区=新的字节[CONTENTLENGTH]
stream.readFully(缓冲液);
stream.close();
DataOutputStream类FOS =新DataOutputStream类(新的FileOutputStream(OUTPUTFILE));
fos.write(缓冲液);
fos.flush();
fos.close();
}赶上(FileNotFoundException异常E){
Log.e(FileNotFoundException异常E +);
返回;
}赶上(IOException异常E){
Log.e(IOException异常E +);
返回;
}
}
私有静态无效installApp(上下文mycontext){
意图安装=新意图();
installer.setAction(android.content.Intent.ACTION_VIEW);
字符串PATH =文件://+ Environment.getExternalStorageDirectory()+/download/yourapp.apk;
installer.setDataAndType(Uri.parse(PATH),应用程序/ vnd.android.package存档);
mycontext.startActivity(安装);
}
I got requirement to host my .apk
file on one public site other than android market or any other app stores. In android market, after registred in to the market the downloded .apk
will automatically installed on mobile without any manual action. So I am willing to create one URL and host my .apk
file in to that and want to download that .apk
in to the android mobile and it has to install automatically.
How can I do that....plz share if any code or links are there regrading this.
{
String url = "http://www.server.com/yourapp.apk";
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "yourapp.apk");
downloadFile(url, outputFile);
installApp(context);
}
private static void downloadFile(String url, File outputFile) {
try {
URL u = new URL(url);
URLConnection conn = u.openConnection();
int contentLength = conn.getContentLength();
DataInputStream stream = new DataInputStream(u.openStream());
byte[] buffer = new byte[contentLength];
stream.readFully(buffer);
stream.close();
DataOutputStream fos = new DataOutputStream(new FileOutputStream(outputFile));
fos.write(buffer);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("FileNotFoundException",e+"");
return;
} catch (IOException e) {
Log.e("IOException",e+"");
return;
}
}
private static void installApp(Context mycontext) {
Intent installer = new Intent();
installer.setAction(android.content.Intent.ACTION_VIEW);
String PATH = "file://" + Environment.getExternalStorageDirectory() + "/download/yourapp.apk";
installer.setDataAndType(Uri.parse(PATH), "application/vnd.android.package-archive");
mycontext.startActivity(installer);
}
这篇关于超过自己的网站主办的.apk文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!