Skip to content

Commit 823f8f3

Browse files
author
zhangwei
committed
[Android]Update case: Send Data Stream.
1 parent f099d58 commit 823f8f3

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SendDataStream.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public class SendDataStream extends BaseFragment implements View.OnClickListener
6363
*/
6464
private byte[] data;
6565

66+
private int streamId;
67+
6668
@Nullable
6769
@Override
6870
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@@ -197,9 +199,17 @@ public void onPermissionsResult(boolean allPermissionsGranted, String[] permissi
197199
* {@link SendDataStream#iMetadataObserver}.
198200
* The metadata here can be flexibly replaced according to your own business.*/
199201
data = String.valueOf(new Date().toString()).getBytes(Charset.forName("UTF-8"));
200-
int streamId = engine.createDataStream(true, true);
201-
engine.sendStreamMessage(streamId, data);
202+
sendStreamMessage(data);
203+
}
204+
}
205+
206+
private void sendStreamMessage(byte[] data){
207+
if (streamId == 0) {
208+
// You can call this method to create a data stream and improve the reliability and ordering of data transmission.
209+
// https://api-ref.agora.io/en/voice-sdk/android/4.x/API/class_irtcengine.html#api_irtcengine_createdatastream
210+
streamId = engine.createDataStream(true, true);
202211
}
212+
engine.sendStreamMessage(streamId, data);
203213
}
204214

205215
private void joinChannel(String channelId) {

0 commit comments

Comments
 (0)