javid piprani
javid piprani

Reputation: 1965

jmdns.jar not working on android 4.0 or later

jMdns is a great java library to provide zeroconf/bonjour capabilities to your Android application.

I successfully using this in a project up until Android 4.0 Ice Cream Sandwich aka ICS, once Android 4.0 devices were starting to be used more often I am facing application not working.

I have tested application in android 4.0 earlier, it show me list of Discover Devices but in android 4.0 or later it show nothing.

I've tested this demo "https://github.com/twitwi/AndroidDnssdDemo" on 4.1 but its not working.

I have written Below code based on suggestion mention in "http://snctln.com/2012/08/03/jmdns-and-android-4-0/"

private android.net.wifi.WifiManager.MulticastLock lock;
private android.os.Handler handler = new android.os.Handler();
private JmDNS jmdns = null;
public  WifiManager wifi; 


private void setUp() 
    {
        
        WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
        WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
        int ip = wifiInfo.getIpAddress();
        String ipAddress = Formatter.formatIpAddress(ip);

        
         
        
        try {
            
            
            jmdns.create(_bindingAddress);
            ServiceInfo[] infos = jmdns.list("_afpovertcp._tcp.local.");
            for (int i=0; i < infos.length; i++) {
                 Log.i("Servic : ",infos[i].getName()+"");
//               notifyUser("\nServic : "+infos[i].getName()+"");
                
            }
            


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

your suggestion are appreciable

Upvotes: 3

Views: 815

Answers (2)

McNinja
McNinja

Reputation: 790

You can let it run via the main thread ala

        if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

Upvotes: 1

Warpzit
Warpzit

Reputation: 28152

My simple guess would be that it's trying to download data on the main thread. This is not possible from Ice Cream Sandwich and forward. Try to look at logcat while it runs on the phone, it should clearly show a warning/error message about it if it's the case.

Upvotes: 1

Related Questions