Not able to get tap points from tapjoy offerwall? - android

I have developed an android app. In this app I have integrated tapjoy and everbadge offerwalls. In tapjoy offerwall, I am calling following method to show offerwall.
TapjoyConnect.getTapjoyConnectInstance().showOffers();
but when I complete an offer I am not able to see tap points in toast. following is the code I have written for tapjoy offerwall.
public class TapjoyOfferwall implements TapjoyEarnedPointsNotifier, TapjoyNotifier{
private Activity context;
//private AppPreferences appPreferences;
private String AppId_TapJoy = "bba49f11-b87f-4c0f-9632-21aa810dd6f1";
private String SecretKey_TapJoy = "yiQIURFEeKm0zbOggubu";
private String displayText = "";
boolean update_text = false;
boolean earnedPoints = false;
int point_total;
String currency_name;
public TapjoyOfferwall(Activity context) {
super();
this.context = context;
//appPreferences = new AppPreferences(context);
// Enables logging to the console.
TapjoyLog.enableLogging(true);
// OPTIONAL: For custom startup flags.
Hashtable<String, String> flags = new Hashtable<String, String>();
flags.put(TapjoyConnectFlag.ENABLE_LOGGING, "true");
// Connect with the Tapjoy server. Call this when the application first starts.
// REPLACE THE APP ID WITH YOUR TAPJOY APP ID.
// REPLACE THE SECRET KEY WITH YOUR SECRET KEY.
TapjoyConnect.requestTapjoyConnect(context,AppId_TapJoy, SecretKey_TapJoy,flags);
//TapjoyConnect.getTapjoyConnectInstance().setUserID(""+appPreferences.GetUserID());
// Set our earned points notifier to this class.
TapjoyConnect.getTapjoyConnectInstance().setEarnedPointsNotifier(this);
//LaunchTapJoyOfferwall();
}
#Override
public void earnedTapPoints(int amount)
{
earnedPoints = true;
update_text = true;
displayText = "You've just earned " + amount + " Tap Points!";
// We must use a handler since we cannot update UI elements from a different thread.
System.out.println("displayText :: "+displayText);
OEPUtil.showAppToast(context, displayText);
}
public void LaunchTapJoyOfferwall() {
TapjoyConnect.getTapjoyConnectInstance().showOffers();
}
#SuppressWarnings("deprecation")
public void SetBannerAutoRefresh() {
TapjoyConnect.getTapjoyConnectInstance().enableBannerAdAutoRefresh(false);
}
public void SetShutDown() {
TapjoyConnect.getTapjoyConnectInstance().sendShutDownEvent();
}
}
this class I am accessing in one of my activity class on click of a button.
Please let me know whatever I am doing is correct or not and how can I get points??

This might help you..
http://www.jjask.com/32814/android-tapjoy-offerwall-never-makes-callback
basically
#Override
protected void onResume()
{
TapjoyConnect.getTapjoyConnectInstance().getTapPoints(this);
super.onResume();
}

Related

