Reputation: 181
I'm using basically the same code as Android: install .apk programmatically. The app launches the new intent, but nothing happens. The APK is getting pulled down from our servers (internal application not on Play store), but the install prompt never appears as it would if I navigate to the downloads folder and manually click on the APK. Does it have anything to do with the fact that I placed the intent filters on the .Main activity?
Here's my code
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());
}
}`
And here is my 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>`
Upvotes: 0
Views: 5537
Reputation: 181
I figured it out...misspelled android in -"application/vnd.andriod.package-archive"
Upvotes: 1