Android 从远程服务器安装apk
当用户点击url链接时,我想从服务器安装apk文件 请指导我如何在网上搜索我没有得到相应的信息 提前谢谢Android 从远程服务器安装apk,android,Android,当用户点击url链接时,我想从服务器安装apk文件 请指导我如何在网上搜索我没有得到相应的信息 提前谢谢 Aswan您不能强制安装APK 如果是这样,任何人都可以在某些服务器上隐藏病毒或间谍软件,当用户单击链接时,它会自动安装 只需将要安装的apk文件放在服务器上,并让超链接指向它。。。就像压缩档案、电影或其他可执行文件一样 浏览器只需下载并安装apk(如果用户需要)。用户当然需要在其设置中激活非市场应用程序。。。(如上链接所述) 我希望这对您有所帮助…这是我使用的代码,它不适用于webview
Aswan您不能强制安装APK 如果是这样,任何人都可以在某些服务器上隐藏病毒或间谍软件,当用户单击链接时,它会自动安装 只需将要安装的apk文件放在服务器上,并让超链接指向它。。。就像压缩档案、电影或其他可执行文件一样 浏览器只需下载并安装apk(如果用户需要)。用户当然需要在其设置中激活非市场应用程序。。。(如上链接所述)
我希望这对您有所帮助…这是我使用的代码,它不适用于webview,但您可以轻松地覆盖url加载并以任何方式应用此代码。。 底部的意图就是你问题的答案
/**
* Main
* When started, will download latest version of AN APPLICATIONand launch an install
* Is just a dialog
*
* REQUIRES SDCARD
* @author Dag
*
*/
public class Main extends Activity {
ProgressDialog dlDialog;
String path = Environment.getExternalStorageDirectory()+ "/"; // Path to where you want to save the file
String inet = "http://www.google.com/test.apk"; // Internet path to the file
String cachedir = "";
String filename = "TMC.apk";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView webview = new TextView(this);
setContentView(webview);
File getcache = this.getCacheDir();
cachedir = getcache.getAbsolutePath();
dlDialog = new ProgressDialog(Main.this);
dlDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dlDialog.setTitle("Downloadin");
dlDialog.setMessage("Connecting");
dlDialog.show();
new Thread(new Runnable() {
public void run() {
String filePath = path;
InputStream is = null;
OutputStream os = null;
URLConnection URLConn = null;
try {
URL fileUrl;
byte[] buf;
int ByteRead = 0;
int ByteWritten = 0;
fileUrl = new URL(inet);
URLConn = fileUrl.openConnection();
is = URLConn.getInputStream();
String fileName = inet.substring(inet.lastIndexOf("/") + 1);
File f = new File(filePath);
f.mkdirs();
String abs = filePath + fileName;
f = new File(abs);
os = new BufferedOutputStream(new FileOutputStream(abs));
buf = new byte[1024];
/*
* This loop reads the bytes and updates a progressdialog
*/
while ((ByteRead = is.read(buf)) != -1) {
os.write(buf, 0, ByteRead);
ByteWritten += ByteRead;
final int tmpWritten = ByteWritten;
runOnUiThread(new Runnable() {
public void run() {
dlDialog.setMessage(""+tmpWritten+" Bytes");
}
});
}
runOnUiThread(new Runnable() {
public void run() {
dlDialog.setTitle("Startar");
}
});
is.close();
os.flush();
os.close();
Thread.sleep(200);
dlDialog.dismiss();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(abs)),
"application/vnd.android.package-archive");
startActivity(intent);
finish();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}
谢谢shay。但是我想从远程服务器安装。你能详细解释一下吗?这是怎么回事,只要给用户一个指向远程url的链接,点击它就可以安装应用程序。你好,阿斯旺,我也想安装android应用程序,而不必从我自己的服务器下载。您找到解决方案了吗?我不想将APK存储在设备或SD卡中的任何位置。我想直接从我的服务器上安装apk。请稍后删除apk,否则此方法不适用于您。