Articles

Linux command for android

In Android on March 28, 2012 by Mamunar Rashid

1.Go to cmd
2.Go to then directory where adb resides
Command: cd C:\Program Files\Android\android-sdk\tools
3.Then type adb shell

If you set android-sdk\tools your user environment variable. then go cmd and type “adb shell

If you get ‘#’ after typing adb shell, you are already get root access on the phone, no need to type su. Otherwise if you get ‘$’ , type ’su’ to get root access (only for rooted device).

If we want to see how many command support in android:

# cd /system/bin/
cd /system/bin/
# ls
ls
svc
bootanimation
date
rmmod
vold
rtp_test
ndc
toolbox
stagefright
run-as
netd
kill
system_server
sdcard
wipe
ifconfig
radiooptions
updater
mv
am
netstat
recovery
logwrapper
surfaceflinger
mkdir
qemu-props
nandread
bmgr
ime
dexopt
sync
ls
gzip
gdbserver
vmstat
keystore_cli
debuggerd
ps
fsck_msdos
rild
applypatch_static
sendevent
hd
keystore
pppd
schedtop
setconsole
InputReader_test
start
dumpsys
applypatch
ObbFile_test
lsmod
racoon
InputChannel_test
netcfg
ionice
rm
smd
notify
omx_tests
qemud
id
ioctl
showlease
ping
dvz
chown
cmp
vdc
newfs_msdos
record
testid3
getevent
gdbjithelper
dmesg
linker
route
chmod
printenv
umount
bugreport
iftop
input
String8_test
monkey
pm
dumpstate
app_process
dhcpcd
logcat
check_prereq
InputDispatcher_test
rmdir
setprop
ln
top
flash_image
insmod
sleep
dalvikvm
dd
Looper_test
uptime
servicemanager
lsof
service
df
reboot
sh
mtpd
InputPublisherAndConsumer_test
stop
watchprops
schedtest
cat
skia_test
installd
renice
log
getprop
mount
mediaserver
audioloop
#

Don’t just randomly try commands. Some delete things so know what you are doing.
ls - lists all files with in a directory try ls – l too.

chmod - give/take rights away from files. The numbers you see in the how-to’s is a little complicated. It has to do with the rights you are assigning the file or folder. http://wiki.linuxquestions.org/wiki/Chmod for further reading.

cat – look at, modify, or combine a file. You can also copy files with this command by “reading” it to another file instead of to the screen.

cd - change from one directory to another

cp - Copy a file from one location to another

dd - copies exact locations to other locations. Can be an entire drive, a folder, etc. dd if= of=. uses an input file and an output file.

exit - exits the shell you are in. When you type su you start up a shell.

mv - Move a file from one location to another. At the same time you can rename a file.

su - Substitute User. We type this to switch to the root user. You need to type this command first to do a lot of the other commands.

tar - creates taped archives. Compresses files like winzip, 7zip, winrar and others tar /? for details.

rm - followed by a file name with delete the file

sync - synchronizes any data on disk with data in memory. We type this before rebooting to ensure we’ve got all data written

Other commands of interest:
df - how much free disk space. In linux you can add a switch “df -h” but the “-h” does nothing for me on Android.

top - like task manager, it displays running processes. in Linux the q key quits. On Android I don’t know how to make it quit other than closing the app.

uptime - displays how long it has been since you last rebooted the system. Interestingly enough the “Menu Key > System > About Phone > Status > Up time” on my phone does not match “uptime” typed in the terminal emulator.

busybox - a tool that combines many linux commands into a single compact file. Typing this displays all the commands at your disposal.

busybox df – a much easier to read display of free diskspace. This display shows how full (use%) each file system is.

Install application

You can use adb to install aplication from your local drive into phone.
Command: adb install appname.apk

Articles

How to solve PermGen space Error in eclipse?

In Software Engineering on March 21, 2012 by Mamunar Rashid

