1

我尝试了 text(*.txt) 文件打印它的工作良好,但是当我尝试 HWML 文件时它不起作用。这是我的代码。

主页.java

public class Home extends Activity{

    private static final String FileName = "file.html";

    Button button1;

    final File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), FileName);

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);

        button1 = (Button) findViewById(R.id.button1);
        button1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Uri uri = Uri.fromFile( file );
                Intent intent = new Intent ("org.androidprinting.intent.action.PRINT");
                intent.setDataAndType( uri, "text/html" );
                startActivity(intent);
                //startActivityForResult(intent, 0);

            }
        });      

    }
}
4

1 回答 1

1

您直接传递图像不需要html文本。试试下面的代码:

Intent intent = new Intent ("org.androidprinting.intent.action.PRINT");
intent.setDataAndType( Uri.fromFile(new File("assets/subba.jpg"), "image/jpeg" );
startActivity(intent);
于 2014-04-03T11:51:49.057 回答