ActivityNotFoundException:无活动处理意向{行为= android.intent.action.VIEW DAT =文件:///mnt/sdcard/testdata5.pdf [英] ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/testdata5.pdf

查看:686
本文介绍了ActivityNotFoundException:无活动处理意向{行为= android.intent.action.VIEW DAT =文件:///mnt/sdcard/testdata5.pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,显示从SD卡的PDF文件。本PDF文件在网络操作后创建。我收到 ActivityNotFoundException 试图通过 activity.startActivity(意向)来打开PDF文件时; 。下面是code folder_list_details.xml

 < XML版本=1.0编码=UTF-8&GT?;
    < RelativeLayout的
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
 <的ListView
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =FILL_PARENT机器人:ID =@ + ID / listV_main/>
< ImageView的
    机器人:ID =@ + ID /摄
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:paddingRight =15dp
    机器人:paddingTop =10dp/>
        < TextView的机器人:ID =@ + ID /名称
    机器人:TEXTSIZE =14sp
    机器人:TEXTSTYLE =黑体
    机器人:文字颜色=#000000
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_toRightOf =@ ID /摄/>

      < / RelativeLayout的>
 

FolderActivity.java

 公共类FolderListActivity扩展ListActivity {

公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    Log.i(FolderListActivity,的onCreate);
    FolderDisplay folderObj =新FolderDisplay(FolderListActivity.this);
    folderObj.execute((无效)NULL);
     }
    }
 

FolderDisplay.java

  @覆盖
       保护无效onPostExecute(空V){
    尝试{
                //活性FolderListActivity的一个实例
        最终的ListView LV1 = activity.getListView();
        lv1.setOnItemClickListener(新OnItemClickListener(){
            @覆盖
      公共无效onItemClick(适配器视图<>为arg0,视图V,INT位置,长的id){
            文件fil​​e = Utility.getInstance()的GetFile()。
                意向意图=新的意图(Intent.ACTION_VIEW);
                 intent.setDataAndType(Uri.fromFile(文件),应用程序/ PDF格式);
                 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  activity.startActivity(意向);
            }
        });
    }赶上(例外五){
        }
 }
 

Mainfest.xml

 < XML版本=1.0编码=UTF-8&GT?;
             <舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
           包=com.example.testlogin
           安卓版code =1
             机器人:VERSIONNAME =1.0>

      <用途-SDK
       安卓的minSdkVersion =11
     机器人:targetSdkVersion =17/>
       <使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
     <使用-权限的Andr​​oid:名称=android.permission.WRITE_EXTERNAL_STORAG​​E>
       < /使用说明 - 许可>

      <应用
    机器人:allowBackup =真
    机器人:图标=@可绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme
    机器人:可调试=真
    >
    <活动
        机器人:名称=com.example.testlogin.LoginActivity
        机器人:标签=@字符串/ APP_NAME
        机器人:windowSoftInputMode =adjustResize | stateVisible>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>

            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
      < /活性GT;
        <活动
        机器人:名称=com.example.testlogin.RepoListActivity
        机器人:标签=@字符串/ title_activity_repo_list>
       < /活性GT;
       <活动
        机器人:名称=com.example.testlogin.FolderListActivity
        机器人:标签=@字符串/ title_activity_folder_list>
      < /活性GT;
     < /用途>

     < /舱单>
 

错误我收到

  android.content.ActivityNotFoundException:无活动处理意向{行为= android.intent.action.VIEW DAT =文件:///mnt/sdcard/Alfdata/testdata5.pdf (典型值)=应用程序/ PDF FLG = 0x4000000}
 

解决方案

这是因为你的设备或仿真器没有能够查看本地PDF文件的应用程序。

I have a requirement to display pdf file from SD card. This pdf file is created after a network operation. I'm getting ActivityNotFoundException when trying to open pdf through activity.startActivity(intent); . Below is code folder_list_details.xml

  <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
 <ListView 
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" android:id="@+id/listV_main"/>
<ImageView 
    android:id="@+id/photo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="15dp"
    android:paddingTop="10dp" />
        <TextView android:id="@+id/name"
    android:textSize="14sp" 
    android:textStyle="bold" 
    android:textColor="#000000" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/photo"/>

      </RelativeLayout>

FolderActivity.java

    public class FolderListActivity extends ListActivity{

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i("FolderListActivity", "onCreate" );
    FolderDisplay folderObj = new FolderDisplay(FolderListActivity.this);
    folderObj.execute((Void) null);
     }
    } 

FolderDisplay.java :

     @Override
       protected void onPostExecute(Void v) {
    try{
                //activity is an  instance of FolderListActivity
        final ListView lv1 =activity.getListView(); 
        lv1.setOnItemClickListener(new OnItemClickListener() {
            @Override
      public void onItemClick(AdapterView<?> arg0, View v, int position,long id) {                           
            File file =Utility.getInstance().getFile();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                 intent.setDataAndType(Uri.fromFile(file), "application/pdf");
                 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  activity.startActivity(intent);
            }  
        });
    }catch(Exception e){
        }
 }

Mainfest.xml

                  <?xml version="1.0" encoding="utf-8"?>
             <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="com.example.testlogin"
           android:versionCode="1"
             android:versionName="1.0" >

      <uses-sdk
       android:minSdkVersion="11"
     android:targetSdkVersion="17" />
       <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
       </uses-  permission>

      <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
    android:debuggable="true"
    >
    <activity
        android:name="com.example.testlogin.LoginActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustResize|stateVisible" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
        <activity
        android:name="com.example.testlogin.RepoListActivity"
        android:label="@string/title_activity_repo_list" >
       </activity>
       <activity
        android:name="com.example.testlogin.FolderListActivity"
        android:label="@string/title_activity_folder_list" >
      </activity>
     </application>

     </manifest>

Error I'm getting

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/Alfdata/testdata5.pdf typ=application/pdf flg=0x4000000 }

解决方案

That is because your device or emulator does not have an application capable of viewing a local PDF file.

这篇关于ActivityNotFoundException:无活动处理意向{行为= android.intent.action.VIEW DAT =文件:///mnt/sdcard/testdata5.pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