HI!
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: " + 
event.getInfo());
                                }

                        };



        }


        public void showAllPrinters()
        {
        try
        {
            ListPrinters.jmdns = JmDNS.create();
            ListPrinters.jmdns.addServiceListener("_http._tcp.local.",
listener);
            ListPrinters.impl = (JmDNSImpl)jmdns;

        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }



}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to