Null pointer exception in creating a dialog in quickblox [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I having some issue in creating a dialog of type group in quickblox chat service on android. I am able to get all the user from the server side of quickblox, able to build dialog and adding those users i got in it but when it comes to call groupChatManager.createDialog(dialog, new QBEntityCallbackImpl(). I am getting a null pointer exception on that. I found later that i have to initialise chatService in class that extends application i did that but still same error. here is my code
enter code here
My applicationSingeltonClass
public class ApplicationSingleton extends Application
{
private QBUser currentUser;
//quickBlox
private static final String APP_ID = "key";
private static final String AUTH_KEY = "authkey";
private static final String AUTH_SECRET = "authsec";
private static ApplicationSingleton instance;
private Map<Integer, QBUser> dialogsUsers = new HashMap<Integer, QBUser>();
private QBRoomChat currentRoom;
#Override
public void onCreate()
{
super.onCreate();
initApplication();
initImageLoader(getApplicationContext());
}
public static ApplicationSingleton getInstance()
{
return instance;
}
private void initImageLoader(Context context)
{
// This configuration tuning is custom. You can tune every option, you may tune some of them,
// or you can create default configuration by
// ImageLoaderConfiguration.createDefault(this);
// method.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.enableLogging() // Not necessary in common
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
}
public QBUser getCurrentUser()
{
return currentUser;
}
public void setCurrentUser(QBUser currentUser)
{
this.currentUser = currentUser;
}
public Map<Integer, QBUser> getDialogsUsers()
{
return dialogsUsers;
}
public void setDialogsUsers(List<QBUser> setUsers)
{
dialogsUsers.clear();
for (QBUser user : setUsers)
{
dialogsUsers.put(user.getId(), user);
}
}
public void addDialogsUsers(List<QBUser> newUsers)
{
for (QBUser user : newUsers)
{
dialogsUsers.put(user.getId(), user);
}
}
public Integer getOpponentIDForPrivateDialog(QBDialog dialog)
{
Integer opponentID = -1;
for(Integer userID : dialog.getOccupants())
{
if(userID != getCurrentUser().getId())
{
opponentID = userID;
break;
}
}
return opponentID;
}
private void initApplication()
{
instance = this;
QBChatService.setDebugEnabled(true);
QBSettings.getInstance().fastConfigInit(APP_ID, AUTH_KEY,AUTH_SECRET);
}
}
here is my other class were i create a dialog
enter code here
protected void onPostExecute(final Boolean success)
{
if(status.equals("accepted"))
{
pagedRequestBuilder.setPage(1);
pagedRequestBuilder.setPerPage(10);
final ArrayList<String> usersLogins = new ArrayList<String>();
usersLogins.add(userID);
usersLogins.add(herocivID);
final ArrayList<Integer> occupantIdsList = new ArrayList<Integer>();
occupantIdsList.add(civID);
occupantIdsList.add(heroCivID);
QBUsers.getUsersByFacebookId(usersLogins, pagedRequestBuilder, new QBEntityCallbackImpl<ArrayList<QBUser>>() {
#Override
public void onSuccess(ArrayList<QBUser> users, Bundle params)
{
if (!QBChatService.isInitialized())
{
QBChatService.init(getApplicationContext());
chatService = QBChatService.getInstance();
chatService.addConnectionListener(chatConnectionListener);
}
QBDialog dialog = new QBDialog();
dialog.setName("chat with mostafa wo may");
dialog.setType(QBDialogType.GROUP);
dialog.setOccupantsIds(occupantIdsList);
QBGroupChatManager groupChatManager = chatService.getInstance().getGroupChatManager();
groupChatManager.createDialog(dialog, new QBEntityCallbackImpl<QBDialog>()
{
#Override
public void onSuccess(QBDialog dialog, Bundle args)
{
Log.i("", "dialog: " + dialog);
}
#Override
public void onError(List<String> errors) {
Toast.makeText(getBaseContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
}
});
}
#Override
public void onError(List<String> errors)
{
Toast.makeText(getBaseContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
}
});
Toast.makeText(getBaseContext(), "you accepted the request", Toast.LENGTH_SHORT).show();
}
else if(status.equals("rejected"))
{
Toast.makeText(getBaseContext(), "you rejected the request", Toast.LENGTH_SHORT).show();
}
}
i need to know were exactly i have to configure the chat service to prevent the null pointer while creating a dialog.
Any help would be appreciated thank you.
You're right,
chatService.getInstance().getGroupChatManager();
is null if you're not logged in ti Chat
so you have to login to chat first and then call this method
I managed to solve this issue.
First you need to check roomChatManager if its equal to null you have to ask the user to login in.
Second in the login wether your using social provider or by mail you have to login to chatService ( ApplicationSingleton.getInstance().chatService.login(userResult);)
ApplicationSingleton is a java class were it extends Application in it you initialise the ChatService.
Thats it now you can create your dialog successfully.

How to track Omniture Custom Traffic Variable in Android?

In Site Catalyst we have defined Custom Traffic Variable "Item Bought". Now how do i send request to update this custom variable from Android library? i don't find much help here
Please find my code below,
public class TrackingHelper {
private static final String TRACKING_RSID = "MY_TRACKING_RSID";
private static final String TRACKING_SERVER = "MY_TRACKING_SERVER";
static ADMS_Measurement measurement = null;
public static void startActivity(Activity activity) {
measurement = ADMS_Measurement.sharedInstance(activity);
measurement.startActivity(activity);
}
public static void stopActivity() {
measurement = ADMS_Measurement.sharedInstance();
measurement.stopActivity();
}
public static void configureAppMeasurement(Activity activity) {
if (measurement == null) {
measurement = ADMS_Measurement.sharedInstance(activity);
measurement.configureMeasurement(TRACKING_RSID, TRACKING_SERVER);
measurement.setOfflineTrackingEnabled(true);
measurement.setDebugLogging(true);
}
}
public static void trackItemBought() {
if (measurement != null) {
measurement = ADMS_Measurement.sharedInstance();
Hashtable<String, Object> contextData = new Hashtable<String, Object>();
contextData.put("Item Bought", "Item Bought");
measurement.setEvents("Item Bought");
measurement.track(contextData);
}
}
}
I can't vouch for the android code, but here are some general thoughts:
When you send a context data variable, you send a name-value pair, so I suspect this line:
contextData.put("Item Bought", "Item Bought");
Should be something more like this (I'm going to say the item being bought is a basketball):
contextData.put("Item Bought", "Basketball");
Then someone with access to processing rules in SiteCatalyst will need to configure a rule to say that that variable ("Item Bought") belongs to its assigned custom traffic variable (prop14, for instance). http://www.jasonegan.net/2011/04/07/omniture-sitecatalyst-15-context-variables-processing-rules/ talks about how to do that a bit, but the article generally assumes you have a certain level of knowledge of SiteCatalyst.
Just make the following change in your code.
public class TrackingHelper {
private static final String TRACKING_RSID = "MY_TRACKING_RSID";
private static final String TRACKING_SERVER = "MY_TRACKING_SERVER";
static ADMS_Measurement measurement = null;
public static void startActivity(Activity activity) {
measurement = ADMS_Measurement.sharedInstance(activity);
measurement.startActivity(activity);
}
public static void stopActivity() {
measurement = ADMS_Measurement.sharedInstance();
measurement.stopActivity();
}
public static void configureAppMeasurement(Activity activity) {
if (measurement == null) {
measurement = ADMS_Measurement.sharedInstance(activity);
measurement.configureMeasurement(TRACKING_RSID, TRACKING_SERVER);
measurement.setOfflineTrackingEnabled(true);
measurement.setDebugLogging(true);
}
}
public static void trackItemBought() {
if (measurement != null) {
measurement = ADMS_Measurement.sharedInstance();
Hashtable<String, Object> contextData = new Hashtable<String, Object>();
contextData.put("Item Bought", "Item Bought");
measurement.setEvents("Item Bought");
measurement.contextData(contextData);
measurement.track();
}
}

Salesforce Rest API with android - NullPointerException # AsyncRequestCallback

I'm trying to get the Salesforce REST API working with Android and new to android programming, followed the sample code to connect with SFDC http://wiki.developerforce.com/page/Getting_Started_with_the_Mobile_SDK_for_Android#Authentication
I'm trying to get a few records from SFDC and display them in the android app, looks like when the Async Call is made at "client.sendAsync(sfRequest, new AsyncRequestCallback()" - NullPointerException is thrown.
I did see a couple of similar issues online, but didn't help me. Hoping if some one would point me in the right direction to troubleshoot this. Thanks much.
public class GetAccountsActivity extends Activity {
private PasscodeManager passcodeManager;
private String soql;
private String apiVersion;
private RestClient client;
private TextView resultText;
private RestRequest sfRequest;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get Api Version
apiVersion = getString(R.string.api_version);
//Create Query
soql = "select id, name from Account limit 10";
// Setup view
setContentView(R.layout.get_accounts_activity);
((TextView) findViewById(R.id.Acc_Title)).setText(apiVersion);
// Passcode manager
passcodeManager = ForceApp.APP.getPasscodeManager();
}
#Override
public void onResume() {
super.onResume();
//Get SFClient
// Login options
String accountType = ForceApp.APP.getAccountType();
LoginOptions loginOptions = new LoginOptions(
null, // login host is chosen by user through the server picker
ForceApp.APP.getPasscodeHash(),
getString(R.string.oauth_callback_url),
getString(R.string.oauth_client_id),
new String[] {"api"});
new ClientManager(this, accountType, loginOptions).getRestClient(this, new RestClientCallback() {
#Override
public void authenticatedRestClient(RestClient client) {
if (client == null) {
ForceApp.APP.logout(GetAccountsActivity.this);
return;
}
GetAccountsActivity.this.client = client;
}
});
//Get Rest Object to query
try {
sfRequest = RestRequest.getRequestForQuery(apiVersion, soql);
//Use SF Rest Client to send the request
client.sendAsync(sfRequest, new AsyncRequestCallback(){
#Override
public void onSuccess(RestRequest request, RestResponse response){
//Check responses and display results
// EventsObservable.get().notifyEvent(EventType.RenditionComplete);
}//end onSuccess
#Override
public void onError(Exception exception) {
//printException(exception);
EventsObservable.get().notifyEvent(EventType.RenditionComplete);
}//End Exception for Async Method
});
}catch (UnsupportedEncodingException e) {
//printHeader("Could Send Query request");
//printException(e);
return;
}
}
}
enter code here
You are calling client.sendAsync from onResume() but client is not set until the authenticatedRestClient callback is called, you need to move your sendAsync call into the authenticatedRestClient callback.

Issue about using Async with an Android Client

I am currently creating a project that needs to have a simple async task to take care of a thread running behind the scenes. The user needs to login. I am using another class called PVAndroid Client that supplies useful methods and has an XML serializer form packets for me. I am completely new to working with threads or doing anything with servers, so this may be completely wrong or somewhat right.
I get the data the user entered: the ip address and port, their username (I split this into first and last name), their region they selected. I encrypt their password, and attempt to connect to the tcp using ip address and port number. I am trying to work in the async task but am kind of confused on what I should do. Can anyone guide me in the right direction and help me out?
Thank you I really appreciate it.
private TcpClient myTcpClient = null;
private UdpClient udpClient;
private static final String USERNAME_SHARED_PREFS = "username";
private static final String PASSWORD_SHARED_PREFS = "password";
private static final String IP_ADDRESS_SHARED_PREFS = "ipAddressPref";
private static final String PORT_SHARED_PREFS = "portNumberPref";
private String encryptedNameLoginActivity, encryptPassLoginActivity;
private EditText userText, passText;
private String getIpAddressSharedPrefs, getPortNumberPrefs;
private String getUserNameValue;
private String getPasswordValue;
private String fName, lName;
private SharedPreferences settings;
private Editor myEditor;
private boolean getCheckedRemember;
private boolean resultCheck = false;
private int portNum;
private Button submitButton;
private String userMACVARIABLE = "";
private String regionSelected, gridSelected;
private Spinner regSpinner, gridSpinner;
PVDCAndroidClient client;
private int userNum;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
client = new PVDCAndroidClient();
}
#Override
protected void onStart() {
super.onStart();
// Take care of getting user's login information:
submitButton = (Button) findViewById(R.id.submitButton);
userText = (EditText) findViewById(R.id.nameTextBox);
passText = (EditText) findViewById(R.id.passwordTextBox);
regSpinner = (Spinner) findViewById(R.id.regionSpinner);
// grid selected as well? sometime?
regSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View v,
int position, long rowId) {
regionSelected = regSpinner.getItemAtPosition(position)
.toString();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
submitButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
settings = PreferenceManager
.getDefaultSharedPreferences(AndroidClientCompnt.this);
getIpAddressSharedPrefs = settings.getString(
IP_ADDRESS_SHARED_PREFS, "");
portNum = Integer.parseInt(settings.getString(
PORT_SHARED_PREFS, ""));
if (getIpAddressSharedPrefs.length() != 0 && portNum != 0) {
if (userText.length() != 0 && passText.length() != 0) {
try {
try {
// encrypting the user's password.
encryptPassLoginActivity = Secure.encrypt(passText
.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// first connect attempt.
myTcpClient = new TcpClient();
myTcpClient.connect(getIpAddressSharedPrefs,
portNum);
// here is where I want to call Async to do login
// or do whatever else.
UploadTask task = new UploadTask();
task.execute();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Could not connect.", Toast.LENGTH_LONG)
.show();
e.printStackTrace();
}
}
}
}
});
}
private class UploadTask extends AsyncTask<String, Integer, Void>
{
#Override
protected void onPreExecute() {
Toast.makeText(getApplicationContext(), "Loading...",
Toast.LENGTH_LONG).show();
}
#Override
protected Void doInBackground(String... names) {
resultCheck = myTcpClient.connect(getIpAddressSharedPrefs,
portNum);
if (resultCheck == true) {
while (myTcpClient.getUserNum() < 0) {
// num set? session? with proxy server?
}
String[] firstAndLast;
String spcDelmt = " ";
firstAndLast = userText.toString().split(spcDelmt);
fName = firstAndLast[0];
lName = firstAndLast[1];
// set up the tcp client to sent the information to the
// server.
client.login(fName, lName, encryptPassLoginActivity,regionSelected, 128, 128, 20);
} else {
Toast.makeText(getApplicationContext(),
"Connection not successful", Toast.LENGTH_LONG)
.show();
}
return null;
}
#Override
protected void onPostExecute(Void result) {
Toast.makeText(getApplicationContext(), "Connected",
Toast.LENGTH_LONG).show();
}
}
}
First
#Override
protected Void doInBackground(String...params) {
new Thread (new Runnable() {
// ...
}
}
Never do this again. There is no need to create new Thread in doInBackground method which actually running on background Thread. So remove it.
The advice to you is tricky because you need to read about Threads, work with Connection etc. So the best advice to you is to read some tutorials, examples of basic applications and read references. So you can start here:
Android TCP Client and Server Communication Programming–Illustrated with Example
I cannot see, where you are yoursing your Task, but I see that you are doing something weired inside doInBackground()! There is absolutely NO reason, to create your own Thread inside it.
remove that, and you could just use your Task like this:
UploadTask task = new UploadTask();
task.execute("someString", "anotherString", "addAsManyStringsYouNeed");
The docs from AsyncTask are very helpfull, too.

What happen if don't call stop() function in Android Google Analytics?

I've been looking through the code of the GoogleIO Android app and I notice the their did not call stop() function on the GoogleAnalytics' instance. What will happen if we don't call stop()?
This is the code:
package com.google.android.apps.iosched.util;
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
/**
* Helper singleton class for the Google Analytics tracking library.
*/
public class AnalyticsUtils {
private static final String TAG = "AnalyticsUtils";
GoogleAnalyticsTracker mTracker;
private Context mApplicationContext;
/**
* The analytics tracking code for the app.
*/
// TODO: insert your Analytics UA code here.
private static final String UACODE = "INSERT_YOUR_ANALYTICS_UA_CODE_HERE";
private static final int VISITOR_SCOPE = 1;
private static final String FIRST_RUN_KEY = "firstRun";
private static final boolean ANALYTICS_ENABLED = true;
private static AnalyticsUtils sInstance;
/**
* Returns the global {#link AnalyticsUtils} singleton object, creating one if necessary.
*/
public static AnalyticsUtils getInstance(Context context) {
if (!ANALYTICS_ENABLED) {
return sEmptyAnalyticsUtils;
}
if (sInstance == null) {
if (context == null) {
return sEmptyAnalyticsUtils;
}
sInstance = new AnalyticsUtils(context);
}
return sInstance;
}
private AnalyticsUtils(Context context) {
if (context == null) {
// This should only occur for the empty Analytics utils object.
return;
}
mApplicationContext = context.getApplicationContext();
mTracker = GoogleAnalyticsTracker.getInstance();
// Unfortunately this needs to be synchronous.
mTracker.start(UACODE, 300, mApplicationContext);
Log.d(TAG, "Initializing Analytics");
// Since visitor CV's should only be declared the first time an app runs, check if
// it's run before. Add as necessary.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mApplicationContext);
final boolean firstRun = prefs.getBoolean(FIRST_RUN_KEY, true);
if (firstRun) {
Log.d(TAG, "Analytics firstRun");
String apiLevel = Integer.toString(Build.VERSION.SDK_INT);
String model = Build.MODEL;
mTracker.setCustomVar(1, "apiLevel", apiLevel, VISITOR_SCOPE);
mTracker.setCustomVar(2, "model", model, VISITOR_SCOPE);
// Close out so we never run this block again, unless app is removed & =
// reinstalled.
prefs.edit().putBoolean(FIRST_RUN_KEY, false).commit();
}
}
public void trackEvent(final String category, final String action, final String label,
final int value) {
// We wrap the call in an AsyncTask since the Google Analytics library writes to disk
// on its calling thread.
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... voids) {
try {
mTracker.trackEvent(category, action, label, value);
Log.d(TAG, "iosched Analytics trackEvent: "
+ category + " / " + action + " / " + label + " / " + value);
} catch (Exception e) {
// We don't want to crash if there's an Analytics library exception.
Log.w(TAG, "iosched Analytics trackEvent error: "
+ category + " / " + action + " / " + label + " / " + value, e);
}
return null;
}
}.execute();
}
public void trackPageView(final String path) {
// We wrap the call in an AsyncTask since the Google Analytics library writes to disk
// on its calling thread.
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... voids) {
try {
mTracker.trackPageView(path);
Log.d(TAG, "iosched Analytics trackPageView: " + path);
} catch (Exception e) {
// We don't want to crash if there's an Analytics library exception.
Log.w(TAG, "iosched Analytics trackPageView error: " + path, e);
}
return null;
}
}.execute();
}
/**
* Empty instance for use when Analytics is disabled or there was no Context available.
*/
private static AnalyticsUtils sEmptyAnalyticsUtils = new AnalyticsUtils(null) {
#Override
public void trackEvent(String category, String action, String label, int value) {}
#Override
public void trackPageView(String path) {}
};
}
As you can see, they start the tracker with 5 minutes interval mTracker.start(UACODE, 300, mApplicationContext); but never call the mTracker.stop() method. Will there be any consequences? Does it mean the service will dispatch the data even when the app is closed or stopped?
EasyTracker - I found this blog entry in the google analytics blog. There they describe an EasyTracker class, that wraps the normal Tracker class and has some nice features.
Configuration via resource file (no coding needed)
Everything's done in a separate thread (not in the ui-thread as with the normal Tracker)
...
And this EasyTracker does not need to be stopped explicity either.
There shouldn't be happen much -- when you close or stop the app, and even if it still lives in the background and there's no activity anymore, no new data will be gathered (because no one invokes track() anymore. So I think it's just good manners to explicitly stop the tracker.

Categories

Resources