运用指定的程序打开指定的文件 Android

     

       String path = "sdcard/CourseWare/study/test01.epub";//指定的文件位置 

      Intent intent = new Intent(Intent.ACTION_VIEW); 

      intent.addCategory(Intent.CATEGORY_DEFAULT); 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK ); 
        Uri uri = Uri.fromFile(new File(path)); 
        intent.setDataAndType(uri, "application/epub"); //用其他程序时更改epub
        ComponentName app1 = new ComponentName("cn.cidtech.reader", "cn.cidtech.reader.run.CoursewareReader");//指定的程序包名和文件名
        intent.setComponent(app); 

        startActivity(intent);

 

调用指定的程序不指定的文件时可用:

 

Intent intent = new Intent();

String pName = "cn.cidtech.reader";//程序包名
String cName = "cn.cidtech.reader.run.CoursewareReader";//程序文件名
intent.putExtra("BookPath",path);
intent.setClassName(pName, cName);
startActivity(intent);

或者

Intent intent = new Intent();
        ComponentName component = new ComponentName("cn.cidtech.reader", "cn.cidtech.reader.run.CoursewareReader" );
        intent.setComponent(component);
        startActivity(intent);

posted @ 2012-10-09 15:29  战地伯爵  阅读(373)  评论(0编辑  收藏  举报