No discovered device found? (android)

asked 2014-06-24 20:57:35 -0700

gumuruh gravatar image

updated 2014-06-24 20:59:57 -0700

Hi everyone! By referring the PDF Guide To Alljoyn- Development using the Java SDK . Please check out the PDF above on page 23.

I tried to implement into my Android single activity to show whether the discovered devices works or not. But seems no luck. There is no device discovered. The question is why there's no devices discovered?

I think i forgot to put something. But i dunno. Please guide me.

So here are my implemented busHandler.java is like this:

package alljoyns;

import main.layout.Chat1Activity;

import org.alljoyn.bus.BusAttachment;
import org.alljoyn.bus.BusException;
import org.alljoyn.bus.BusListener;
import org.alljoyn.bus.Mutable;
import org.alljoyn.bus.ProxyBusObject;
import org.alljoyn.bus.SessionListener;
import org.alljoyn.bus.SessionOpts;
import org.alljoyn.bus.SessionPortListener;
import org.alljoyn.bus.Status;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

/* This class will handle all AllJoyn calls. See onCreate(). */
public class BusHandler extends Handler {       

    private Chat1Activity obChat1Activity;

    private static final String SERVICE_NAME = "alljoyns.simpleservice";
    private static final short CONTACT_PORT=42;

    private BusAttachment mBus;
    private ProxyBusObject mProxyObj;
    private MyServiceInterface mSimpleInterface;
    private ServiceImplementator mInterface = new ServiceImplementator();

    private int     mSessionId;
    private boolean mIsInASession;
    private boolean mIsConnected;
    private boolean mIsStoppingDiscovery;

    /* These are the messages sent to the BusHandler from the UI. */
    public static final int CONNECT = 1;
    public static final int JOIN_SESSION = 2;
    public static final int DISCONNECT = 3;
    public static final int PING = 4;

    private String sName;
    private short sTransport;

    public void setActivity(Chat1Activity obj){
        obChat1Activity = obj;

    public BusHandler(Looper looper, Chat1Activity obj) {
        mIsInASession = false;
        mIsConnected = false;
        mIsStoppingDiscovery = false;

    public void advertiseAndDiscover(){

        mBus = new BusAttachment(obChat1Activity.getPackageName(), BusAttachment.RemoteMessage.Receive);

        Status stat; 

        // testing whether this is true to discover or not
        mBus.registerBusListener(new BusListener(){

            public void foundAdvertisedName(String name, short transport, String namePrefix) {
                short contactPort = CONTACT_PORT;
                SessionOpts XsessionOpts = new SessionOpts();
                Mutable.IntegerValue sessionId = new Mutable.IntegerValue();

                Status stat = mBus.joinSession((String) "", contactPort, sessionId, XsessionOpts, new SessionListener(){});

                obChat1Activity.sendMessage("I found! " + name);


        stat = mBus.connect();

        if(stat != Status.OK){
            obChat1Activity.sendMessage("Error goes here");

        stat = mBus.findAdvertisedName("alljoyns.chatting");

        if(stat != Status.OK){
            obChat1Activity.sendMessage("Error goes again here");


    public void connect(){

        // org.alljoyn.bus.alljoyn.DaemonInit.PrepareDaemon(obChat1Activity.getApplicationContext());

        mBus = new BusAttachment(obChat1Activity.getPackageName(), BusAttachment.RemoteMessage.Receive);

        mBus.registerBusListener(new BusListener() {
            public void foundAdvertisedName(String name, short transport, String namePrefix) {
                //String.format("MyBusListener.foundAdvertisedName(%s, 0x%04x, %s)", name, transport, namePrefix));

                if(!mIsConnected) {

                    sTransport = transport;
                    sName = name;


        /* To communicate with AllJoyn objects, we must connect the BusAttachment to the bus. */
        Status status = mBus.connect();
        //logStatus("BusAttachment.connect()", status);
        if (Status.OK != status) {

        status = mBus.findAdvertisedName(SERVICE_NAME);
        //logStatus(String.format("BusAttachement.findAdvertisedName(%s)", SERVICE_NAME), status);
        if (Status.OK != status) {


    public void joinSession(){

        if (mIsStoppingDiscovery) {

        short contactPort = CONTACT_PORT;
        SessionOpts sessionOpts = new SessionOpts();
        sessionOpts.transports = (short)sTransport;
        Mutable.IntegerValue sessionId = new Mutable.IntegerValue();

        Status status = mBus.joinSession((String) sName, contactPort, sessionId, sessionOpts, new SessionListener() {
            public void sessionLost(int sessionId, int reason ...
edit retag flag offensive close merge delete


Can you first try running the sample apps (maybe the chat app) to make sure that your network allows for multicast and local sockets? If that works, then I would suggest modifying that that app to do what you need. That might be an easier approach. alternatively, if you post logs, we can help better

waynelee ( 2014-06-26 10:01:53 -0700 )edit

actually becoz of my understanding from reading the sample code is very limited. I tried to implement the code right away based on the tutorial PDF. But it seems unlucky... sigh

gumuruh ( 2014-06-28 01:45:43 -0700 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-07-10 11:05:08 -0700

bspencer gravatar image

The solution is actually quite simple, your application is not advertising a well-known name. The service name you are searching for is "alljoyns.chatting":

stat = mBus.findAdvertisedName("alljoyns.chatting");

In your advertiseanddiscover method you will want to add calls to BindSession and AdvertiseName as well as creating a SessionListener and SessionPortListener. You will also want to implement a BusObject that implements the Interface that contains the Ping method. (See service code for an example of using these APIs calls)

If you want to use this application to discover the Simple Service then you will want to change the findAdvertisedName call to be:

stat = mBus.findAdvertisedName("org.alljoyn.bus.samples.simple");

If you want to discover the Chat Application then you would change the line to be:

stat = mBus.findAdvertisedName("org.alljoyn.bus.samples.chat");

I would also recommend that you read the descriptions we have of the terms/concepts and flow of building an application from the AllSeen Alliance website.

edit flag offensive delete publish link more


@gumuruh Did this solve your problem?

bspencer ( 2014-10-01 16:20:46 -0700 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2014-06-24 20:57:35 -0700

Seen: 194 times

Last updated: Jul 10 '14