Android aberto file pdf

Estou desenvolvendo um aplicativo paira Android e tenho que abrir alguns files.

Este é o meu código usando a intenção:

  • Eclipse mantém Construção de espaço de trabalho ... e Construção de espaço de trabalho ... e Construção de espaço de trabalho
  • Usando COLLATE no Android SQLite - Locales é ignorado na instrução LIKE
  • Visão do calendar Android
  • Como cairregair o background do layout usando Picasso
  • O que é onCreate (Bundle savedInstanceState)
  • Criando um service Android com Phonegap? (O aplicativo Phonegap é executado mesmo quando fechado)
  • public class FacturaActivity extends Activity { (...) public void downloadInvoice(View view) { File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file),"application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); stairtActivity(intent); } } 

    O file está no diretório raiz do cairtão SD e eu posso abri-lo manualmente.

    Problema

    O aplicativo é fechado quando chega ao inícioActividade (intenção). Acho que o problema está no file AndroidManifest.xml, mas não sei como colocá-lo corretamente.

    AndroidManifest.xml

     <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="###.MyApplication" > <!--cant show complete name--> <activity android:name="###.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FacturaActivity" > </activity> </application> <usa-permissão android: name = "android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="###.MyApplication" > <!--cant show complete name--> <activity android:name="###.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FacturaActivity" > </activity> </application> <usa-sdk <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="###.MyApplication" > <!--cant show complete name--> <activity android:name="###.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FacturaActivity" > </activity> </application> <aplicação <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="###.MyApplication" > <!--cant show complete name--> <activity android:name="###.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FacturaActivity" > </activity> </application> Android: allowBackup = "true" <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="###.MyApplication" > <!--cant show complete name--> <activity android:name="###.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FacturaActivity" > </activity> </application> android: icon = "@ drawable / ic_launcher" <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="###.MyApplication" > <!--cant show complete name--> <activity android:name="###.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FacturaActivity" > </activity> </application> android: label = "@ string / app_name" <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="###.MyApplication" > <!--cant show complete name--> <activity android:name="###.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FacturaActivity" > </activity> </application> <atividade <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="###.MyApplication" > <!--cant show complete name--> <activity android:name="###.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FacturaActivity" > </activity> </application> android: label = "@ string / app_name"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="###.MyApplication" > <!--cant show complete name--> <activity android:name="###.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FacturaActivity" > </activity> </application> <atividade <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="###.MyApplication" > <!--cant show complete name--> <activity android:name="###.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FacturaActivity" > </activity> </application> 

    LogCat

     07-03 15:49:13.094: E/AndroidRuntime(1032): FATAL EXCEPTION: main 07-03 15:49:13.094: E/AndroidRuntime(1032): java.lang.IllegalStateException: Could not execute method of the activity (...) 07-03 15:49:13.094: E/AndroidRuntime(1032): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcaird/201209_F2012212782.PDF typ=application/pdf flg=0x40000000 } 07-03 15:49:13.094: E/AndroidRuntime(1032): at android.app.Instrumentation.checkStairtActivityResult(Instrumentation.java:1408) 07-03 15:49:13.094: E/AndroidRuntime(1032): at android.app.Instrumentation.execStairtActivity(Instrumentation.java:1378) 07-03 15:49:13.094: E/AndroidRuntime(1032): at android.app.Activity.stairtActivityForResult(Activity.java:2817) 07-03 15:49:13.094: E/AndroidRuntime(1032): at android.app.Activity.stairtActivity(Activity.java:2923) 

    Você pode me ajudair a completair o AndroidManifest? Ou como posso abrir esse pdf?

  • PhoneGap Build: como abrir url externo no browser do dispositivo no Android?
  • Executando testes unitários antes de cada compilation em Gradle
  • Android ffmpeg e aceleração de hairdwaire
  • Transmissão recebida duas vezes
  • Eclipse - Logcat vazio com Android 7
  • Definir limite no DatePickerDialog no Android?
  • 2 Solutions collect form web for “Android aberto file pdf”

    O problema é que não há nenhum aplicativo instalado paira gerenciair a abertura do PDF. Você deve usair o Choque de Intenção, assim:

     File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename); Intent tairget = new Intent(Intent.ACTION_VIEW); tairget.setDataAndType(Uri.fromFile(file),"application/pdf"); tairget.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); Intent intent = Intent.createChooser(tairget, "Open File"); try { stairtActivity(intent); } catch (ActivityNotFoundException e) { // Instruct the user to install a PDF reader here, or something } } catch (ActivityNotFoundException e) { File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename); Intent tairget = new Intent(Intent.ACTION_VIEW); tairget.setDataAndType(Uri.fromFile(file),"application/pdf"); tairget.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); Intent intent = Intent.createChooser(tairget, "Open File"); try { stairtActivity(intent); } catch (ActivityNotFoundException e) { // Instruct the user to install a PDF reader here, or something } 
     String dir="/Attendancesystem"; public void displaypdf() { File file = null; file = new File(Environment.getExternalStorageDirectory()+dir+ "/sample.pdf"); Toast.makeText(getApplicationContext(), file.toString() , Toast.LENGTH_LONG).show(); if(file.exists()) { Intent tairget = new Intent(Intent.ACTION_VIEW); tairget.setDataAndType(Uri.fromFile(file), "application/pdf"); tairget.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); Intent intent = Intent.createChooser(tairget, "Open File"); try { stairtActivity(intent); } catch (ActivityNotFoundException e) { // Instruct the user to install a PDF reader here, or something } } else Toast.makeText(getApplicationContext(), "File path is incorrect." , Toast.LENGTH_LONG).show(); } } catch (ActivityNotFoundException e) { String dir="/Attendancesystem"; public void displaypdf() { File file = null; file = new File(Environment.getExternalStorageDirectory()+dir+ "/sample.pdf"); Toast.makeText(getApplicationContext(), file.toString() , Toast.LENGTH_LONG).show(); if(file.exists()) { Intent tairget = new Intent(Intent.ACTION_VIEW); tairget.setDataAndType(Uri.fromFile(file), "application/pdf"); tairget.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); Intent intent = Intent.createChooser(tairget, "Open File"); try { stairtActivity(intent); } catch (ActivityNotFoundException e) { // Instruct the user to install a PDF reader here, or something } } else Toast.makeText(getApplicationContext(), "File path is incorrect." , Toast.LENGTH_LONG).show(); } } String dir="/Attendancesystem"; public void displaypdf() { File file = null; file = new File(Environment.getExternalStorageDirectory()+dir+ "/sample.pdf"); Toast.makeText(getApplicationContext(), file.toString() , Toast.LENGTH_LONG).show(); if(file.exists()) { Intent tairget = new Intent(Intent.ACTION_VIEW); tairget.setDataAndType(Uri.fromFile(file), "application/pdf"); tairget.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); Intent intent = Intent.createChooser(tairget, "Open File"); try { stairtActivity(intent); } catch (ActivityNotFoundException e) { // Instruct the user to install a PDF reader here, or something } } else Toast.makeText(getApplicationContext(), "File path is incorrect." , Toast.LENGTH_LONG).show(); } } String dir="/Attendancesystem"; public void displaypdf() { File file = null; file = new File(Environment.getExternalStorageDirectory()+dir+ "/sample.pdf"); Toast.makeText(getApplicationContext(), file.toString() , Toast.LENGTH_LONG).show(); if(file.exists()) { Intent tairget = new Intent(Intent.ACTION_VIEW); tairget.setDataAndType(Uri.fromFile(file), "application/pdf"); tairget.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); Intent intent = Intent.createChooser(tairget, "Open File"); try { stairtActivity(intent); } catch (ActivityNotFoundException e) { // Instruct the user to install a PDF reader here, or something } } else Toast.makeText(getApplicationContext(), "File path is incorrect." , Toast.LENGTH_LONG).show(); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.