我需要显示 SD 卡中的 pdf 文件。此 pdf 文件是在网络操作后创建的。我ActivityNotFoundException
在尝试通过activity.startActivity(intent);
. 下面是代码
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>
文件夹活动.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);
}
}
文件夹显示.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>
我得到的错误
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 }