Click here to Skip to main content
15,906,626 members
Home / Discussions / Android
   

Android

 
Questionplan and execute an android project Pin
mrkeivan7-Dec-14 1:28
mrkeivan7-Dec-14 1:28 
AnswerRe: plan and execute an android project Pin
Richard MacCutchan7-Dec-14 1:54
mveRichard MacCutchan7-Dec-14 1:54 
AnswerRe: plan and execute an android project Pin
David Crow8-Dec-14 3:54
David Crow8-Dec-14 3:54 
GeneralRe: plan and execute an android project Pin
Member 1137936816-Jan-15 1:53
Member 1137936816-Jan-15 1:53 
AnswerRe: plan and execute an android project Pin
David Crow16-Jan-15 2:04
David Crow16-Jan-15 2:04 
QuestionHow to show up number of notification in application icon Android like Facebook Pin
thientamtita29-Nov-14 23:28
thientamtita29-Nov-14 23:28 
SuggestionRe: How to show up number of notification in application icon Android like Facebook Pin
David Crow1-Dec-14 7:34
David Crow1-Dec-14 7:34 
QuestionHelp me troubleshout error send message using SignalR from Android client Pin
thientamtita28-Nov-14 19:34
thientamtita28-Nov-14 19:34 
--I have a simple chat website http://mynotyfy.somee.com/[^]

-- And simple code Android , I recieved succeed from Server web but I send 1 message from client to web, application unfortunly

Java
package com.signalr_client;

import java.util.concurrent.ExecutionException;

import microsoft.aspnet.signalr.client.Action;
import microsoft.aspnet.signalr.client.ConnectionState;
import microsoft.aspnet.signalr.client.ErrorCallback;
import microsoft.aspnet.signalr.client.MessageReceivedHandler;
import microsoft.aspnet.signalr.client.Platform;
import microsoft.aspnet.signalr.client.http.android.AndroidPlatformComponent;
import microsoft.aspnet.signalr.client.hubs.HubConnection;
import microsoft.aspnet.signalr.client.hubs.HubProxy;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

public class MainActivity extends Activity {
	HubConnection chatConnection;
	HubProxy SignalRChatHub;

	Button ChatButton;
	EditText ChatInput;
	TextView ChatMessages;

	<a href="http://www.codeproject.com/Members/override">@Override</a>
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Platform.loadPlatformComponent(new AndroidPlatformComponent());
		setContentView(R.layout.activity_main);
		// Intent i= new Intent(getApplicationContext(), NotifyService.class);
		// startService(i);

		chatConnection = new HubConnection("http://www.mynotyfy.somee.com/");
		SignalRChatHub = chatConnection.createHubProxy("ChatHub");
		// SignalRChatHub.subscribe(MainActivity.this);

		chatConnection.error(new ErrorCallback() {

			<a href="http://www.codeproject.com/Members/override">@Override</a>
			public void onError(final Throwable error) {
				runOnUiThread(new Runnable() {
					public void run() {
						Toast.makeText(getApplicationContext(),
								error.getMessage(), Toast.LENGTH_LONG).show();
					}
				});
			}
		});
		Init();

		ChatButton.setOnClickListener(new View.OnClickListener() {

			<a href="http://www.codeproject.com/Members/override">@Override</a>
			public void onClick(View v) {
				runThread();
			}
		});
		SignalRChatHub.subscribe(new Object() {
			@SuppressWarnings("unused")
			public void broadcastMessage(final String name, final String message) {
				runOnUiThread(new Runnable() {
					public void run() {
						Toast.makeText(getApplicationContext(),
								name + ": " + message, Toast.LENGTH_LONG)
								.show();
					}
				});
			}
		});

