2014-09-09 23 views
0

Я использую в основном тот же код, что и Android: install .apk programmatically. Приложение запускает новое намерение, но ничего не происходит. APK сбрасывается с наших серверов (внутреннее приложение не в Play Store), но приглашение на установку никогда не появляется, как если бы я перешел к папке загрузки и вручную щелкнул APK. Имеет ли это какое-либо отношение к тому факту, что я поместил фильтры намерения в .Main?Установка APK программно

Вот мой код

 StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
     StrictMode.setThreadPolicy(policy); 

     URL url = new URL("http://ourURL/app.apk"); 

     HttpURLConnection c = (HttpURLConnection) url.openConnection(); 
     c.setRequestMethod("GET"); 
     c.connect(); 

     String PATH = Environment.getExternalStorageDirectory() + "/Download/"; 
     File file = new File(PATH); 
     file.mkdirs(); 
     File outputFile = new File(file, "app.apk"); 
     FileOutputStream fos = new FileOutputStream(outputFile); 

     is = c.getInputStream(); 

     byte[] buffer = new byte[1024]; 
     int len1 = 0; 
     while ((len1 = is.read(buffer)) != -1) { 
      fos.write(buffer, 0, len1); 
     } 
     fos.close(); 
     is.close(); 




     Intent promptInstall = new Intent(Intent.ACTION_VIEW); 
       promptInstall.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/Download/" + "app.apk")), "application/vnd.andriod.package-archive"); 
       promptInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 



     startActivity(promptInstall); 

    } catch (IOException e) { 
     Toast.makeText(getApplicationContext(), "Update error!" + e.toString() + e.getStackTrace().toString(), Toast.LENGTH_LONG).show(); 
     TextView txtQuestion = (TextView) findViewById(R.id.txtViewQuestion); 
     txtQuestion.setText(e.toString()); 
    } 
}` 

А вот мой Manifest `

<application 
    android:allowBackup="true" 
    android:icon="@drawable/bancsource" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".MainActivity" 
     android:configChanges="orientation" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW"/> 
      <category android:name="android.intent.category.DEFAULT"/> 
      <category android:name="android.intent.category.LAUNCHER"/> 
      <category android:name="android.intent.category.OPENABLE"/> 
      <category android:name="android.intent.category.BROWSABLE"/> 
      <data android:path="@string/updatePath"/> 
      <data android:mimeType="application/vnd.andriod.package-archive"/> 


     </intent-filter> 
    </activity>` 
+0

добавить разрешение для манифестации:

+0

У меня есть все эти разрешения. Извините, я не включил их в свой пример кода. – JMoney

ответ

1

я понял это ... опечатка андроида в -" приложения/vnd.andriod. пакет-архив "

Смежные вопросы