Joe
Joe

Reputation: 834

apk installation via my application

i get parse error once i use my function below

public void installFile()
{
    String path = "/data/data/com.utsc.smartdictate/";
    String filename = "smartdictate.apk";
    File file = new File(path + filename);
    if(file.exists())
    {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        startActivity(intent);
    }
}

i tried pulling the apk file from the emulator and tried installing it, to test if the file was corrupted or not, however it installed! so i dont know why it is failing.

EDIT: i have "android.permission.INSTALL_PACKAGES" permission added in the manifest

Upvotes: 2

Views: 261

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007584

Most likely, the file is not readable by the installer. Files in your application-local file store are not readable by other processes by default. You will need to either store the file on external storage, or create your file use openFileOutput() and MODE_WORLD_READABLE, or create a content provider to serve that file.

Also:

  • Never hardwire a path. Use getFilesDir() to get the root of your application-local file store
  • Do not store files in /data/data/com.utsc.smartdictate/, but in /data/data/com.utsc.smartdictate/files, which is what you will get from getFilesDir()
  • Do not concatenate strings to get a complete path -- use the proper File constructor instead

Upvotes: 2

Related Questions