问题
I am new to android and working on printing modules now a days.I am developing an app to send print receipt to printers connected on my local network of my own choice. I am interested to see how many printers are connected on my local network if i click them the details should be shown somewhere.
What i have tried to achieve this is implemented the example https://github.com/Bhagvati/NSD-Network-service-discovery-Android/blob/master/NSD/src/com/example/android/nsd/NSDMainActivity.java
I have tried to connect my device using
String HTTPSERVICE_TYPE="_http.tcp"
NsdServiceInfo serviceInfo = new NsdServiceInfo();
serviceInfo.setPort(port);
serviceInfo.setServiceName(mServiceName);
serviceInfo.setServiceType(HTTPSERVICE_TYPE);
serviceInfo.setHost(ip);
mNsdManager.registerService(serviceInfo,
NsdManager.PROTOCOL_DNS_SD, mRegistrationListener);
//and to discover printer on my local network i am using "_ipp.tcp"
public NsdServiceInfo discoverServices() {
mNsdManager.discoverServices(IPPSERVICE_TYPE,
NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener);
return mService;
}
But it is not working to find printer using IPPSERVICE_TYPE="_ipp.tcp." although it is written in the documentation to find the printer we can use this protocol. if i use HTTPService_Type it shows the camera connected to my local network but two cameras are connected only it is indicating one camera connected.
@Override
public void onServiceFound(NsdServiceInfo service) {
if (service.getServiceType().contains("luxul")) {
mNsdManager.resolveService(service, mResolveListener);
Log.e(TAG, "service info :: " + service + "..");
mService = service;
appendResultsText("service luxul info :: " + service );
}
else if (service.getServiceType().contains(HTTPSERVICE_TYPE)) {
mNsdManager.resolveService(service, mResolveListener);
Log.e(TAG, "service info :: " + service + "..");
mService = service;
appendResultsText("service http info :: " + service );
}
else if (service.getServiceType().contains(IPPSERVICE_TYPE)) {
mNsdManager.resolveService(service, mResolveListener);
Log.e(TAG, "service info :: " + service + "..");
mService = service;
appendResultsText("service http info :: " + service );
}
else{
appendResultsText("no service found yet");
}
}
Can anyone guide me where i am doing wrong? Any Help would be appreciated. I am using thermal printer which is connected to my local network and i have also tried to send the print from my android app using IP Address and portNo it is connected.there is no connectivity issue.
来源:https://stackoverflow.com/questions/59873766/connect-to-printer-connecting-on-local-network