附近的连接A​​PI - 断开连接几次后设备不通告

时间:2015-11-16 16:56:32

标签: android google-nearby

我正在使用所谓的附近连接。一个设备是广告(Nearby.Connections.startAdvertising()),另一个是发现(Nearby.Connections.startDiscovery())。这api工作正常,我可以成功连接到主机设备。但是,如果我断开连接并重新连接几次,则该设备不再进行广告宣传。我正在调用Nearby.Connections.startAdvertising(),但是根本没有调用PendingResult的onResult()方法。从Nearby.Connections.startAdvertising()方法返回PendingResult,您可以使用它来检查广告是否成功启动。有没有人有类似的问题?

我必须重启设备才能让广告重新开始工作。 (重新连接wifi无济于事。)

2 个答案:

答案 0 :(得分:0)

当您开始投放广告时,您是否设置了超时?您可以尝试在那里设置0:

<?php
//connect to the server
$link = mysql_connect('*****', '*****', '****'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
}

mysql_select_db('******'); 

$query = mysql_query("SELECT * FROM tablename");

        echo "<table border='1'>
            <tr>
            <td>Date</td>
            <td>Region</td>
            <td>Cameraman</td>
            <td>Livestream?</td>
            <td>Event Title</td>
            <td>Lecturer</td>
            <td>Time</td>
            <td>Speaker</td>
            <td>ICE Contact</td>
            <td>Venue Address</td>
            <td>Venue Contact</td>
            <td>Additional Comments</td>
            <td>On App?</td>
            </tr>";

        WHILE($rows = mysql_fetch_array($query)):

            $date = $rows['date'];
            $region = $rows['region'];
            $cameraman = $rows['cameraman'];
            $livestream = $rows['livestream'];
            $eventtitle = $rows['eventitle'];
            $lecturer = $rows['lecturer'];
            $time = $rows['time'];
            $speaker = $rows['speaker'];
            $icecontact = $rows['icecontact'];
            $venuecontact = $rows['venueaddress'];
            $venuecontact = $rows['venuecontact'];
            $additionalcomments = $rows['additionalcomments'];
            $onapp = $rows['onapp'];



            echo "<tr>";
            echo "<td>" . $rows['date'] . "</td>";
            echo "<td>" . $rows['region'] . "</td>"; 
            echo "<td>" . $rows['cameraman'] . "</td>";
            echo "<td>" . $rows['livestream'] . "</td>"; 
            echo "<td>" . $rows['eventitle'] . "</td>";
            echo "<td>" . $rows['lecturer'] . "</td>"; 
            echo "<td>" . $rows['time'] . "</td>";
            echo "<td>" . $rows['speaker'] . "</td>";
            echo "<td>" . $rows['icecontact'] . "</td>";
            echo "<td>" . $rows['venueaddress'] . "</td>"; 
            echo "<td>" . $rows['venuecontact'] . "</td>";
            echo "<td>" . $rows['additioncomments'] . "</td>";  
            echo "<td>" . $rows['onapp'] . "</td>";     
            echo "</tr>";
            echo "</table>";


        endwhile;
?>

在附近的连接快速入门示例中,您可以设置以下两个变量:

Nearby.Connections.startAdvertising(mGoogleApiClient, hostNameString, appMetadata, 0l, this);

答案 1 :(得分:0)

如果您不需要,我建议不要继续广告您的连接。

我建议您在开始会话时使用stopAdvertising(),当您需要重新连接时,只需再次发送主机ConnectionRequest(...)而不做广告。

无论如何你需要它,你可以再次打开它。 如果你愿意,你可以试试 stopAdvertising()然后startAdvertising(...),看看它是否有效,因为我使用的是这种方法,而且效果很好。

希望有所帮助