Category Archives: Android

Implement C/ C++ Lib using ANDROID NDK on Android

Android uses Java as it’s native programming language. The developers should use Java to develop Android app. Unfortunately, in some case developers can’t use Java to develop. For example : to communicate with network protocol interface/ radio interface, developers better use C/ C++ library or write an Android program using C/ C++. In order to make it works, we will use Android NDK.
“The NDK is a toolset that allows you to implement parts of your app using native-code languages such as C and C++. For certain types of apps, this can be helpful so you can reuse existing code libraries written in these languages, but most apps do not need the Android NDK (taken from developers.android.com)”. Here is the steps how to do that.
1. Download Android NDK here : https://developer.android.com/tools/sdk/ndk/index.html
2. After download Android NDK, I got following file android-ndk-r10c-windows-x86_64.exe
3. Move the file into sdk directory of your Android Studio Installer

4. Just click the file, it will extract it self.
5. After self extraction successful, we will have file and directory like following

6. Create simple project using Eclipse ADT or Android Studio like following.



7. Create a directory called ‘jni’ within the root application. Like following

Jni ==> java native interface
8. Within jni directory, create a file called jni.h ( this file contains header ) and type following.
===> continue

Fetching Drop Call Event Issue on Android 2.3 above

Drop call event is an event that occurred when an active call is cut. Whether it is cut from caller or recipient or something else that cause the event occurred. Nowadays, there are many programming forums talking about the issue “how to get drop call cause event on android”. But unfortunatelly, they can’t answer the question correctly, even though there are a few people that almost give good answer ( that’s what I tough ). As we know that there are many drop call causes from explanation of android API it self. But in this case, the main problem is Android API that provide drop call cause is no more available on Android 2.3 or above. Because Google has made it to be hidden API from package android.telephony.
A few week ago, I also looking for the solution about this issue. I had done some small research to solve it. Based on my research, I’ve founded 3 solutions for this issue. The first is by accessing radio interface layer on Android ( we can use RIL ) . The second is by reading logcat from the device it self. The third is by using radio command ( AT Command ) to directly communicate through modem device. In this opportunity, I’d like to share you how to get drop call cause with the second idea which is by reading logcat.
1. Giving root access to Android device. We can use Kingo Root application
2. Create android project ( I use Android Studio ) with blank activity. Because we will create the activity.xml later.
MyActivity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:id="@+id/btReadLog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start Listening"/>

    <Button
        android:id="@+id/btClearLog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Clear Log"/>  
</LinearLayout>

DropCallCause.java

public class ActDropCallCause extends Activity {

    private List<String> dropCallCauseList;
    private Button btReadLog;
    private Button btClearLog;   
    Calendar now;
    Calendar afterXSecond;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.myactivity);
        btReadLog = (Button) findViewById(R.id.btReadLog);
        btReadLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                readDropCallCauseList();
            }
        });

        btClearLog = (Button) findViewById(R.id.btClearLog);
        btClearLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doClearLog();
            }

        });        
    }
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.drop_call_cause, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void doClearLog() {
        try {
            Runtime.getRuntime().exec("logcat -c");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /*Reading Logcat OnDisconnect Event ( Dropped Call ) for the last 5 minutes*/
    public void readDropCallCauseList(){
        dropCallCauseList = new ArrayList<String>();
        doClearLog();
        try {
            Process process = Runtime.getRuntime().exec("su -c logcat");
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            afterXSecond = Calendar.getInstance();
            afterXSecond.add(Calendar.SECOND, 60);
            now = Calendar.getInstance();

            while ( ( (line = bufferedReader.readLine()) != null ) && ( now.getTime().compareTo(afterXSecond.getTime()) <= 0 ) ) {
                if ( (line.contains("CallNotifier")) && line.contains("onDisconnect: cause")) {
                    Log.d("INCREMENT", String.valueOf(dropCallCauseList.size()));
                    line = new Date().toString()+line;
                    line=line.replace("/", ":").trim();
                    line = line.replaceAll("\\s+", "");
                    dropCallCauseList.add(line+"::");
                    Log.d("DCC", line);
                }
                now = Calendar.getInstance();
            }
            doClearLog();
            Log.d("SCHEDULER DCC", "CLEAR LOG");
            sendDropCallCause();
            Log.d("SCHEDULER DCC", "SENDING DCC");
            dropCallCauseList.clear();
            readDropCallCauseList();
            Log.d("SCHEDULER DCC", "START READING DCC");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

3. Run the project as Android application and do simulation.

Note : all solutions that I said above require root access to the device.

Moving on Android

android

image taken from : http://livewire.talkingpointsmemo.com/entry/google-android-mascot-concept-sketches-published

A few days ago i bought a new mobile phone. this is the first time for me buying an expensive enough stuff by my self, i use my own money. i bought Sony Xperia Sola, Besides having nice appearance, it also has great performance inside.for summary the processor is dual core, with ginger bread android operating system, 8 Mega pixel camera and many more features. even though the latest android recently is ice cream sandwich (4.0), i still can upgrade it, cause it can handle that operating system.For android user, first thing that needs to be done is synchronize the device with any accounts whether from internet, old mobile phone also from computer. So, this is all about integration. We can access all of our settings only in simple touch, thank you android 🙂

My First Android Apps

About 2 weeks ago, I really intend to learn android and how to  make it works on computer. Actually, there are several steps to install android on our computer .

First , just install the SDK (software development kit)

Second, install eclipse ide.

Third, install adt plugin on eclipse. That’s it then, you’ll be able to develop android apps on your machine

Here is the preview of my first app