Enabling USB Debugging Mode for Android Devices

Enabling USB Debugging Mode for Android Devices

USB Debugging Mode for Android Device is a must when developing an Android application. It will save you a lot of time when debugging and executing your application. Please note that USB Debugging option might be disabled when your device is already connected to your PC. To enable it, you must disconnect it first and follow the steps given below.

I’m using a Galaxy Tab, so here’s what I did:
Touched Menu Soft Key > Settings > Touch Applications > Development > USB Debugging to be Checked
When you are able to check or enable the USB debugging mode option in your Android device, you would want to verify if your PC also detects it for your development. To do this, we have to follow the some simple steps.

Verify If Android Device is Attached to PC for Debugging

There was time when I was trying to run my Android code to my device but it seemed not working. One of the things I thought that causes this was if my Android device is really connected or attached to my computer. So I had to verify if it was. I’m using windows, so here’s what I did:

1. Execute the command prompt (cmd.exe)

2. Go to your Android SDK platform-tools directory. I had to execute cd c:Program FilesAndroidandroid-sdkplaform-tools in the command prompt

3. Check if ADB is present by executing adb, if you got those data rolled down, ADB is working fine.

4. See if your device is attached by executing adb devices, You should see your attached devices which look like something like this:

Verify If Android Device is Attached to PC for Debugging
Click to enlarge.
If no device was attached, you’ll receive a message of something like “Waiting for device”.


This is also where you can execute the ADB logcat which will make your life easier when debugging your Android App. You can do that by executing adb logcat


So that’s it, you can now run your code from eclipse. :)

How To Scroll Android TextView

Hi there! Today we’re going to do a script that will make a scrolling Android TextView. I found this one useful when I’m testing my other code snippets. The situation is, my text output exceeds the height of my android device screen, I cannot see the whole output unless I make the TextView scrolling.

Let’s rock and scroll! :))

Let’s rock and scroll! :))

We will have the following code on our main activity – ScrollingTextView.java

package com.example.ScrollingTextView;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ScrollingTextView extends Activity {
    TextView tv;
    
    //Called when the activity is first created. 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //textViewWithScroll is the name of our TextView on main.xml
        this.tv = (TextView) this.findViewById(R.id.textViewWithScroll);
        
        //initializing a blank textview
        //so that we can just append a text later
        tv.setText("");
        
        //display the text 10 times
        //so that it will exceed the device screen height
        //and be able to scroll
        for(int x = 1; x < 11; x++ ){
            tv.append("Hi there!n");
            tv.append("Did you know that...n");
            tv.append("I'm handsome? Hahaha! Just kidding.n");
        }
    }
}

And then the following codes on our layout file – main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <ScrollView   
    android:id="@+id/ScrollView01"  
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:layout_below="@+id/DownloadData" >  
    
        <TextView  
        android:text="Text here..."
        android:id="@+id/textViewWithScroll" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"/>
        
    </ScrollView>  
    
</RelativeLayout>

We will have something like this on the output:droidscroll

Thanks for reading this How To Scroll Android TextView!

Multiple Android Button Tutorial

Multiple Android Button Tutorial

Hi guys! Today we’re gonna do an example application of android Push Buttons.

Push-buttons can be pressed, touched, or clicked by the user to invoke an event or action in your application.

This example will show you how to make two android buttons working (you can add more if you want).

It also uses an Android toast so if you’re not yet familiar with it, you may visit also view my post about Android Toasts here.

So, after creating a new project, we will modify two files.

The main activity file, which is in this case, the AndroidButtons.java and the layout file which is the main.xml

AndroidButtons.java

package com.example.AndroidButtons;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class AndroidButtons extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    try {
    View.OnClickListener handler = new View.OnClickListener(){
        public void onClick(View v) {
            //we will use switch statement and just
            //get thebutton's id to make things easier
            switch (v.getId()) {

                case R.id.ShowToastBtn: //toast will be shown
                    Toast.makeText(getBaseContext(), "You Clicked Show Toast Button!", Toast.LENGTH_SHORT).show(); 
                    break;
                case R.id.FinishBtn: //program will end
                    finish();
                    break;
            }
        }
    };
        
    //we will set the listeners
    findViewById(R.id.ShowToastBtn).setOnClickListener(handler);
    findViewById(R.id.FinishBtn).setOnClickListener(handler);
        
    }catch(Exception e){
         Log.e("Android Button Tutorial", e.toString());
    }  
}
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button
    android:layout_width="98px"
    android:layout_height="wrap_content"
    android:text="Show Toast" 
    android:id="@+id/ShowToastBtn">
    </Button>
    
    <Button
    android:layout_width="98px"
    android:layout_height="wrap_content"
    android:text="Finish" 
    android:id="@+id/FinishBtn">
    </Button>
</LinearLayout>

When you run this script it will look like this:

SC20110720-085607

When you click the “Show Toast” Button, it will look like this:

SC20110720-085600

When you click “Finish”, obviously, the program will end. Haha!

Android Toast Tutorial

What is Android Toast? The Android Toast is a view containing a quick little message for the user. When the toast is shown to the user, appears as a floating view over the application so it will never receive focus. The idea is to be as unobtrusive as possible, for example you want to instantly display information to user while they are using the your app. This tutorial will show you how to create a simple Android Toast using the toast class.

Android Toast Tutorial

I feel hungry now. :))

package com.example.AndroidToastTutorial;

import android.app.Activity;
import android.os.Bundle;
//import the toast widget
import android.widget.Toast;

