Skip to content

Commit

Permalink
Seems to help the weird issue of the first ever app being installed n…
Browse files Browse the repository at this point in the history
…ot working.
  • Loading branch information
0queue committed May 2, 2017
1 parent cdd165a commit 7d0846b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/src/main/java/edu/umd/cmsc436/mstestsuite/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ public Activity getActivity() {
@Override
public void installPackage(File f) throws IOException {

if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
mInstallCache = f;
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_PERMISSION);
return;
}

FileChannel inChannel = new FileInputStream(f).getChannel();
File downloadsFolder = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);

Expand All @@ -354,13 +360,6 @@ public void installPackage(File f) throws IOException {
FileChannel outChannel = new FileOutputStream(outFile).getChannel();


if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
mInstallCache = f;
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_PERMISSION);
return;
}


try {
inChannel.transferTo(0, inChannel.size(), outChannel);
} finally {
Expand Down

0 comments on commit 7d0846b

Please sign in to comment.