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. Itemized overlay

I've a problem with ItemizedOverlay in a mapView.
I had folow the tuto HelloMapView in the android developpers website
and i can't display the itemized overlay in the bottom of the tuto.
I show you my code:

mapview java:

import java.util.List;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.ZoomControls;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


public class Map extends MapActivity {
        List<Overlay> mapOverlays;
        Drawable drawable;
        ItemizedOverlay itemizedOverlay;
        LinearLayout linearLayout;
        MapView mapView;
        ZoomControls mZoom;


        @Override
    public void onCreate(Bundle savedInstanceState) {

                GeoPoint point = new GeoPoint(19240000,-99120000);
                OverlayItem overlayitem = new OverlayItem(point, "", "");
                itemizedOverlay.addOverlay(overlayitem);
                mapOverlays.add(itemizedOverlay);
                mapOverlays = mapView.getOverlays();
                drawable = this.getResources().getDrawable
(R.drawable.androidmarker);
                itemizedOverlay = new ItemizedOverlay(drawable);

                super.onCreate(savedInstanceState);
        setContentView(R.layout.map);
                linearLayout = (LinearLayout) findViewById(R.id.zoomview);
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setSatellite(true);
    }
        protected boolean isRouteDisplayed() {
                return false;
        }
}

ItemizedOverlay Java:

import android.graphics.drawable.Drawable;
import java.util.ArrayList;

import com.google.android.maps.OverlayItem;

public class ItemizedOverlay extends
com.google.android.maps.ItemizedOverlay {

        private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>
();

        public ItemizedOverlay(Drawable defaultMarker) {
                super(boundCenterBottom(defaultMarker));

        }

        @Override
        protected OverlayItem createItem(int i) {
          return mOverlays.get(i);
        }

        @Override
        public int size() {
                return mOverlays.size();
        }
        public void addOverlay(OverlayItem overlay) {
            mOverlays.add(overlay);
            populate();
        }

}

map XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="0GWRUwsy0_POHxdWofVfhZeFLwtgkcn7ouMfwcg"/>
        <LinearLayout
    android:id="@+id/zoomview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/mapview"
    android:layout_centerHorizontal="true"/>
</LinearLayout>

If anyone see any error in this code ??? (I think the mistake is in
the itemizedOverlay java class but i can't find it with the debug
mode)
Thanks
Sweet
--~--~---------~--~----~------------~-------~--~----~

2. startActivity crash

Hello.
 
I have an application in which I am trying to start an activity (geotest)
in, and the activity crashes upon start of the application.  Below is my
code and my logcat output.  I can't figure out the problem, because I have
several other activities I am able to start exactly the same way with no
problem.  When I compare the code, I can't see what I'm doing wrong with the
activity that crashes.  Am I missing permissions for something maybe?  Can
someone please help?  Thanks!
----------------------------------------------------------------------------
----------------------------------------------
 
geotest.java:
 
package net.tinyang.geotest;

import android.app.Activity;

//import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.Toast;

public class geotest extends Activity {

Button geotagbtn = null;

Button next2btn = null;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

geotagbtn = (Button) findViewById(R.id.geotagbtn);

geotagbtn.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

//startActivity(new Intent(MainMenu.this, TakePic.class));

Toast.makeText(geotest.this, "Geotag Picture coming soon", 5000).show();

}

});

next2btn = (Button) findViewById(R.id.next2btn);

next2btn.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

//startActivity(new Intent(Geotest.this, FieldGuide.class));

Toast.makeText(geotest.this, "Next coming soon", 5000).show();

}

});

}

}

----------------------------------------------------------------------------
--------------------------------------

geotag.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=" http://www.***.com/ ;

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

<TextView

android:id="@+id/pictitle"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dip"

android:text="Geotag your Picture" /> 

<ImageView android:id="@+id/camsurface"

android:layout_width="wrap_content" 

android:layout_height="wrap_content">

</ImageView> 

<TableLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content" > 

<TableRow> 

<Button android:id="@+id/geotagbtn"

android:layout_width="wrap_content" 

android:layout_height="wrap_content"

android:layout_below="@id/camsurface"

android:layout_centerHorizontal="true"

android:text=" Geotag " />

<Button android:id="@+id/next2btn"

android:layout_width="wrap_content" 

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:text=" Next " />

</TableRow>

</TableLayout>

</LinearLayout>

----------------------------------------------------------------------------
-------------------------------------------------

manifest:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android=" http://www.***.com/ ;

package="net.tinyang.geotest"

android:versionCode="1"

android:versionName="1.0">

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.CAMERA"/>

<application android:icon="@drawable/icon" android:label="@string/app_name">

<activity android:name=".geotest"

android:label="@string/app_name">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application> 

<uses-sdk android:minSdkVersion="2" />

</manifest> 

----------------------------------------------------------------------------
---------------------------------------------------------------