public class AndroidToastTutorial extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //"This is the Toast message" will appear when you run this code
        Toast.makeText(getBaseContext(), "This is the Toast message", Toast.LENGTH_SHORT).show();
    }
}

The output of this code will look like the lower part of the image above (below the android logo and toasted bread). More info here. So that’s it! :)

Fixed: Android requires compiler compliance level 5.0. Please fix project properties.

When I tried to import an existing eclipse android project to my new workspace, I encountered an error:

Android requires compiler compliance level 5.0. Please fix project properties.

So here’s what I did to fix this problem:

Right Click Project > Properties > Java Build Path > Order and Export Tab > Check Your Android SDK Version on the list (I got Android 2.2)

Fixed: Android requires compiler compliance level 5.0. Please fix project properties.

Then…

Right Click Project > Properties > Java Compiler > Check Enable Project Specific Settings > Select Compiler Compliance Level
In my case, I had to changed the compiler compliance level from 1.6 to 1.5

jcompiler

And that solves my problem. :)

Android Fix: Eclipse is loading framework information and the layout library from the SDK folder. main.xml will refresh automatically once the process is finished.

After doing some android coding, I’m supposedly doing some improvement on its user interface. But when I viewed the graphic layout of my main.xml, the black screen did not show up, instead, a message prompted me:

Eclipse is loading framework information and the layout library from the SDK folder. main.xml will refresh automatically once the process is finished.

Android Fix: Eclipse is loading framework information and the layout library from the SDK folder. main.xml will refresh automatically once the process is finished.

Oh no!

I searched google but none of the solutions worked for me. Then I decided to reinstall the Android SDK. I removed it from my control panel and run the android-sdk installer I have (installer_r10-windows.exe). And that solves my problem. I hope this helps someone. :)

Getting Started with Google Android Development

May 2013 Update: How to Install Android Development Environment

I was so happy of the news that I will be working with Google Android Development. Its cool, now I can use my knowledge in Java Programming. I took up one Java Programming course (one semester) when I was in college. So here it is, I wanna share with you my Java comeback experience – with Google Android.

Getting Started with Google Android Development
Getting started too?

Android is an open-source software stack for mobile devices that includes an operating system, middleware and key applications.
If you’re a windows user, follow the these steps (you can at least have an idea here even if you’re not a windows user):
Step 1: Check the system and software requirements for developing Android applications – http://developer.android.com/sdk/requirements.html. If you think your system submits to Android system requirements, proceed to step 2.
 
Step 2: Download the Following:
  • Eclipse –  http://www.eclipse.org/downloads/ (Choose Eclipse IDE for Java Developers which is the first in the list, as of this time, version name to be downloaded is “Eclipse Helios“)
  • Android SDKhttp://developer.android.com/sdk/index.html (Choose the latest version installer_r10-windows.exe which is recommended). The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.  
  • Android Development Tools (ADT) http://developer.android.com/sdk/eclipse-adt.html#installing (I prefer downloading the zip file first (which is ADT-10.0.1.zip as of now), than installing it in default or via URL, it offers less errors). ADT is a plugin for the Eclipse IDE that is designed to give you a powerful, integrated environment in which to build Android applications. ADT extends the capabilities of Eclipse to help you quickly develop new Android projects
    Step 3: Install
    • JDK – I got this file after downloading: jdk-6u24-windows-i586.exe. This is the first one to be installed
    • Unzip Eclipse Helios to your desired location. I placed mine in C:, then create a shortcut of eclipse.exe to desktop so that it will be easy to find and run on next start up of your computer.
    • I got installer_r10-windows.exe for Android SDK. I installed mine in C:ANDROID-SDK. Close Android SDK and AVD manager first if it pops out.
      Step 4: Run your eclipse.exe, when you run it for the first time, workspace launcher will pop out for you to select a workspace directory, I had C:JAVA-WS as my workspace directory then tick the checkbox “Use this as my default workspace” if you want so that workspace launcher won’t pop up on next eclipse start up.
      Step 5: Install ADT Plugin.
      • On eclipse, go to Help > Install New Software then click the Add Button on the pop up. 
      • On the Add Repository pop up, click the Archive Button then browse the ADT Plugin (ADT-10.0.1.zip) we have downloaded earlier, specify a local name (i.e. Android Plugin) then click OK.
      • You can now see the Developer Tools check box, tick it and click the Next Button. Wait for several minutes while it loads.
      • Click on Next > Accept the terms of license agreement > Finish > Eclipse will install the software OR you have to Tick Always run in background check box > Click Run in background button.
      • Wait for eclipse to load/install new software (see the status on the lower right corner). After that it will prompt you to restart eclipse, please restart eclipse. 
      Step 6: Use the android SDK and AVD manager.
      • Set Up android SDK location: Window > Preferences > Browse your SDK Location. Mine is C:ANDROID-SDK since this is where I installed my SDK (third bullet of Step 3).

      Step 7: Install Android Platform
      • On eclipse, go to Window > Android SDK and AVD manager > Select Available Packages on the left bar > Explode Android Repository > Tick the platform that you want to use (I ticked SDK Platform Android 1.6, API 4, revision 3 for now) > Click Install selected > Accept Radio button > Install button > Wait for the platform to be downloaded.
      My next blog could be the undying “Hello World” example — in Android and I’m gonna try to make it more simple.

      If you think I missed something in this post, you can ask about it by leaving a comment below.

        Resources: