Java Pubnub 正在订阅频道
Java Pubnub Subscribing to Channel
我是 Pubnub 的新手,我只是需要一些代码方面的帮助:
package com.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.pubnub.api.*;
import org.json.*;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("Tag", "Start");
final Pubnub pubnub = new Pubnub("demo", "demo");
Log.i("Tag", "Creation of pubnub");
try{
pubnub.subscribe("DavidsChannel", new Callback() {
@Override
public void connectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : CONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
Log.i("Tag", "CONNECT");
}
@Override
public void disconnectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : DISCONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
Log.i("Tag", "DISCONNECT");
}
public void reconnectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : RECONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
Log.i("Tag", "RECONNECT");
}
@Override
public void successCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : " + channel + " : "
+ message.getClass() + " : " + message.toString());
Log.i("Tag", channel);
}
@Override
public void errorCallback(String channel, PubnubError error) {
System.out.println("SUBSCRIBE : ERROR on channel " + channel
+ " : " + error.toString());
Log.i("Tag", "ERROR");
}
}
);
} catch (Exception e) {
System.out.println("Error" + " : " + e.toString());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我没有订阅频道并且 returns:
08-14 10:47:06.625 13752-13752/? I/Tag﹕开始
08-14 10:47:06.641 13752-13752/? I/Tag﹕创建pubnub
08-14 10:47:06.655 13752-13773/? I/Tag﹕错误
我也遇到了这个错误:
08-14 10:42:06.321 2828-2856/? W/NetworkManagementSocketTagger:untagSocket(52) 失败,errno -22
请帮帮我,先谢谢了。
https://github.com/pubnub/java
只需复制并删除多余的东西。创建新的基本项目,然后相应地移动他们的项目文件。
我是 Pubnub 的新手,我只是需要一些代码方面的帮助:
package com.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.pubnub.api.*;
import org.json.*;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("Tag", "Start");
final Pubnub pubnub = new Pubnub("demo", "demo");
Log.i("Tag", "Creation of pubnub");
try{
pubnub.subscribe("DavidsChannel", new Callback() {
@Override
public void connectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : CONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
Log.i("Tag", "CONNECT");
}
@Override
public void disconnectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : DISCONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
Log.i("Tag", "DISCONNECT");
}
public void reconnectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : RECONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
Log.i("Tag", "RECONNECT");
}
@Override
public void successCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : " + channel + " : "
+ message.getClass() + " : " + message.toString());
Log.i("Tag", channel);
}
@Override
public void errorCallback(String channel, PubnubError error) {
System.out.println("SUBSCRIBE : ERROR on channel " + channel
+ " : " + error.toString());
Log.i("Tag", "ERROR");
}
}
);
} catch (Exception e) {
System.out.println("Error" + " : " + e.toString());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我没有订阅频道并且 returns:
08-14 10:47:06.625 13752-13752/? I/Tag﹕开始
08-14 10:47:06.641 13752-13752/? I/Tag﹕创建pubnub
08-14 10:47:06.655 13752-13773/? I/Tag﹕错误
我也遇到了这个错误:
08-14 10:42:06.321 2828-2856/? W/NetworkManagementSocketTagger:untagSocket(52) 失败,errno -22
请帮帮我,先谢谢了。
https://github.com/pubnub/java 只需复制并删除多余的东西。创建新的基本项目,然后相应地移动他们的项目文件。