Erro Abrir PDF Pasta assets

0 respostas
marcio_fire

Boa tarde,

Estou salvando um arquivo PDF na pasta assets do projeto, porém depois que eu inslado o APK no celular
mostra a mensagem "Ele não existe ou não pode ser lido".

Alguem sabe como resolver esta zica?
public void AbrirPDF(){
        //File file = new File("/sdcard/teste.pdf"); //Funciona se o arquivo estiver no SDCARD do aparelho
        //File file = new File("/assets/teste.pdf"); //não funciona
        //File file = new File("file:///assets/teste.pdf"); //não funciona
            //File file = new File("content://br.com.pacote/assets/teste.pdf"); //não funciona
        
        
        

            File file = new File("file:///android_asset/teste.pdf"); 
        try {
                
                    Uri path = Uri.fromFile(file);
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setDataAndType(path, "application/pdf");
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        
                    try {
                        startActivity(intent);
                    } 
                    catch (ActivityNotFoundException e) {
                        Toast.makeText(PrincipalActivity.this, 
                                "Não existe este arquivo para visualisar em PDF", 
                                Toast.LENGTH_SHORT).show();
                    }
                
                
        }catch(Exception erro){
            exibirMensagem("Erro", 
                    "Não foi possivel carregar o pdf " + erro.getMessage());
        }
    }
Criado 9 de agosto de 2012
Respostas 0
Participantes 1