Frage

I tried for text(*.txt) file print its working good but when I try for HWML file its not working. Here is my code.

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);

            }
        });      

    }
}
War es hilfreich?

Lösung

you directly pass image don't need to html text. try below code:

Intent intent = new Intent ("org.androidprinting.intent.action.PRINT");
intent.setDataAndType( Uri.fromFile(new File("assets/subba.jpg"), "image/jpeg" );
startActivity(intent);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top