how to use jmdns

by Naveen » Wed, 21 Apr 2010 14:45:12 GMT


Sponsored Links
 I!
My goal is to find network printers using jmdns

Following is the code I have written which does not work. I am new to
all this Pls. help me.
What exactly I want to do is to list all printers in list
box...Currently I am not filtering printers..

I am always getting exception... Here is my code


public class ListPrinters extends ListActivity {
public static JmDNS jmdns;
public static JmDNSImpl impl;
protected ServiceListener listener;
protected ServiceInfo info;

public ListView lv;
public ArrayList<String> PrinterList;
public int cancel =0;

public final static String TAG = "ListPrinter";


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_printers);

showAllPrinters();
PrinterList = new ArrayList<String>();
PrinterList.add("First Node"); /// just for checking
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1 , PrinterList));
lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View
view,
int position, long id)
{
// When clicked, show a toast with the
TextView text
Toast.makeText(getApplicationContext(),
((TextView)
view).getText(),
Toast.LENGTH_SHORT).show();

if (jmdns != null)
{


ListPrinters.jmdns.removeServiceListener("_http._tcp.local.",
listener);
ListPrinters.jmdns.close();
ListPrinters.jmdns = null;
ListPrinters.impl = null;


}
}
});

this.listener = new ServiceListener() {

public void serviceAdded(ServiceEvent event) {

PrinterList.add("Service added : " +
event.getName() + "." +
event.getType());
Log.v(TAG,"Service added : " +
event.getName() + "." +
event.getType());
}

public void serviceRemoved(ServiceEvent event) {
PrinterList.add("Service removed : " +
event.getName() + "." +
event.getType());
Log.v(TAG,"Service removed : " +
event.getName() + "." +
event.getType());
}

public void serviceResolved(ServiceEvent event)
{
PrinterList.add("Service resolved: " +
event.getInfo());
Log.v(TAG,"Service resolved: " +



how to use jmdns

by Bob Kerns » Thu, 22 Apr 2010 04:38:42 GMT


 sually exceptions are your clue as to what went wrong. And debuggers
are your best tool for understanding what triggered that exception,
and where.

Since you don't tell us the exception or where, I'm afraid you have
all the information you'll need to figure this out -- and we do not.

Good luck.

On Apr 20, 11:44pm, Naveen <naveen...@gmail.com> wrote:
>


Sponsored Links


Other Threads

1. Gallery View using images from file (Dynamic vs. Static images)

The api demo for gallery uses resource id's to access the drawables in
the gallery.

I have tried multiple ways to use images from file. My steps...

- 1. grab filepaths and save all files as a drawable array
- 2. using the same logice in the api demo, I ste the background to
the drawable
          instaed of the resid

That's All I felt the need to replace from the api demo, which seems
to fail miserably since the images do not appear in my test app.

 If you have any hints to help with this let me know,

Thanks
Billy Y
--~--~---------~--~----~------------~-------~--~----~

2. Access drawable resources from ItemizedOverlay

if u jus need resources, have a static Context instance in ur launcher
activity to which u assign the getApplicationContext() in the onCreate
method. Now u hv access to ur app Context from any where in ur application.
"m not sure if this is the best method.
But this is wat i could think of..






-- 
Regards,
Sujay
Fred Allen <http://www.brainyquote.com/quotes/authors/f/fred_allen.html>  -
"California is a fine place to live - if you happen to be an orange."

--~--~---------~--~----~------------~-------~--~----~

3. ListView with different types of View's

4. Soft keyboard pushes stuff up - how to find new Y position (ViewDebug)?

5. Rotating map view

6. How to get a java object property from javascript on Android?

7. JIS conversion is ignored!