Calling a public Class in onClick - java

I have an onClick event:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPrayerTime = (Button)findViewById(R.id.muteButton);
mPrayerTime.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//call CityModelHere
}
});
and I want to call this class (and specifically get the fajr variable without it returning null as it does if I instantiate a new cityModel in the onClick):
public class cityModel implements Serializable {
private String fajr;
public void setFajr(String fajr) {
this.fajr= fajr;
}
public String getFajr() {
return fajr;
}
}
the class takes the string from a later class here just in case:
protected void outputTimings(JSONArray jsonArray) {
String[] prayers = {"fajr", "shurooq", "dhuhr", "asr", "maghrib", "isha"};
cityModel cityObj;
try {
cityObj= new cityModel();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject cityObject =
jsonArray.getJSONObject(i);
result = result + "fajr" + " : "
+ cityObject.getString("fajr") + "\n" + result + "shurooq" + " : "
+ cityObject.getString("shurooq") + "\n" + result + "dhuhr" + " : "
+ cityObject.getString("dhuhr") + "\n" + result + "asr" + " : "
+ cityObject.getString("asr") + "\n" + result + "maghrib" + " : "
+ cityObject.getString("maghrib") + "\n" + result + "isha" + " : "
+ cityObject.getString("isha") + "\n";
cityObj.setFajr(""+cityObject.getString("fajr"));
}
} catch (JSONException e1) {
e1.printStackTrace();
}
}

Make your variable final, and then you can access it from the setOnClickListener.

Related

How to change Bluetooth scan interval?