		chatConnection.start().done(new Action<Void>() {

			<a href="http://www.codeproject.com/Members/override">@Override</a>
			public void run(Void obj) throws Exception {
				runOnUiThread(new Runnable() {
					public void run() {
						Toast.makeText(getApplicationContext(),
								"Done Connecting!", Toast.LENGTH_LONG).show();
					}
				});
			}
		});
		chatConnection.received(new MessageReceivedHandler() {
			<a href="http://www.codeproject.com/Members/override">@Override</a>
			public void onMessageReceived(final JsonElement json) {
				runOnUiThread(new Runnable() {
					public void run() {
						Toast.makeText(getApplicationContext(),
								"testing!", Toast.LENGTH_LONG).show();
						JsonObject jsonObject = json.getAsJsonObject();
						JsonArray jsonArray = jsonObject.getAsJsonArray("A");
						String messagex = jsonArray.get(0).getAsString() + ": "
								+ jsonArray.get(1).getAsString();
						ChatMessages.append(messagex + "\n");
						Toast.makeText(getApplicationContext(),
								"loading!", Toast.LENGTH_LONG).show();
						// Toast.makeText(getApplicationContext(), messagex ,
						// Toast.LENGTH_LONG).show();
					}
				});
			}
		});
	}

	public void Init() {
		ChatButton = (Button) findViewById(R.id.ChatButton);
		ChatInput = (EditText) findViewById(R.id.ChatInput);
		ChatMessages = (TextView) findViewById(R.id.ChatMessages);
	}

	public void runThread() {

		new Thread(new Runnable() {
			public void run() {
				try {
					Thread.sleep(500);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} 
				MainActivity.this.runOnUiThread(new Runnable() {
					public void run() {
						Toast.makeText(getApplicationContext(),
								"Click button1", Toast.LENGTH_SHORT).show();
						try{
							SignalRChatHub.invoke("Send", "Android", "hixhix");
						}catch(Exception e){
							ChatMessages.setText(e.getMessage().toString());
						}
							
					}
				});
			}
		}).start();

	}

}


modified 29-Nov-14 3:50am.

QuestionRe: Help me troubleshout error send message using SignalR from Android client Pin
Richard MacCutchan28-Nov-14 22:40
mveRichard MacCutchan28-Nov-14 22:40 
AnswerRe: Help me troubleshout error send message using SignalR from Android client Pin
thientamtita29-Nov-14 16:38
thientamtita29-Nov-14 16:38 
GeneralRe: Help me troubleshout error send message using SignalR from Android client Pin
Richard MacCutchan29-Nov-14 23:14
mveRichard MacCutchan29-Nov-14 23:14 
GeneralRe: Help me troubleshout error send message using SignalR from Android client Pin
thientamtita29-Nov-14 23:28
thientamtita29-Nov-14 23:28 
QuestionRe: Help me troubleshout error send message using SignalR from Android client Pin
David Crow1-Dec-14 8:15
David Crow1-Dec-14 8:15 
Questionandroid src code for bluetooth file and data transfer Pin
Member 1119766327-Nov-14 19:55
Member 1119766327-Nov-14 19:55 
AnswerRe: android src code for bluetooth file and data transfer Pin
den2k8827-Nov-14 20:37
professionalden2k8827-Nov-14 20:37 
GeneralRe: android src code for bluetooth file and data transfer Pin
inbrok0014-Dec-14 9:55
inbrok0014-Dec-14 9:55 
AnswerRe: android src code for bluetooth file and data transfer Pin
Richard MacCutchan27-Nov-14 21:26
mveRichard MacCutchan27-Nov-14 21:26 
Questionhelp me Convert code SignalR From Xamarin (C#) to Eclipse (Java) Pin
thientamtita26-Nov-14 22:53
thientamtita26-Nov-14 22:53 
AnswerRe: help me Convert code SignalR From Xamarin (C#) to Eclipse (Java) Pin
Richard MacCutchan26-Nov-14 22:59
mveRichard MacCutchan26-Nov-14 22:59 
GeneralNeed help from Google Glass dev/designers/testers! Pin
Josh Siemanowicz24-Nov-14 5:42
Josh Siemanowicz24-Nov-14 5:42 
GeneralRe: Need help from Google Glass dev/designers/testers! Pin
Richard MacCutchan24-Nov-14 6:23
mveRichard MacCutchan24-Nov-14 6:23 
QuestionWeb browser Pin
Member 1125990424-Nov-14 5:08
Member 1125990424-Nov-14 5:08 
AnswerRe: Web browser Pin
Richard MacCutchan24-Nov-14 5:55
mveRichard MacCutchan24-Nov-14 5:55 
Questionabout images in ListView Pin
Erdinc2724-Nov-14 1:28
Erdinc2724-Nov-14 1:28 
QuestionI can't find control id in R.id Pin
Richard MacCutchan21-Nov-14 3:19
mveRichard MacCutchan21-Nov-14 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.