Logcat output:

 
09-02 23:14:42.623: ERROR/mountd(20): could not read initial mass storage
state
09-02 23:14:42.934: ERROR/flash_image(29): can't find recovery partition
09-02 23:14:50.694: ERROR/MemoryHeapBase(52): error opening /dev/pmem: No
such file or directory
09-02 23:14:50.694: ERROR/SurfaceFlinger(52): Couldn't open
/sys/android_power/wait_for_fb_sleep or /sys/android_power/wait_for_fb_wake
09-02 23:14:50.725: ERROR/GLLogger(52): couldn't load <libhgl.so> library
(Cannot find library)
09-02 23:14:50.805: ERROR/GLLogger(52): couldn't load <libhgl.so> library
(Cannot find library)
09-02 23:14:53.533: ERROR/BatteryService(52): Could not open
'/sys/class/power_supply/usb/online'
09-02 23:14:53.533: ERROR/BatteryService(52): Could not open
'/sys/class/power_supply/battery/batt_vol'
09-02 23:14:53.533: ERROR/BatteryService(52): Could not open
'/sys/class/power_supply/battery/batt_temp'
09-02 23:14:53.754: ERROR/EventHub(52): could not get driver version for
/dev/input/mouse0, Not a typewriter
09-02 23:14:53.754: ERROR/System(52): Failure starting core service
09-02 23:14:53.754: ERROR/System(52): java.lang.SecurityException
09-02 23:14:53.754: ERROR/System(52):     at
android.os.BinderProxy.transact(Native Method)
09-02 23:14:53.754: ERROR/System(52):     at
android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
09-02 23:14:53.754: ERROR/System(52):     at
android.os.ServiceManager.addService(ServiceManager.java:72)
09-02 23:14:53.754: ERROR/System(52):     at
com.android.server.ServerThread.run(SystemServer.java:155)
09-02 23:14:53.764: ERROR/AndroidRuntime(52): Crash logging skipped, no
checkin service
09-02 23:14:53.783: ERROR/EventHub(52): could not get driver version for
/dev/input/mice, Not a typewriter
09-02 23:14:54.045: ERROR/SystemServer(52): Failure starting
StatusBarService
09-02 23:14:54.045: ERROR/SystemServer(52): java.lang.NullPointerException
09-02 23:14:54.045: ERROR/SystemServer(52):     at
com.android.server.status.StatusBarPolicy.updateBluetooth(StatusBarPolicy.ja
va:762)
09-02 23:14:54.045: ERROR/SystemServer(52):     at
com.android.server.status.StatusBarPolicy.<init>(StatusBarPolicy.java:285)
09-02 23:14:54.045: ERROR/SystemServer(52):     at
com.android.server.status.StatusBarPolicy.installIcons(StatusBarPolicy.java:
341)
09-02 23:14:54.045: ERROR/SystemServer(52):     at
com.android.server.ServerThread.run(SystemServer.java:182)
09-02 23:14:54.055: ERROR/AndroidRuntime(52): Crash logging skipped, no
checkin service
09-02 23:14:54.295: ERROR/GpsLocationProvider(52): Could not open GPS
configuration file /etc/gps.conf
09-02 23:14:54.295: ERROR/GpsLocationProvider(52):
java.io.FileNotFoundException: /etc/gps.conf
09-02 23:14:54.295: ERROR/GpsLocationProvider(52):     at
org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:227)
09-02 23:14:54.295: ERROR/GpsLocationProvider(52):     at
java.io.FileInputStream.<init>(FileInputStream.java:76)
09-02 23:14:54.295: ERROR/GpsLocationProvider(52):     at
com.android.internal.location.GpsLocationProvider.<init>(GpsLocationProvider
.java:179)
09-02 23:14:54.295: ERROR/GpsLocationProvider(52):     at
com.android.server.LocationManagerService._loadProvidersNoSync(LocationManag
erService.java:356)
09-02 23:14:54.295: ERROR/GpsLocationProvider(52):     at
com.android.server.LocationManagerService.loadProvidersNoSync(LocationManage
rService.java:340)
09-02 23:14:54.295: ERROR/GpsLocationProvider(52):     at
com.android.server.LocationManagerService.loadProviders(LocationManagerServi
ce.java:333)
09-02 23:14:54.295: ERROR/GpsLocationProvider(52):     at
com.android.server.LocationManagerService.<init>(LocationManagerService.java
:447)
09-02 23:14:54.295: ERROR/GpsLocationProvider(52):     at
com.android.server.ServerThread.run(SystemServer.java:235)
09-02 23:14:54.305: ERROR/AndroidRuntime(52): Crash logging skipped, no
checkin service
09-02 23:15:00.605: ERROR/dalvikvm(157): pthread_setspecific failed, err=22
09-02 23:15:03.095: ERROR/NetworkStateTracker(52):
net.tcp.buffersize.unknown not found in system properties. Using defaults
09-02 23:15:03.095: ERROR/NetworkStateTracker(52): Can't set tcp buffer
sizes:java.io.FileNotFoundException: /sys/kernel/ipv4/tcp_rmem_min

 
-- 
:-) 
{*filter*}a 
P Please don't print this e-mail unless you really need to. 
 
Computer Problems?  Questions?  I can help!  Click on the link below:
 http://www.***.com/ {*filter*}ah
 

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

3. LandScape App. freezes during launching

4. does ur developer phone suck, too?

5. Memory consumption of a typical Android implementation

6. Samsung Galaxy (and future others) compatibility

7. How to design a light and a full version of android app.