shailesh@shailesh-desktop:~$ adb -e shell rm -r /mnt/sdcard/*
Friday, June 29, 2012
How to format the SDCard through ADB in Android?
shailesh@shailesh-desktop:~$ adb -e shell rm -r /mnt/sdcard/*
Tuesday, June 19, 2012
Troubleshooting Android’s ‘adb devices’?
I’ve
been playing around a bit with Android development lately, and —
for the second time — spent a while trying to work out why
adb
devices
wasn’t
showing me anything:$ adb devices
List of devices attached
$
Thanks,
adb. I’m pretty sure I’ve got a Dream plugged in there, you know.
I did get it working in the end, so I thought I’d write up some of
the troubleshooting steps so that I’ll have something to refer to
the next time
I run into this problem.
First
off, it’s worth mentioned that if you’re on Windows, you
apparently need to install
some USB drivers first
(and it appears that the 32-bit and 64-bit versions aren’t
compatible, so you need to pick the right version too). I’m not
using Windows, though, so I don’t know a whole lot about this step.
However,
life’s not all rosy on Linux: the
adb
command
scans /dev/bus/usb/
rather
than /proc/bus/usb/
(as
provided by usbdevfs) or /sys/bus/usb/
(ditto,
sysfs). This is absolutely the right thing to do (lsusb
works
the same way), but it means that there’s another step (udev)
between the device detection and being able to use the device.
Evidently
some of the default udev rules (possibly only on some distributions;
in particular, on Ubuntu) create device nodes that aren’t
world-readable, meaning that the device node is created, but adb
can’t read it. The easiest way to tell whether you’re having this
problem is to kill the adb daemon and restart it as
root
:$ adb kill-server
$ sudo adb start-server
* daemon not running. starting it now *
* daemon started successfully *
$ adb devices
(The
adb daemon appears in
ps
as “adb
fork-server server
”,
by the way.) I’ve also seen suggestions that you should be able to
runsudo
adb devices
to
start the server as root, but when I tried that I ended up with a
daemon running as myself again.
If
this is your problem, the fix is mentioned on the setup
page.I
mentioned previously: you create a file called something
like
/etc/udev/rules.d/51-android.rules
that
contains rules telling udev to make the device node world-writable
when a matching device is found.
The
example rule provided in the Developer Guide matches any HTC devices,
which might be a bit wide-ranging: you could presumably restrict the
match to just the device’s id. (The HTC Dream and Magic share the
same device id,
0bb4:0c02
,
or, strangely,0bb4:0c01
when
booting into HBOOT/fastboot mode.)
Finally,
there’s one very important thing that I’d completely forgotten
about: if the devices appears in
lsusb
output
but adb
devices
still
shows nothing,check
that the phone is set up to allow debugging via
USB(Settings⇒Applications⇒Development⇒USB
debugging). If this is off, you’ll see nothing… and that was the
step I’d forgotten about.
Things
went much better after that: I think I might have had to restart the
phone once when it was being insistent that there wasn’t a USB
connection, but other than that, it’s all happy:
$ adb devices
List of devices attached
HT851N003417 device
$
One
more thing: while looking around, I found an
issue reported
against the Android project that states that
adb
is
broken against Linux kernel versions 2.6.27 and later, with identical
symptoms. I’m currently using 2.6.24, so I can’t test it, but
it’s worth being aware of.Saturday, June 16, 2012
How to change the android rules in ubuntu through terminal in ubuntu?
The first thing to do is download android sdk from http://developer.android.com/sdk/index.html and extract it to wherever you want then log in as root and create a new plain text document in
/etc/udev/rules.d
and name it
51-android.rules
In the text document type:
SUBSYSTEM=="usb",SYSFS{idVendor}=="22b8",MODE="0666"
and save it to that directory.Then open Terminal and execute
chmod a+r /etc/udev/rules.d/51-android.rules
Restart the computer and go to the adb directory and execute
./adb devices
If the device ID shows instead of the question marks you should be ready to execute any adb commands.ENJOY!
(Dont forget to enable USB debugging on you're phone!)
I followed following step so that i can get writing permission in rules file,so first step login through root....
shailesh@shailesh-desktop:~$ sudo -i
root@shailesh-desktop:~# cd /
root@shailesh-desktop:/# cd etc/
root@shailesh-desktop:/etc# cd udev/
root@shailesh-desktop:/etc/udev#
root@shailesh-desktop:/etc/udev# cd rules.d/
root@shailesh-desktop:/etc/udev/rules.d# chmod 777 51-android.rules
//No we can write and save after saving type the below command....
root@shailesh-desktop:/etc/udev/rules.d# chmod a+r 51-android.rules
Friday, June 15, 2012
Design Layout For Multiple Screens in android?
You need to create different layout for diff screen size. Support all screen you need to create following layout:
1-Low density Small screens QVGA 240x320 (120dpi):
layout-small-ldpi (240x320)
layout-small-land-ldpi (320x240)
2-Low density Normal screens WVGA400 240x400 (x432) (120dpi):
layout-ldpi (240 x 400 )
layout-land-ldpi (400 x 240 )
3-Medium density Normal screens HVGA 320x480 (160dpi):
layout-mdpi (320 x 480 )
layout-land-mdpi (480 x 320 )
4-Medium density Large screens HVGA 320x480 (160dpi):
layout-large-mdpi (320 x 480 )
layout-large-land-mdpi (480 x 320)
5-Galaxy Tab ( 240 dpi ):
layout-large (600 x 1024)
layout-large-land (1024 x 600)
6-High density Normal screens WVGA800 480x800 (x854) (240 dpi):
layout-hdpi (480 x 800)
layout-land-hdpi (800 x 480)
7-Xoom (medium density large but 1280x800 res) (160 dpi):
layout-xlarge (800 x 1280)
layout-xlarge-land (1280 x 800)
8- Other
layout-normal-mdpi -> 320x480
layout-normal-hdpi -> 800x480 and 854x480 (adjusted in the code)
layout-normal-ldpi -> 400x240
layout-large-mdpi -> 800x480 tablet (mostly the same as the layout-normal-hdpi layout, but needs to be in this folder)
layout-small-ldpi -> 320x240
Also add following code in .manifest file:
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Sunday, June 10, 2012
keytool -genkey error: Keystore file does not exist(Ubuntu) in Android ?
Below command will generate the KeyStore..........
keytool -list -alias [KEYNAME] -keystore [STORE FILENAME] -storepass [STORE PASSWORD] -keypass [KEY PASSWORD]
shailesh@shailesh-desktop:~$ cd .android/
shailesh@shailesh-desktop:~/.android$ keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android
keytool error: java.lang.Exception: Keystore file does not exist: debug.keystore
SOLUTION
Generating a key pair (and a new keystore) has to be done as a separate operation to creating a self-signed certificate for that key.
i.e.
keytool -genkey -alias myKey -keystore store.jks
keytool -selfcert -alias myKey -keystore store.jks
shailesh@shailesh-desktop:~/.android$ keytool -genkey -alias debug -keystore store.jks
Enter keystore password:
Above command will ask for the password and other information and hence the key is generated.
Tuesday, June 5, 2012
Monday, June 4, 2012
Android emulator: How to monitor network traffic?
There are two ways to capture network traffic directly from an Android emulator:
- Copy and run an ARM-compatible tcpdump binary on the emulator, writing output to the SD card, perhaps (e.g.
tcpdump -s0 -w /sdcard/emulator.cap
). - Run
emulator -tcpdump emulator.cap -avd my_avd
to write all the emulator's traffic to a local file on your PC
In both cases you can then analyse the pcap file with tcpdump or Wireshark as normal.
try wireshark http://www.wireshark.org/
Capture network trace in Android devices ?
After finding a bug,
the next step for a tester is to find whose fault is it ?
Normally a software interacts a lot with servers. It is then
quite useful to capture the network exchanges between the software and the
servers to find what is really happening behind the user interface. For Android
devices, we can use Android Debug Bridge (ADB), tcpdump-arm and wireshark to
analyse network packages. First, you need to have Wireshark and ADB installed
in your computer (here’s a bit oftutorial). Then, I’ll
briefly explain how to use tcpdump-arm in your Android devices to capture a
network trace during use case scenario.
1. Download tcpdump-arm from here
2. Open command-promt where your ADB tools
located. Put your tcpdump-arminto /data/local in
your Android device through this command :
adb remount
adb push tcpdump-arm /data/local
3. Go inside Android devices through this command
:
adb shell
cd data/local
cd data/local
4. Give tcpdump-arm execute permission.
chmod 777 tcpdump-arm
5. We need to define in which interface we want
to listen to the packages. If you run the command below, you’ll see the list of
interfaces registered on your device. Normally we find three interfaces: svnet0, pdp0,
and l0.
./tcpdump-arm -D
6. Since I want to capture packets coming from
data network, I choose to listen to interface: pdp0. (Still
remember the famous Packet Data Protocol Context learnt at school ). I specify also
the output file in which I’d like it to be read through Wireshark later on.
./tcpdump-arm -i pdp0 -w capture.pcap
7. FYI, the option of pdp0 is
available when you use the firmware Gingerbread for Samsung Galaxy 2. When you
use Ice Scream Sandwich, there’ll be only two options offered: svnet0 and l0.
You can either listening to svnet0, but sometimes I also try with option -s
0 to make it capture the full packets and later on I filter what
I want in wireshark.
./tcpdump-arm -s 0 -w capture.pcap
8. After finish the test, run Ctrl+C to stop the
capture. Move the output filecapture.pcap from the device into your
computer and open it in Wireshark. Here you can do whatever filter you want to
find your exchange package.
adb pull data/local/capture.pcap
These tricks have
helped me a lot to prevent myself from blaming the developpers for some faults
since it’s proved that the bug comes from another source . Have fun!
Friday, June 1, 2012
How to avoid spinner listener to get fire before Adapter is set in android?
Solution
1.
in onCreate(), count how many Spinner
(or Spinner) widgets you have in the view. (mSpinnerCount)
2.
in onItemSelected(), count how often
it has triggered. (mSpinnerInitializedCount)
3.
when (mSpinnerInitializedCount <
mSpinnerCount) == false, then execute the code meant for the user
public class myActivity extends Activity implements OnItemSelectedListener
{
//this counts how many Spinner's are on the UI
private int mSpinnerCount=0;
//this counts how many Spinner's have been initialized
private int mSpinnerInitializedCount=0;
//UI reference
private Spinner mSpinner;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.myxmllayout);
//get references to UI components
mSpinner = (Spinner) findViewById(R.id.myspinner);
//trap selection events from spinner
mSpinner.setOnItemSelectedListener(this);
//trap only selection when no flinging is taking place
mSpinner.setCallbackDuringFling(false);
//
//do other stuff like load images, setAdapter(), etc
//
//define how many Spinner's are in this view
//note: this could be counted dynamically if you are programmatically creating the view
mSpinnerCount=1;
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
if (mSpinnerInitializedCount < mSpinnerCount)
{
mSpinnerInitializedCount++;
}
else
{
//only detect selection events that are not done whilst initializing
Log.i(TAG, "selected item position = " + String.valueOf(position) );
}
}
}
{
//this counts how many Spinner's are on the UI
private int mSpinnerCount=0;
//this counts how many Spinner's have been initialized
private int mSpinnerInitializedCount=0;
//UI reference
private Spinner mSpinner;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.myxmllayout);
//get references to UI components
mSpinner = (Spinner) findViewById(R.id.myspinner);
//trap selection events from spinner
mSpinner.setOnItemSelectedListener(this);
//trap only selection when no flinging is taking place
mSpinner.setCallbackDuringFling(false);
//
//do other stuff like load images, setAdapter(), etc
//
//define how many Spinner's are in this view
//note: this could be counted dynamically if you are programmatically creating the view
mSpinnerCount=1;
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
if (mSpinnerInitializedCount < mSpinnerCount)
{
mSpinnerInitializedCount++;
}
else
{
//only detect selection events that are not done whilst initializing
Log.i(TAG, "selected item position = " + String.valueOf(position) );
}
}
}
Why this works
this solution works because the Spinner finishes initialization
long before a user is physically able to make a selection.
Android HelpFull Links ?
Android Cheat Sheet
WP Blogs
http://www.krvarma.com/category/posts/android/ (Gestures,
telephony manager etc)
External Links
Android Academy (source
codes): http://www.androidacademy.com/3-tutorials
Individual Entities Tutorials
Android APK Build
Process http://asantoso.wordpress.com/2009/09/15/how-to-build-android-application-package-apk-from-the-command-line-using-the-sdk-tools-continuously-integrated-using-cruisecontrol/
Supporting Multiple
Screens: http://developer.android.com/guide/practices/screens_support.html#testing
Using Menus, Preferences,
Animations http://www.androidacademy.com/3-tutorials/43-hands-on/167-coolsplash-an-interactive-splash-toy-for-android-apps
Common Tasks How to do
them in Android: http://developer.android.com/guide/appendix/faq/commontasks.html
Telephony Manager: http://www.krvarma.com/posts/android/using-phonestatelistener-to-listen-to-state-change-in-android/
Broadcasting: http://thinkandroid.wordpress.com/2010/02/02/custom-intents-and-broadcasting-with-receivers/
GPS: http://www.javacodegeeks.com/2010/09/android-location-based-services.html,
http://developer.android.com/guide/topics/location/obtaining-user-location.html
Custom Scroll View (Great
Tutorial) https://github.com/ysamlan/horizontalpager/blob/master/src/com/github/ysamlan/horizontalpager/HorizontalPager.java
Android AndEngine
Examples(Source Code) http://code.google.com/p/andengineexamples/
Subscribe to:
Posts (Atom)