Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Update Android Sample for Preview 3 (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelm12 authored Oct 23, 2018
1 parent b9d6055 commit 1879896
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
5 changes: 3 additions & 2 deletions AndroidJavaClient/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.microsoft.aspnet.signalr.samples.androidjavaclient"
minSdkVersion 24
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand All @@ -29,5 +29,6 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.microsoft.aspnet:signalr:0.1.0-preview1-35029'
implementation group: 'com.microsoft.signalr', name: 'signalr', version: '1.0.0-preview3-35501'
implementation group: 'org.slf4j', name: 'slf4j-android', version: '1.7.7'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.microsoft.aspnet.signalr.samples.androidjavaclient;


import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
Expand All @@ -10,10 +11,8 @@
import android.widget.ListView;
import android.widget.TextView;

import com.microsoft.aspnet.signalr.Action;
import com.microsoft.aspnet.signalr.HubConnection;
import com.microsoft.aspnet.signalr.HubConnectionBuilder;
import com.microsoft.aspnet.signalr.LogLevel;
import com.microsoft.signalr.HubConnection;
import com.microsoft.signalr.HubConnectionBuilder;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -24,7 +23,7 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
HubConnection hubConnection = new HubConnection("Your URL Here");
HubConnection hubConnection = HubConnectionBuilder.create("YOUR URL HERE").build();
TextView textView = (TextView)findViewById(R.id.tvMain);
ListView listView = (ListView)findViewById(R.id.lvMessages);
Button sendButton = (Button)findViewById(R.id.bSend);
Expand Down Expand Up @@ -58,11 +57,21 @@ public void onClick(View view) {
}
});

try {
hubConnection.start();
} catch (Exception e) {
e.printStackTrace();
textView.setText("There was an error: " + e.getMessage());
new HubConnectionTask().execute(hubConnection);
}

class HubConnectionTask extends AsyncTask<HubConnection, Void, Void>{

@Override
protected void onPreExecute() {
super.onPreExecute();
}

@Override
protected Void doInBackground(HubConnection... hubConnections) {
HubConnection hubConnection = hubConnections[0];
hubConnection.start().blockingAwait();
return null;
}
}
}
}

0 comments on commit 1879896

Please sign in to comment.