我试过文本(* .txt)文件打印它的工作正常但是当我尝试HWML文件时它无法正常工作。这是我的代码。
Home.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);
}
});
}
}
答案 0 :(得分:1)
你直接传递图片不需要html文字。尝试以下代码:
Intent intent = new Intent ("org.androidprinting.intent.action.PRINT");
intent.setDataAndType( Uri.fromFile(new File("assets/subba.jpg"), "image/jpeg" );
startActivity(intent);