Search This Blog

Friday, February 1, 2013

Basic Linux commands

1. To Delete a Directory
with View: rm -rvf .\
without View: rm -rf .\
2. To Tar a Directory
With View: tar –cvzf .tar ./
Without View: tar -cf .tar ./
e.g. To tar Android folder #tar –cvzf android.tar ./android
3. To UnTar a Directory
With View: tar -xvf .tar
Without View: tar -xf .tar
e.g. To Untar Android folder #tar -xvf android.tar
4. To Mount a N/W Drive:
Step 1: Make a folder in Windows drive, share that & provide read/write premission e.g. "androidsrc" folder is created in Windows drive & same is shared also with R/W premissions.
Step 2: Make a folder in Linux System that you want to mount to Windows system e.g. "test" folder is created in Linux Machin.
Step 3: Go to Linus PC & Run below mentioned command
smbmount /// ./
e.g. smbmount //10.168.82.159/androidsrc ./test

5. To Remove Some files from a Folder Structure:
e.g. remove all git & gitignore files from Android folder (it will remove all git files)
.../Android$ find ./ -name ‘.git’ xargs rm –rvf
.../Android$ find ./ -name '.gitignore' xargs rm -rvf

Set IP & Gateway

Set IP:
sudo ifconfig eth0 <IP>

Set Gateway:
sudo route add default gw <gw-IP> eth0

To check IP:
ifconfig

e.g. To set IP (192.168.100.105) & Gateway (192.168.100.1)
sudo ifconfig eth0 192.168.100.105
sudo route add default gw <192.168.100.1> eth0

p.s.: eth0 is for default Network card. So, by using eth0; mentioned IP & Port will be set for LAN.

Friday, June 22, 2012

JNI

Pass String as parameter from Android code to Java Native Code
Android Java Code:
public static final String JNI_LIB_NAME = "sampleJniLibrary";
public class JNIClass {
static {
              System.loadLibrary(JNI_LIB_NAME);
       }
    public native void addClientList(String userName, String password,
                     String ipAddress, int mode);
}
JNI C Code:
Void
Java_com _android_sample_JNIClass_addClientList( JNIEnv* env, jobject thiz, jstring user, jstring passwd, jstring ip, jint ipermission )
{
     const char *tuser;
     const char *tpasswd;
     const char *tip;
     int tipermission;
     tuser = (*env)->GetStringUTFChars(env, user, 0);
     tpasswd = (*env)->GetStringUTFChars(env, passwd, NULL);
     tip = (*env)->GetStringUTFChars(env, ip, 0);
     tipermission =  ipermission;
     // do required operation
     add_client_list(tuser, tpasswd, tip, tipermission);
     //release resources when done
     (*env)->ReleaseStringUTFChars(env, user, tuser); 
     (*env)->ReleaseStringUTFChars(env, passwd, tpasswd);    
     (*env)->ReleaseStringUTFChars(env, ip, tip);    
     return;
}

Model Number & Android Version

String modelNumber = android.os.Build.MODEL
String version = android.os.Build.VERSION.RELEASE

Tuesday, December 13, 2011

Google Analytics

To start with Google Analytic, We must have have an Google account & We need to get a unique key that will be used in code to trace events. Follow below mentioned process to achieve it.

At Web side (Google):

1. Create an account on http://www.google.com/analytics/

2. Select Setting button & add a new Account

3. Provide Account name, URL, Time Zone & Press "Create Account"

4. Now you will get a "Web Property ID"; this key we need to use at code level.

5. Now download the required lib from below path

http://code.google.com/apis/analytics/docs/mobile/download.html

At code side:

Set Environment (for Eclipse):

1. Get libGoogleAnalytics.jar

2. Go to Properties - > Java Build Path & select Add external jar.

3. Provide the path of libGoogleAnalytics.jar & add it.

Changes in Code:

1. Add permission in AndroidManifest.xml manifest file.

2. Start session in onCreate & End Session in onDestroy

public void onCreate()

{

super.onCreate(savedInstanceState);

tracker = AnalyticsTracker.createInstance();

tracker.start("<GOOGLE ANALYTICS ACCOUNT ID>", this);

}

public void onDestroy()

{

super.onDestroy();

// manually dispatch tracker

tracker.dispatch();

// Stop tracker.

tracker.stop();

}

Your application is linked to google account & it's ready to track page views and event. To do the same, use its API set. Basic use of them is shown below

To Trace Events:

tracker.trackEvent( Category, Action, Label, Value);

e.g. tracker.trackEvent("Category Name", "Action Name", "", 0);

To Trace Page Views:

tracker.trackPageView("");

Useful Link:

http://code.google.com/apis/analytics/docs/mobile/android.html

Flurry Analytics

To start with Analytics, we need to make an account & need to do changes at code side to send events to account. Need to follow below process step by step to achieve it.

At Web side (Flurry):
1. Create an account on http://www.flurry.com/dev/signup.html
2. Add an application & select Android (for Android application developers)
3. Provide Application name & Category.
4. Now you will get a unique "application key"; this key we need to use at code level.
5. Now download the Flurry SDK for android.

At code side:
Set Environment (for Eclipse):

1. Get FlurryAgent.jar
2. Go to Properties - > Java Build Path & select Add external jar.
3. Provide the path of FlurryAgent.jar & add it.
Changes in Code:
1. Set permission in manifest file for android.permission.INTERNET
2. Start session in OnStart & End Session in onStop.
public void onStart()
{
super.onStart();
FlurryAgent.onStartSession(this, "");
}
public void onStop()
{
super.onStop();
FlurryAgent.onEndSession(this);
}

After this your application will be linked to Flurry account.
Now to trace various Events & to get Page Counts, use API set of FlurryAgent at required place at code level & you will get complete details in your web Flurry account.

Import APIs:
To Trace Events:
FlurryAgent.logEvent (String eventId)
FlurryAgent.logEvent (String eventId, boolean timed)
FlurryAgent.logEvent (String eventId, Map parameters)
FlurryAgent.logEvent (String eventId, Map parameters, boolean timed)

e.g.
final HashMap parameters = new HashMap();
parameters.put("Event","myEventName");
FlurryAgent.logEvent("EVENT_ID", parameters);

To Trace Page Views:
FlurryAgent.onPageView();

Useful Link: https://dev.flurry.com/android_uploadNewVersion.do?projectID=135549

Monday, October 24, 2011

Convert String Encoding type from ISO to UTF-8

Break string to Bytes using current string encoding format and then arrange those bytes in required encoding format.
e..g. Here, statusLine, errorCode and errorMsg are the string in ISO format & o/p will be in UTF-8 format.
String encodedStatusLine = new String(statusLine.getBytes( iso-8859-1 ), utf-8);
String encodedErrorCode = new String(errorCode.getBytes( iso-8859-1 ), utf-8);
String encodedErrorMsg = new String(errorMsg.getBytes( iso-8859-1 ), utf-8);