I am building a collector application that continuously scans the Bluetooth and writes the RSSI results in a file, I used this code but it scans and records the data every 5-second.
I want to make it scan and collect the RSSI data every 100 mill second.Please help me to modify this.
private ScanCallback leScanCallback = new ScanCallback() {
#Override
public void onScanResult(int callbackType, final ScanResult result) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
// Tried new Handler(Looper.myLopper()) also
#Override
public void run() {
peripheralTextView.append("MAC: " + result.getDevice().getAddress() +","
+ result.getDevice().getName() +","
+ " RSSI: " + result.getRssi() + "\n");
}
});
try {
long TimeStampMillSec = TimeStampMillSec();
String DateTimeToIso8601Datetimehhmmss = DateTimeToIso8601Datetimehhmmss();
JSONObject jsonMsg =new JSONObject();
//Edited by Mansour
jsonMsg.put("BLue",
"6"+","+phoneIMEI+","+DateTimeToIso8601Datetimehhmmss+
","+TimeStampMillSec+","+result.getDevice().getName()
+ "," + result.getRssi());
WriteMessageLog(0, jsonMsg +"\n");
// auto scroll for text view
final int scrollAmount =
peripheralTextView.getLayout().getLineTop(peripheralTextView.getLineCount())
- peripheralTextView.getHeight();
// if there is no need to scroll, scrollAmount will be <=0
if (scrollAmount > 0)
peripheralTextView.scrollTo(0, scrollAmount);
}
catch (Exception e)
{
e.printStackTrace();
}
}
};`

How to call a Method in OnClickListener without variable (Fajr) in the method becoming null when called

In my OnClickListener:
private Button mPrayerTime;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPrayerTime = (Button)findViewById(R.id.muteButton);
mPrayerTime.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
cityModel cityObj= new cityModel();
String fajr=cityObj.getFajr();
Log.d("Fajr", ""+fajr);
}
});
}
I call a method called cityModel, found here
public final class cityModel implements Serializable {
private String fajr;
public void setFajr(String fajr) {
this.fajr= fajr;
}
public String getFajr() {
return fajr;
}
}
which retrieves set.Fajr from:
protected void outputTimings(JSONArray jsonArray) {
String[] prayers = {"fajr", "shurooq", "dhuhr", "asr", "maghrib", "isha"};
final cityModel cityObj;
try {
cityObj= new cityModel();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject cityObject =
jsonArray.getJSONObject(i);
result = result + "fajr" + " : "
+ cityObject.getString("fajr") + "\n" + result + "shurooq" + " : "
+ cityObject.getString("shurooq") + "\n" + result + "dhuhr" + " : "
+ cityObject.getString("dhuhr") + "\n" + result + "asr" + " : "
+ cityObject.getString("asr") + "\n" + result + "maghrib" + " : "
+ cityObject.getString("maghrib") + "\n" + result + "isha" + " : "
+ cityObject.getString("isha") + "\n";
cityObj.setFajr(""+cityObject.getString("fajr"));
}
When I tried to debug, I found that cityModel finds the value for fajr and stores it just fine, so the issue seems to be with how I call the method because whenever I look for the label Fajr in logcat it shows up as null.

Save user input string to variable on button click

in my application the user will input a channel they want to subscribe to in an editable text field. Upon clicking the subscribe button, the variable that is placed in my method to subscribe the user should be updated to that of the users choice and then a toast will appear notifying the user that they are subscribed to this channel.
At the bottom, I get the string value that the user inputs in the EditText field, but I don't think I'm putting it in the right place. Can someone take a look at it and let me know what I'm doing wrong? Let me know if I wasn't clear or am missing something and I can try to explain better. Thanks!
public class MainActivity extends ActionBarActivity {
private Button channelSubscribeButton;
private EditText subscribeChannelEditText;
//Declare variable
String subscribeChannel = null;
//-------------------------Access PubNub API-------------------------//
Pubnub pubnub = new Pubnub("pub-c-940c4776-36ff-425f-9677-f1c904a9d57b", "sub-c-cf42b292-a8bf-11e4-85d5-0619f8945a4f");
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
channelSubscribeButton = (Button) findViewById(R.id.subscribe_button);
subscribeChannelEditText = (EditText) findViewById(R.id.channel_name);
//-------------------------Subscribe to a Channel to Receive Messages-------------------------//
try {
//THIS IS WHERE I AM INPUTTING THE VARIABLE THAT CONTAINS THE USER INPUTTED TEXT//
//I AM GETTING ERROR THAT SAYS IT CAN'T RESOLVE THE SYMBOL 'subscribeChannel'//
pubnub.subscribe(subscribeChannel, new Callback() {
#Override
public void connectCallback(String channel, Object message) {
Log.d("PUBNUB", "SUBSCRIBE : CONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
#Override
public void disconnectCallback(String channel, Object message) {
Log.d("PUBNUB", "SUBSCRIBE : DISCONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
public void reconnectCallback(String channel, Object message) {
Log.d("PUBNUB", "SUBSCRIBE : RECONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
#Override
public void successCallback(String channel, Object message) {
Log.d("PUBNUB", "SUBSCRIBE : " + channel + " : "
+ message.getClass() + " : " + message.toString());
}
#Override
public void errorCallback(String channel, PubnubError error) {
Log.d("PUBNUB", "SUBSCRIBE : ERROR on channel " + channel
+ " : " + error.toString());
}
}
);
} catch (PubnubException e) {
Log.d("PUBNUB", e.toString());
}
public void onChannelButtonClick(View view) {
subscribeChannel = String.valueOf(subscribeChannelEditText.getText());
String yourSubscribeChannel = "Subscribed to the " + subscribeChannel + " Channel";
Toast.makeText(this, yourSubscribeChannel, Toast.LENGTH_LONG).show();
return subscribeChannel;
}
Your subscribeChannel variable is only visible within the scope of your onChannelButtonClick method. Declare it outside along with your instance variables.
public void onChannelButtonClick(View view) {
//here you set it and then it's lost.
String subscribeChannel = String.valueOf(subscribeChannelEditText.getText());
String yourSubscribeChannel = "Subscribed to the " + subscribeChannel + " Channel";
Toast.makeText(this, yourSubscribeChannel, Toast.LENGTH_LONG).show();
}
Instead do:
//declare it.
String subscribeChannel = null;
And then on your method assign the value.
public void onChannelButtonClick(View view) {
//assign it.
subscribeChannel = String.valueOf(subscribeChannelEditText.getText());
String yourSubscribeChannel = "Subscribed to the " + subscribeChannel + " Channel";
Toast.makeText(this, yourSubscribeChannel, Toast.LENGTH_LONG).show();
}

Java exception (Can't create handler inside thread that has not called Looper.prepare())) - what does it mean?

in my project i received error:
02-20 23:32:45.433: E/Receiver(19076): Read: Error
02-20 23:32:45.433: E/Receiver(19076): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
02-20 23:32:45.433: E/Receiver(19076): at android.os.Handler.<init>(Handler.java:200)
02-20 23:32:45.433: E/Receiver(19076): at android.os.Handler.<init>(Handler.java:114)
02-20 23:32:45.433: E/Receiver(19076): at android.app.Activity.<init>(Activity.java:793)
02-20 23:32:45.433: E/Receiver(19076): at stas.tcp.client.SensorsActivity.<init>(SensorsActivity.java:29)
02-20 23:32:45.433: E/Receiver(19076): at stas.tcp.client.SPN_API.invoke_command(SPN_API.java:208)
02-20 23:32:45.433: E/Receiver(19076): at stas.tcp.client.SPN_engine.doInvokeCommand(SPN_engine.java:164)
02-20 23:32:45.433: E/Receiver(19076): at stas.tcp.client.SPN_engine.processPoUART(SPN_engine.java:127)
02-20 23:32:45.433: E/Receiver(19076): at stas.tcp.client.PoUARTSupport.checkPacket(PoUARTSupport.java:65)
02-20 23:32:45.433: E/Receiver(19076): at stas.tcp.client.Receiver.run(Receiver.java:46)
02-20 23:32:45.433: E/Receiver(19076): at java.lang.Thread.run(Thread.java:841)
and i don't know what does it mean for me. I have few threads in my project, and i don't know which made error. When i commented out one and only thred in SensorsActivity.class - error still occured.
--EDIT---
public class SensorsActivity extends Activity implements EventListener, StepCounterListener, LinearAccListener, StepDetectorListener, LightSensorListener, PressureSensorListener, GravitySensorListener, RotationVectorListener, RelativeHumidityListener, ProximitySensorListener, TempSensorListener, AccelerometerSensorListener, GyroSensorListener, MagSensorListener {
public static final long axisssx = 0;
private TextView lightText, pressureText, signText, noiseText, humidityText, linearAccText, proximityText, tempText, accelText, gyroText, magText, rotationText, gravityText, stepDetectorText, stepCounterText;
private LightSensor mLightSensor;
private PressureSensor mPressureSensor;
private RelativeHumiditySensor mRelativeHumidity;
private ProximitySensor mProximitySensor;
private TemperatureSensor mTempSensor;
private AccelerometerSensor mAccelSensor;
private GyroscopeSensor mGyroSensor;
private MagnetometerSensor mMagSensor;
private RotationSensor mRotSensor;
private GravitySensor mGravitySensor;
private StepCounterSensor mStepCounter;
private StepDetectorSensor mStepDetector;
private LinearAccelerometer mLinearAcc;
private NoiseLevel mNoise;
public double amp;
private Handler handler1;
public long accelx, accely, accelz;
private SPN_native spnNative;
private SPN_API spnApi;
private int argsImageLength;
private int actualNrOfArgs;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sensors);
lightText = (TextView)findViewById(R.id.rLight);
pressureText = (TextView)findViewById(R.id.rPressure);
humidityText = (TextView)findViewById(R.id.rHumidity);
proximityText = (TextView)findViewById(R.id.rProximity);
tempText = (TextView)findViewById(R.id.rTemp);
accelText = (TextView)findViewById(R.id.rAccel);
gyroText = (TextView)findViewById(R.id.rGyro);
magText = (TextView)findViewById(R.id.rMag);
rotationText = (TextView)findViewById(R.id.rRotation);
gravityText = (TextView)findViewById(R.id.rGravity);
stepCounterText = (TextView)findViewById(R.id.rSCounter);
stepDetectorText = (TextView)findViewById(R.id.rSDetector);
linearAccText = (TextView)findViewById(R.id.rLinearAcc);
signText = (TextView)findViewById(R.id.rSignMotion);
noiseText = (TextView)findViewById(R.id.rNoise);
//SOUND LEVEL CODE:
mNoise = new NoiseLevel();
try {
mNoise.starter();
//Toast.makeText(getBaseContext(), "Sound sensor initiated.", Toast.LENGTH_SHORT).show();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
handler1 = new Handler();
final Runnable r = new Runnable() {
//this.runOnUiThread(new Runnable(){
public void run() {
Toast.makeText(getBaseContext(), "Working!", Toast.LENGTH_LONG).show();
runOnUiThread(new Runnable() {
#Override
public void run() {
// Get the volume from 0 to 255 in 'int'
//double volume = 10 * mNoise.getTheAmplitude() / 32768;
double volume = mNoise.getTheAmplitude();
int volumeToSend = (int) volume;
noiseText.setText("Volume: " + String.valueOf(volumeToSend));
handler1.postDelayed(this, 250); // amount of delay between every cycle of volume level detection + sending the data out
}
});
}
};
handler1.postDelayed(r, 250);
mLightSensor = new LightSensor(getBaseContext());
mLightSensor.setListener(this);
Log.e("Sensor Activity:" , "LIGHT SENSOR LISTENER ACTIVE");
mPressureSensor = new PressureSensor(getBaseContext());
mPressureSensor.setListener(this);
Log.e("Sensor Activity:" , "PRESSURE SENSOR LISTENER ACTIVE");
mRelativeHumidity = new RelativeHumiditySensor(getBaseContext());
mRelativeHumidity.setListener(this);
mProximitySensor = new ProximitySensor(getBaseContext());
mProximitySensor.setListener(this);
Log.e("Sensor Activity:" , "PROXIMITY SENSOR LISTENER ACTIVE");
mTempSensor = new TemperatureSensor(getBaseContext());
mTempSensor.setListener((TempSensorListener) this);
mAccelSensor = new AccelerometerSensor(getBaseContext());
mAccelSensor.setListener(this);
mGyroSensor = new GyroscopeSensor(getBaseContext());
mGyroSensor.setListener(this);
mMagSensor = new MagnetometerSensor(getBaseContext());
mMagSensor.setListener(this);
mRotSensor = new RotationSensor(getBaseContext());
mRotSensor.setListener(this);
mGravitySensor = new GravitySensor(getBaseContext());
mGravitySensor.setListener(this);
mStepCounter = new StepCounterSensor(getBaseContext());
mStepCounter.setListener(this);
mStepDetector = new StepDetectorSensor(getBaseContext());
mStepDetector.setListener(this);
mLinearAcc = new LinearAccelerometer(getBaseContext());
mLinearAcc.setListener(this);
spnNative = new SPN_native();
spnApi = new SPN_API();
}
public void onLightSensorChanged(int lux){
lightText.setText("LIGHT level: " + lux + " lx");
}
public void onPressureSensorChanged(long pressure){
pressureText.setText("\nPRESSURE: " + pressure + " mPa ");
}
public void onRelativeHumidityChanged(String humidity) {
humidityText.setText("\nRELATIVE HUMIDITY: " + humidity);
}
public void onProximitySensorChanged(int proximity) {
proximityText.setText("\nPROXIMITY: " + proximity);
}
public void onTempSensorChanged(String temperature) {
tempText.setText("\nAMBIENT TEMPERATURE :" + temperature + " celcius degree");
}
public void onAccelSensorChanged(long axisX, long axisY, long axisZ) {
accelText.setText("\nACCELEROMETER: \nX: " + axisX + "nm/s^2 || Y: " + axisY + "nm/s^2 || Z: " + axisZ +"nm/s^2");
}
public void onGyroSensorChanged(long axisX, long axisY, long axisZ) {
gyroText.setText("\nGYROSCOPE: \nX: " + axisX + "nrad/s || Y: " + axisY + "nrad/s || Z: " + axisZ + "nrad/s");
}
public void onMagSensorChanged(long axisX, long axisY, long axisZ) {
magText.setText("\nMAGNETOMETER: \nX: " + axisX + " piko Tesla || Y: " + axisY + " piko Tesla || Z: " + axisZ + " piko Tesla");
}
public void onRotationVectorChanged(long rot1, long rot2, long rot3) {
rotationText.setText("\nROTATION VECTOR: \nYaw: " + rot1 + " nrad || Pitch: " + rot2 + " nrad || Roll: " + rot3 + " nrad");
}
public void onGravitySensorChanged(long gravity1, long gravity2, long gravity3) {
gravityText.setText("\nGRAVITY: \nX: " + gravity1 + "nm/s^2 || Y: " + gravity2 + "nm/s^2 || Z: " + gravity3 + "nm/s^2");
}
public void onStepCounterChanged(int step) {
stepCounterText.setText("\nSTEP CONTER: " + step + " steps");
}
public void onStepDetectorChanged(String step) {
stepDetectorText.setText("\nSTEP DETECTOR: " + step);
}
public void onLinearAccChanged(long axisX, long axisY, long axisZ) {
linearAccText.setText("\nLINEAR ACCELERATION: \nX: " + axisX + "nm/s^2 || Y: " + axisY + "nm/s^2 || Z: " + axisZ + "nm/s^2");
}
#Override
protected void onResume() {
super.onStart();
// Sound based code
// try {
// mNoise = new NoiseLevel();
// mNoise.starter();
// Toast.makeText(getBaseContext(), "Sound sensor initiated.", Toast.LENGTH_SHORT).show();
// } catch (IllegalStateException e) {
// // TODO Auto-generated catch block
// Toast.makeText(getBaseContext(), "On resume, sound sensor messed up...", Toast.LENGTH_LONG).show();
// e.printStackTrace();
// }
if(!mLightSensor.register()){
lightText.setText("\nLight sensor not supported!");
// Toast.makeText(this, "Light sensor not supported!", Toast.LENGTH_SHORT).show();
}
if(!mPressureSensor.register()){
pressureText.setText("\nPressure sensor not supported!");
}
if(!mRelativeHumidity.register()){
humidityText.setText("\nRelative humidity sensor not supported!");
}
if(!mProximitySensor.register()){
proximityText.setText("\nProximity sensor not supported!");
}
if(!mTempSensor.register()){
tempText.setText("\nAmbient temperature sensor not supported!");
}
if(!mAccelSensor.register()){
accelText.setText("\nAccelerometer sensor not supported!");
}
if(!mGyroSensor.register()){
gyroText.setText("\nGyroscope sensor not supported!");
}
if(!mMagSensor.register()){
magText.setText("\nMagnetometer sensor not supported!");
}
if(!mRotSensor.register()){
rotationText.setText("\nRotation Vector sensor not supported!");
}
if(!mGravitySensor.register()){
gravityText.setText("\nGravity sensor not supported!");
}
if(!mStepCounter.register()){
stepCounterText.setText("\nStep counter sensor not supported!");
}
if(!mStepDetector.register()){
stepDetectorText.setText("\nStep detector sensor not supported!");
}
if(!mLinearAcc.register()) {
linearAccText.setText("\nLinear accelerometer not supported!");
}
}
#Override
protected void onPause() {
super.onStop();
}
private void start() throws IllegalStateException, IOException {
mNoise.starter();
}
private void stop() {
// mNoise.stop();
}
private void sleep() {
// mNoise.stop();
}
private static byte[] longToByteArray(long data, int arrayLength) {
byte[] array = new byte[arrayLength];
int n = 0;
for(int i = arrayLength - 1; 0 <= i; --i) {
array[n] = (byte)(data >> i*8);
n++;
}
Log.e("SensorActivity", "longToByteArray array= " + Arrays.toString(array));
return array;
}
}

Stream API in twitter Not responding

I am using twitter4j Stream API 3.0.3 jar. I tried to get the User Stream and tweets my code is given below. It is running only not showing any outputs for past 1 hour.
public class StreamAPI {
public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey("xxxx");
cb.setOAuthConsumerSecret("xxxx");
cb.setOAuthAccessToken("xxx-x");
cb.setOAuthAccessTokenSecret("xxxxx");
cb.setUseSSL(true);
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
RawStreamListener listener = new RawStreamListener() {
#Override
public void onMessage(String rawJSON) {
System.out.println(rawJSON);
}
#Override
public void onException(Exception ex) {
ex.printStackTrace();
}
};
twitterStream.addListener(listener);
twitterStream.sample();
}
}
and when I try to get user, it shows 401 Authentication error
static UserStreamListener listener = new UserStreamListener() {
#Override
public void onStatus(Status status) {
System.out.println("onStatus #" + status.getUser().getScreenName() + " - " + status.getText());
}
#Override
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
}
#Override
public void onDeletionNotice(long directMessageId, long userId) {
System.out.println("Got a direct message deletion notice id:" + directMessageId);
}
#Override
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
System.out.println("Got a track limitation notice:" + numberOfLimitedStatuses);
}
#Override
public void onScrubGeo(long userId, long upToStatusId) {
System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
}
#Override
public void onStallWarning(StallWarning warning) {
System.out.println("Got stall warning:" + warning);
}
#Override
public void onFriendList(long[] friendIds) {
System.out.print("onFriendList");
for (long friendId : friendIds) {
System.out.print(" " + friendId);
}
System.out.println();
}
#Override
public void onFavorite(User source, User target, Status favoritedStatus) {
System.out.println("onFavorite source:#"
+ source.getScreenName() + " target:#"
+ target.getScreenName() + " #"
+ favoritedStatus.getUser().getScreenName() + " - "
+ favoritedStatus.getText());
}
#Override
public void onUnfavorite(User source, User target, Status unfavoritedStatus) {
System.out.println("onUnFavorite source:#"
+ source.getScreenName() + " target:#"
+ target.getScreenName() + " #"
+ unfavoritedStatus.getUser().getScreenName()
+ " - " + unfavoritedStatus.getText());
}
#Override
public void onFollow(User source, User followedUser) {
System.out.println("onFollow source:#"
+ source.getScreenName() + " target:#"
+ followedUser.getScreenName());
}
#Override
public void onDirectMessage(DirectMessage directMessage) {
System.out.println("onDirectMessage text:"
+ directMessage.getText());
}
#Override
public void onUserListMemberAddition(User addedMember, User listOwner, UserList list) {
System.out.println("onUserListMemberAddition added member:#"
+ addedMember.getScreenName()
+ " listOwner:#" + listOwner.getScreenName()
+ " list:" + list.getName());
}
#Override
public void onUserListMemberDeletion(User deletedMember, User listOwner, UserList list) {
System.out.println("onUserListMemberDeleted deleted member:#"
+ deletedMember.getScreenName()
+ " listOwner:#" + listOwner.getScreenName()
+ " list:" + list.getName());
}
#Override
public void onUserListSubscription(User subscriber, User listOwner, UserList list) {
System.out.println("onUserListSubscribed subscriber:#"
+ subscriber.getScreenName()
+ " listOwner:#" + listOwner.getScreenName()
+ " list:" + list.getName());
}
#Override
public void onUserListUnsubscription(User subscriber, User listOwner, UserList list) {
System.out.println("onUserListUnsubscribed subscriber:#"
+ subscriber.getScreenName()
+ " listOwner:#" + listOwner.getScreenName()
+ " list:" + list.getName());
}
#Override
public void onUserListCreation(User listOwner, UserList list) {
System.out.println("onUserListCreated listOwner:#"
+ listOwner.getScreenName()
+ " list:" + list.getName());
}
#Override
public void onUserListUpdate(User listOwner, UserList list) {
System.out.println("onUserListUpdated listOwner:#"
+ listOwner.getScreenName()
+ " list:" + list.getName());
}
#Override
public void onUserListDeletion(User listOwner, UserList list) {
System.out.println("onUserListDestroyed listOwner:#"
+ listOwner.getScreenName()
+ " list:" + list.getName());
}
#Override
public void onUserProfileUpdate(User updatedUser) {
System.out.println("onUserProfileUpdated user:#" + updatedUser.getScreenName());
}
#Override
public void onBlock(User source, User blockedUser) {
System.out.println("onBlock source:#" + source.getScreenName()
+ " target:#" + blockedUser.getScreenName());
}
#Override
public void onUnblock(User source, User unblockedUser) {
System.out.println("onUnblock source:#" + source.getScreenName()
+ " target:#" + unblockedUser.getScreenName());
}
#Override
public void onException(Exception ex) {
ex.printStackTrace();
System.out.println("onException:" + ex.getMessage());
}
};
Is anyone can help me to get details about the user, users followers following and tweets in Twitter
The 401 error code indicates that you're not properly authenticated. Are you certain those credentials are correct?
A good way to test that would be to connect to the regular streaming API (rather than a user stream) and seeing if you still get a 401. If you do, then your credentials are incorrect. If it works, then there's a problem with the user stream you're requesting.

Categories

Resources