2014-02-22 5 views
0

ListView을 작성하여 각 항목에 안드로이드 앱 내에있는 assets/PDFS 폴더에있는 특정 .pdf 파일을 열어 보겠습니다. 다음 코드는 오류는 발생시키지 않지만 파일을 열지는 않습니다. 누군가 해결책을 공유 할 수 있습니까? 나는 당신이 다른 응용 프로그램에서 자산 파일을 열 수 없습니다 조각pdf는 목록보기에서 assets 폴더에 저장됩니다.

public class FreshFragment extends Fragment implements OnItemClickListener { 

    ListView lv; 
    String[] titles; 

    public FreshFragment() { 

    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     View V = inflater.inflate(R.layout.fragment_fresh, container, false); 


     lv = (ListView)V.findViewById(android.R.id.list); 
     lv.setOnItemClickListener(this); 

     return V; 
    } 

    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

     switch (position) { 
     case 0: 
      File pdfFile = new File("res/assets/peedee.pdf"); 
      Uri path = Uri.fromFile(pdfFile); 
      Intent intent = new Intent(Intent.ACTION_VIEW); 
      intent.setDataAndType(path, "application/pdf"); 
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      break; 

     } 
    } 
} 

답변

0

사용하고

참고. 두 앱 모두 외부 저장소와 같이 먼저 읽을 수있는 디스크에 저장해야합니다.

+0

하나의 응용 프로그램 만 pdf 파일에 액세스합니다 ... pdfs가 – LimpLimp

+0

에 저장되어있는 경우 잘못된 유형의 인 텐트가 사용됩니다. pdfs를 읽을 수 있다고 선언 한 응용 프로그램을 찾을 행동보기 의도를하지 마십시오. 실행할 특정 활동에 대한 의도를 작성하고 파일 이름을 의도 된대로 전달하십시오. –

관련 문제