1.Open the configuration file named “ eclipse.ini
2.Add command   ” -XX:MaxPermSize=512m  ”   below   “-vmargs”  line.
3.Save it and restart Eclipse IDE.

related links:
Eclipse.ini
How do I increase the heap size available to Eclipse

Articles

How to show all video file stored in your sd card in a listview

In Android on February 17, 2012 by Mamunar Rashid

1. Create a layout for VideoList named 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">
<ListView
android:id="@+id/PhoneVideoList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

2. Create a layout for list item named listitem.xml


<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">

<ImageView android:id="@+id/imgIcon"
android:layout_width="60dip"
android:layout_height="60dip"
android:paddingLeft="10dip"
android:paddingRight="10dip"/>

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="10dip">

<TextView android:id="@+id/txtTitle"
android:layout_width="250dip"
android:layout_height="wrap_content"
android:gravity="left"
android:textStyle="normal"
android:textSize="15dp"
android:textColor="#FF0000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />

<TextView android:id="@+id/txtSize"
android:layout_width="250dip"
android:layout_height="wrap_content"
android:gravity="right"
android:textStyle="italic"
android:textSize="12dp"
android:textColor="#00FF00" />
</LinearLayout>
</LinearLayout>

3. Then create a activity named VideoStoredInSDCard


public class VideoStoredInSDCard extends Activity
{
private Cursor videoCursor;
private int videoColumnIndex;
ListView videolist;
int count;
String thumbPath;

String[] thumbColumns = { MediaStore.Video.Thumbnails.DATA,MediaStore.Video.Thumbnails.VIDEO_ID };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initialization();
}

private void initialization()
{
System.gc();
String[] videoProjection = { MediaStore.Video.Media._ID,MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY_NAME,MediaStore.Video.Media.SIZE };
videoCursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,videoProjection, null, null, null);
count = videoCursor.getCount();
videolist = (ListView) findViewById(R.id.PhoneVideoList);

videolist.setAdapter(new VideoListAdapter(this.getApplicationContext()));
videolist.setOnItemClickListener(videogridlistener);
}

private OnItemClickListener videogridlistener = new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,long id)
{
System.gc();
videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
videoCursor.moveToPosition(position);
String filename = videoCursor.getString(videoColumnIndex);
Log.i("FileName: ", filename);
//Intent intent = new Intent(VideoActivity.this, ViewVideo.class);
//intent.putExtra("videofilename", filename);
//startActivity(intent);
}};

public class VideoListAdapter extends BaseAdapter
{
private Context vContext;
int layoutResourceId;

public VideoListAdapter(Context c)
{
vContext = c;
}

public int getCount()
{
return videoCursor.getCount();
}

public Object getItem(int position)
{
return position;
}

public long getItemId(int position)
{
return position;
}

public View getView(int position, View convertView, ViewGroup parent)
{
View listItemRow = null;
listItemRow = LayoutInflater.from(vContext).inflate(R.layout.listitem, parent, false);

TextView txtTitle = (TextView)listItemRow.findViewById(R.id.txtTitle);
TextView txtSize = (TextView)listItemRow.findViewById(R.id.txtSize);
ImageView thumbImage = (ImageView)listItemRow.findViewById(R.id.imgIcon);

videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
videoCursor.moveToPosition(position);
txtTitle.setText(videoCursor.getString(videoColumnIndex));

videoColumnIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
videoCursor.moveToPosition(position);
txtSize.setText(" Size(KB):" + videoCursor.getString(videoColumnIndex));

int videoId = videoCursor.getInt(videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
Cursor videoThumbnailCursor = managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID+ "=" + videoId, null, null);

if (videoThumbnailCursor.moveToFirst())
{
thumbPath = videoThumbnailCursor.getString(videoThumbnailCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
Log.i("ThumbPath: ",thumbPath);

}
thumbImage.setImageURI(Uri.parse(thumbPath));

return listItemRow;

}

}

}

