2010-10-17 29 views
0

当用户点击url链接我想从服务器安装apk文件。从远程服务器安装apk文件

请指导我怎么做我搜索的净我没有得到事先

相应的信息

感谢阿斯旺

+0

嗨阿斯旺,我也想安装android应用程序,而无需从我自己的服务器下载。你找到解决方案吗? – Manoj 2012-10-27 06:41:59

回答

4
+0

thankq shay。但我想从远程server.can u pl安装解释详细 – Aswan 2010-10-17 12:01:58

+1

这是如何,只要给用户链接到远程URL点击它将安装应用程序。 – 2010-10-17 12:04:54

2

你不能强迫要安装的APK。 ..

如果是这样,任何人都可以在某些服务器上隐藏病毒或间谍软件,并且当用户点击链接时,自动安装...

简单地把你想要安装在你的服务器上的apk文件,让超链接指向它...就像一个zip档案,电影或其他可执行文件。

浏览器只需下载apk并安装它(如果用户需要的话)。当然,用户需要激活非市场的应用程序在其设置...

我希望这可以帮助你(在上面的链接描述)......

3

这是我使用的代码,它是不是为web视图,但你可以轻松地覆盖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(); 

} 
} 
+0

我不想在设备或SD卡中的任何位置存储APK。我想直接从我的服务器安装apk。 – 2015-04-06 12:21:47

+0

之后删除APK,否则此方法不适合您。 – DagW 2015-04-09 12:47:38