2010-10-17 56 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