How to create MobileFirst analytics log in native Android app? - android

I'm trying to write custom analytics log in native Android app. I don't see it in Analytics console. What could be wrong?
I use following code:
public void logEvent(View view) {
WLAnalytics.enable();
String json = "{\"package\": \"mfpStart\" }";
try {
WLAnalytics.log("Custom event", new JSONObject(json));
} catch (JSONException e) {
e.printStackTrace();
}
WLAnalytics.send();
}
Thanks in advance!

You have to make sure you are calling WLAnalytics.setContext(context) for example on your Activity's onCreate method do something like.
class YourActivity extends Activity {
public void onCreate(Bundle bundle) {
// other code
WLAnalytics.setContext(this);
}
}

Related

Cordova app with integrated plugin on webview crash when try to exit plugin webview (android test)

I have a problem when i try to go back from a cordova plugin integrated on cordova. When i try to do it, the app crashes, I debugged first the javascript and then the native code that javascript call and this is the instruction that make app crash.
cordova.getActivity().finish();
This is in TestPlugin.java file in this most global context:
if (action.equals("open")) {
try {
cordova.getThreadPool().execute(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(cordova.getActivity(),
PhemiumEnduserActivity.class);
cordova.getActivity().startActivity(intent);
cordova.getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
});
callback.success("");
} catch (final Exception e) {
callback.error(e.getMessage());
}
}
else if( action.equals("exit_app") ) {
try {
cordova.getThreadPool().execute(new Runnable() {
#Override
public void run() {
cordova.getActivity().finish();
}
});
callback.success("");
} catch (final Exception e) {
callback.error(e.getMessage());
}
}
When the app calls the plugin executes the "open" part and when i click the back button makes the "exit_app" part and then on cordova.getActivity().finish(); app crashes with no error on the android studio console. There is no signal of webview close. What i'm doing wrong? Why it crashes?
Please post full plugin code or repository, but i think is because you try to finish activity in another thread, or activity no more exist (getActivity return null).
You need to try with somewhat like this:
protected Activity mActivity;
....
else if( action.equals("exit_app") ) {
mActivity = cordova.getActivity();
try {
cordova.getThreadPool().execute(new Runnable() {
#Override
public void run() {
if(mActivity!=null)
mActivity.finish();
}
});
callback.success("");
} catch (final Exception e) {
callback.error(e.getMessage());
}
}
For more trace info try to open android project in Android studio and debug it.

Windows Azure Service Client

I'm trying the my Azure Mobile Service. Below is the code to make a new ToDo item entry. The sample Android code shows how to create a mobile client. I added it to the onCreate method as mentioned in the example.
But the insert always fails. I always get an exception which says com.microsoft.windowsazure.mobileservices.MobileServiceException: Error while processing request.
mClient does get initialized. But, mClient.mCurrentUser is null. Not sure if this is a problem.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
mClient = new MobileServiceClient("https://myservice.azure-mobile.net/",
"slkerjasfi234eSomePrivateKey", this);
Item item = new Item();
item.setText("Awesome item");
item.setComplete(false);
mClient.getTable(Item.class).insert(item,
new TableOperationCallback<Item>() {
public void onCompleted(Item entity,
Exception exception,
ServiceFilterResponse response) {
if (exception == null) {
ShowMessage("Success");
} else {
ShowMessage("Failed");
}
}
});
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
In my case, it looked like the key (parameter 2 in MobileServiceClient constructor) was incorrect. That is how I had downloaded it though. It happened again today and I manually fixed the key and it worked for another service. Believe it was the same issue here. To view your key, you go to your service in Azure and click Manage Keys at the bottom.

One of my Application's view inside my second application in android

I got stuck in to the problem where I need to show my first application in to some area of second application's screen. Both codes are under my control. Can any one suggest me where should I proceed as I am not getting any clue about the situation.
if some one help me for the issue, it would be a great help for me.
Or
If I can open both of my applications using the multiscreen option available in S3.
Write a service on either of your application or a individual application. Have AIDL(Android Interface Definition Language) defined as IRemoteService.aidl, the below is my pseudo code or sample implementation. Using this approach you can start activity and handle events of another application through your application.
// IRemoteService.aidl
// Declare any non-default types here with import statements
/** Example service interface */
interface IAccountService {
String getLoggedInUserInfo(String appId);
void userLogin(String appId,ILoginCallback cb);
void signout(String appId);
}
interface ILoginCallback {
void loginSuccess(String userId);
void loginFailed();
}
In your service have some RemoteCallbacks
#Override
public IBinder onBind(Intent intent) {
final RemoteCallbackList<ILoginCallback> mCallbacks = new RemoteCallbackList<ILoginCallback>();
if(mCallbacks!=null){
int i = mCallbacks.beginBroadcast();
while(i>0){
i--;
try {
Log.e(TAG, "Callback ...");
mCallbacks.getBroadcastItem(i).loginSuccess(newUserId);
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing
// the dead object for us.
}
}
mCallbacks.finishBroadcast();
}
}
private final IAccountService.Stub mBinder = new IAccountService.Stub() {
#Override
public void userLogin(String appId,ILoginCallback cb) throws RemoteException {
String userId = Settings.getSettings().getUserId();
if(userId ==null||userId.length()==0){
mCallbacks.register(cb);
Intent intent = new Intent(getApplicationContext(), AccountLoginActivity.class);
intent.putExtra("deviceId", Settings.getSettings().getDeviceUniqueId());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
You can find detailed AIDL examples in the below links.
http://owenhuangtw.pixnet.net/blog/post/23760257-android-aidl-(android-interface-definition-language)
http://www.app-solut.com/blog/2011/04/using-the-android-interface-definition-language-aidl-to-make-a-remote-procedure-call-rpc-in-android/
https://github.com/afollestad/aidl-example

LibGDX inside Android Activity

I'm in the middle of developing a small app for Android using the Android UI and activities for the most part of the interaction, however one key aspect requires the use of LibGDX (using 3D models and physics). I want to be able to click a button in my app (my "Activate" class) which will open the "AndroidApplication" class (my "Bobble" class) that initializes and runs all the LibGDX code.
My problem is that I can't use an "Intent" to start an AndroidApplication class (only an Activity as far as I can tell). I'm sure that people have had to work around this issue in the past so any help would be fantastic.
Here's my code so far:
public class Activate extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
setContentView(R.layout.activate_screen);
Button b_Run = (Button) findViewById(id.bActiveRun);
b_Run.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent to_Bobble = new Intent(v.getContext(), Bobble.class);
startActivity(to_Bobble);
}
});
}
catch (Exception e)
{
Log.e("Activate", "Error in activity", e);
Toast.makeText(getApplicationContext(),
e.getClass().getName() + " " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}
public class Bobble extends AndroidApplication {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LifeCycle loop = new LifeCycle();
loop.ddgSettings = new ddgSystemSettings(this);
initialize(loop, false);
}
}
Ok I can now confirm that there is no issue at all with the above code. The issue was that I hadn't declared my "Bobble" class/file in the AndroidManifest file, and that was causing the runtime error.

logOut from Facebook in Android Phonegap

I have successfully setup the Facebook Plugin by Jos located (https://github.com/jos3000/phonegap-plugins/tree/master/Android/Facebook) - but I can't seem to figure out a way to log the user out. Sure I could tell them to delete the App access on the website then try to login again and click on "Not you?" but I would really rather have a JS Function that does it for me.
Can anyone help provide some guidance on how to do this? I've looked through the files and it looks like there is a way to do it in the facebook.java but I just need to hack something together to connect it to webview. I'm not capable of doing so :) can anyone please help?
This solution is to disable the single sign on feature in the Facebook plugin
in FaceBook.java file
replace DEFAULT_AUTH_ACTIVITY_CODE in the Authorize method [2 overloads] by FORCE_DIALOG_AUTH
in FacebookAuth.Java file
append this to execute method [in the switch case section]
else if (action.equals("performLogout")){
this.performLogout(first);}
//Add this method to FacebookAuth.java class
public void performLogout(final String appid) {
Log.d("PhoneGapLog", "LOGOUT");
final FacebookAuth fba = this;
Runnable runnable = new Runnable() {
public void run() {
fba.mFb = new Facebook(appid);
fba.mFb.setPlugin(fba);
try {
fba.mFb.logout((Activity) fba.ctx);
fba.success(new PluginResult(PluginResult.Status.OK, ""), fba.callback);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
};
this.ctx.runOnUiThread(runnable);
}
//in facebook.js file add the following section
Facebook.prototype.Logout = function(app_id,callback){
PhoneGap.exec(callback,null, "FacebookAuth", "performLogout", [app_id]); };
// in your page add the following code
function LogoutClick() //on logout click
{
appId = "123" ; //your app Id
window.plugins.facebook.Logout(appId,CompleteLogout);
}
function CompleteLogout() //call back function
{
//do some logic for callback
}
//Enjoy..!!

Categories

Resources