Articles

How to write Spash screen In Android Application in simplest way

In Android on February 15, 2012 by Mamunar Rashid

1. First create an activity and layout  for Splash activity .

2.Then set this activity as luncher and main activity in then AndroidManifest.xml file.


<activity android:name=".SplashScreenActivity" >
    <intent-filter >
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

4. Then create a layout for your splash activity in your application layout folder  and set it to you Splash screen activity’s layout by setContentView(R.layout.splash)  method.

5.Let assume the  name of spalsh screen is “SplashScreenActivity “. then write the following code here.


public class SplashScreenActivity extends Activity
{
   private final int  SPLASH_TIME = 3000;
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.splash);

       new Handler().postDelayed(new Runnable()
       {
            @Override
            public void run()
            {
               Intent mainScreen = new Intent(getApplicationContext(),MainActivity.class);
               startActivity(mainScreen);
               finish();
            }
       }, SPLASH_TIME );
    }
}

Articles

How to Add Option Menu in an specific activity

In Android on February 9, 2012 by Mamunar Rashid

1.if  you have not any menu folder in your Application architecture’s directory  , then just right click to you application root folder then

go to New-> Android XML

2.The you see a pop up window named “New Android XML File”. Select “Menu” from Resource type drop down.then give tour menu layout file name in “File” text filed such as : mainmenu.xml .then click finish.the you will see  a folder named “menu” is created under your res/ directory.and your menu layout xml resides thats.if a menu folder created earlier then you just make a right click on it and go to New->Android XML and follow the process.

then edit the menu layout file like that:

<?xml version="1.0" encoding="utf-8"?>
  <menu xmlns:android="http://schemas.android.com/apk/res/android" >
       <item android:id="@+id/menu1"
             android:title="Menu 1">
       </item>
       <item android:id="@+id/menu2"
             android:title="Menu 2">
       </item>
 </menu>

3.Overwrite this two  function into the activity class where you want to make option menu.we have to inflate the mainmennu.xml layout into Menu view objects tree. [inflate means converting  XML layout specification into the actual tree of View objects of that layout]


@Override
 public boolean onCreateOptionsMenu(Menu inflatedMenu)
 {
     //to infate menu we need MenuInflater.
     MenuInflater inflater = getMenuInflater();
    // then inflate the mainmenu.xml to menu object name "inflatedMenu"
     inflater.inflate(R.menu.mainmenu,inflatedMenu);
     return true;
}

4.After creating the menu we need to add some action when the menu item selected.for this we need to override the “onOptionsItemSelected(MenuItem item)” callback fuction of this specific activity.

@Override
 public boolean onOptionsItemSelected(MenuItem item)
 {
     switch (item.getItemId())
     {
        case R.id.menu1:
             Toast.makeText(this, "You pressed the menu1!", Toast.LENGTH_LONG).show();
             break;
        case R.id.menu2:
             Toast.makeText(this, "You pressed the menu2!", Toast.LENGTH_LONG).show();
             break;
     }
     return true;
}

Quotes

About Me

The dark side of the moon is no different than the side which deflects light on us. It is our point of view which makes us, our lives, the world different.
Some would like to escape from the dark and some die tying to find the dark side.The meaning of being lost is not a hopeless beginning, rather is a chance to find and taste it again.
I am none of them. I am just lost in the dark trying to find the light. The more I try to get to the light, the far it gets away from me, as if it is a secret, the more it tells you the less you know.
I am just a lost soul in maze of abstraction and reality.

Posted March 16, 2011 by Mamunar Rashid

Articles

Test Driven Development

In Software Engineering on October 28, 2008 by Mamunar Rashid

I’m now working in Test Driven Development(TDD). It is really awesome. bcz i dont need to take extra look at bug fixing and the code is robust, feature  of software component is more specified…….

I’m happy with TDD…….:-)

Follow

Get every new post delivered to your Inbox.