我是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);
}
}
我没有订阅该频道并返回:
08-14 10:47:06.625 13752-13752 /? I /标签:开始
08-14 10:47:06.641 13752-13752 /? I / Tag:创建pubnub
08-14 10:47:06.655 13752-13773 /? I /标签:错误
我也收到此错误:
08-14 10:42:06.321 2828-2856 /? W / NetworkManagementSocketTagger:untagSocket(52)因errno -22失败
请帮助我,谢谢你。
最佳答案
https://github.com/pubnub/java
只需复制并删除多余的东西。创建一个新的基本项目,然后相应地移动其项目文件。