Java 需要Android程序连接到wifi打印机并实际打印内容
我有一个使用asp web服务的Android程序。现在,我想让我的Android程序连接到wifi打印机,打印它从web服务中使用的内容。我不知道从哪里开始,使用什么资源Java 需要Android程序连接到wifi打印机并实际打印内容,java,android,printing,wifi,Java,Android,Printing,Wifi,我有一个使用asp web服务的Android程序。现在,我想让我的Android程序连接到wifi打印机,打印它从web服务中使用的内容。我不知道从哪里开始,使用什么资源 任何帮助都将不胜感激。我将从查看文档开始 然后,您必须了解“打印机端”协议(我假设您正在与特定的供应商合作,对吗?)要向其发送哪些确切数据(以及如何发送) 我不确定是否所有wifi打印机都共享相同的API,这取决于您的检查我将从查看文档开始 然后,您必须了解“打印机端”协议(我假设您正在与特定的供应商合作,对吗?)要向其发送
任何帮助都将不胜感激。我将从查看文档开始
然后,您必须了解“打印机端”协议(我假设您正在与特定的供应商合作,对吗?)
要向其发送哪些确切数据(以及如何发送)
我不确定是否所有wifi打印机都共享相同的API,这取决于您的检查
我将从查看文档开始
然后,您必须了解“打印机端”协议(我假设您正在与特定的供应商合作,对吗?)
要向其发送哪些确切数据(以及如何发送)
我不确定是否所有wifi打印机都共享相同的API,这取决于您的检查
我使用以下代码打印
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import com.iPrint.iObject;
import com.iPrint.iPaperType;
import com.iPrint.iPrint;
import com.iPrint.iPrinters;
import com.iPrint.iSettings;
import com.iPrint.ipConnection;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iSettings set = new iSettings();
set.SetPaperType(iPaperType.LETTER);
set.PrinterType(iPrinters.HP);
//Creating Connection object
ipConnection wfc = new ipConnection();
wfc.ipAddress("IP-Address");
wfc.Port(port-number);
try {
wfc.Connect();
Log.e("Connected", wfc.isConnected()+"");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("In Error", "In Error");
e.printStackTrace();
}
//Creating a Printing object
iPrint p = new iPrint(getApplicationContext());
p.Connection(wfc);
p.Settings(set);
if (wfc.isConnected())
{
p.Start();
iObject ob = new iObject();
ob.Text("Hello iPrint!");
p.Add(ob);
p.End();
p.Print();
ob = null;
}
else
{
Log.v("Error",wfc.ErrorMessage()+"");
//showDialog(wfc.ErrorMessage(), AppContext);
}
print(getApplicationContext());
}
private void print(Context AppContext)
{
//Creating Settings object
iSettings set = new iSettings();
set.SetPaperType(iPaperType.LETTER);
set.PrinterType(iPrinters.HP);
//Creating Connection object
ipConnection wfc = new ipConnection();
wfc.ipAddress("ip-address");
wfc.Port(port-number);
try {
wfc.Connect();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("In Error", "In Error");
e.printStackTrace();
}
//Creating a Printing object
iPrint p = new iPrint(AppContext);
p.Connection(wfc);
p.Settings(set);
if (wfc.isConnected())
{
p.Start();
iObject ob = new iObject();
ob.Text("Hello iPrint!");
p.Add(ob);
p.End();
p.Print();
ob = null;
}
else
{
Log.v("Error",wfc.ErrorMessage()+"");
}
set = null;
wfc = null;
p = null;
}
}
添加
iprint.jar
,我已经这样做了。我使用了以下代码来打印
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import com.iPrint.iObject;
import com.iPrint.iPaperType;
import com.iPrint.iPrint;
import com.iPrint.iPrinters;
import com.iPrint.iSettings;
import com.iPrint.ipConnection;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iSettings set = new iSettings();
set.SetPaperType(iPaperType.LETTER);
set.PrinterType(iPrinters.HP);
//Creating Connection object
ipConnection wfc = new ipConnection();
wfc.ipAddress("IP-Address");
wfc.Port(port-number);
try {
wfc.Connect();
Log.e("Connected", wfc.isConnected()+"");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("In Error", "In Error");
e.printStackTrace();
}
//Creating a Printing object
iPrint p = new iPrint(getApplicationContext());
p.Connection(wfc);
p.Settings(set);
if (wfc.isConnected())
{
p.Start();
iObject ob = new iObject();
ob.Text("Hello iPrint!");
p.Add(ob);
p.End();
p.Print();
ob = null;
}
else
{
Log.v("Error",wfc.ErrorMessage()+"");
//showDialog(wfc.ErrorMessage(), AppContext);
}
print(getApplicationContext());
}
private void print(Context AppContext)
{
//Creating Settings object
iSettings set = new iSettings();
set.SetPaperType(iPaperType.LETTER);
set.PrinterType(iPrinters.HP);
//Creating Connection object
ipConnection wfc = new ipConnection();
wfc.ipAddress("ip-address");
wfc.Port(port-number);
try {
wfc.Connect();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("In Error", "In Error");
e.printStackTrace();
}
//Creating a Printing object
iPrint p = new iPrint(AppContext);
p.Connection(wfc);
p.Settings(set);
if (wfc.isConnected())
{
p.Start();
iObject ob = new iObject();
ob.Text("Hello iPrint!");
p.Add(ob);
p.End();
p.Print();
ob = null;
}
else
{
Log.v("Error",wfc.ErrorMessage()+"");
}
set = null;
wfc = null;
p = null;
}
}
添加
iprint.jar
,我已经这样做了。哦,谢谢。但是是否有任何代码示例或任何链接可供我参考。因为我想知道android java编程中应该使用哪些库(例如:Socket等),以便连接和物理打印。谢谢,谢谢。但是是否有任何代码示例或任何链接可供我参考。因为我想知道android java编程中应该使用哪些库(例如:Socket等),以便连接和物理打印。谢谢你打印的文字,格式是否正确,或者它们是否被编码了?好的,很酷。如果我遇到任何问题,我会做并发布。谢谢。嘿,还有一件事,你能提供到iPrint.jar的链接吗。再次感谢您提供了iPrint.jar的链接,但您似乎找不到它。谢谢你,还没有,兄弟。。表示“V/Error(625):传输端点未连接”,因此正在尝试找出答案。。可能与我的网络有关?它是?但无论如何,这是很大的帮助!嘿,你打印的文字是以正确的格式来的,还是被编码了?好吧,酷。如果我遇到任何问题,我会做并发布。谢谢。嘿,还有一件事,你能提供到iPrint.jar的链接吗。再次感谢您提供了iPrint.jar的链接,但您似乎找不到它。谢谢你,还没有,兄弟。。表示“V/Error(625):传输端点未连接”,因此正在尝试找出答案。。可能与我的网络有关?它是?但无论如何,这是很大的帮助!