Copyright (c) 2014 FeedHenry Ltd, All Rights Reserved.
Please refer to your contract with FeedHenry for the software license agreement.
If you do not have a contract, you do not have a license to use...
If you think the Android project fh-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.feedhenry.fhandroidexampleapp;
/*www.java2s.com*/import org.json.fh.JSONArray;
import org.json.fh.JSONObject;
import com.feedhenry.sdk.FH;
import com.feedhenry.sdk.FHActCallback;
import com.feedhenry.sdk.FHResponse;
import com.feedhenry.sdk.api.FHActRequest;
import com.feedhenry.sdk.api.FHCloudRequest;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
publicclass FHActActivity extends ListActivity {
privatestaticfinal String TAG = "FHAndroidSDKExample";
private ProgressDialog mDialog = null;
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Tweets About FeedHenry");
final Context that = this;
mDialog = ProgressDialog.show(this, "Loading", "Please wait...");
FH.setLogLevel(FH.LOG_LEVEL_VERBOSE);
FH.init(this, new FHActCallback() {
@Override
publicvoid success(FHResponse arg0) {
loadTweets();
}
@Override
publicvoid fail(FHResponse arg0) {
mDialog.dismiss();
FhUtil.showMessage(that, "Error", arg0.getErrorMessage());
}
});
}
privatevoid loadTweets(){
final Context that = this;
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.activity_act);
getListView().setAdapter(adapter);
try{
//build the request object. The first parameter is the name of the cloud side function to be called,
//the second parameter is the data parameter for the function
FHCloudRequest request = FH.buildCloudRequest("getTweets", "GET", null, null);
//the request will be executed asynchronously
request.executeAsync(new FHActCallback() {
@Override
publicvoid success(FHResponse res) {
//the function to execute if the request is successful
try{
JSONArray resObj = res.getJson().getJSONArray("tweets");
Log.d(TAG, resObj.toString(2));
for(int i=0;i<resObj.length();i++){
JSONObject event = resObj.getJSONObject(i);
adapter.add(event.getString("text"));
}
mDialog.dismiss();
} catch(Exception e){
Log.e(TAG, e.getMessage(), e);
}
}
@Override
publicvoid fail(FHResponse res) {
//the function to execute if the request is failed
Log.e(TAG, res.getErrorMessage(), res.getError());
mDialog.dismiss();
FhUtil.showMessage(that, "Error", res.getErrorMessage());
}
});
} catch(Exception e){
Log.e(TAG, e.getMessage(), e);
}
}
}