Archive for the ‘Google Phone’ Category

26
Mar

ADB stands for the android debugging bridge and is used for testing and debugging purposes by developers. However, we like to get more out of our devices, and its a great way to fix things. Knowing adb can mean the difference between a paperweight and a working phone.

To start with, you need JDK from Sun/Oracle and Android SDK from Google. Here let me explain some ADB commands,

1. To install an application on your device (sideloading). Unlike installing from the SD card, it does not require unknown sources (settings/development/unknown sources) to be enabled. This assumes that you are working from the directory where the file is located.
This will install the application to /data/app. It will also show sometimes useful errors if install fails.

adb install packagename

2. adb shell which logs into the phone.

adb shell

 

3. If we end up with a $, we will want admin rights, in many cases. This is not one of them, I don’t beleive.
To get admin rights, you want to type:


su

 

4. Look at your phone if this is the first time, it may prompt you to allow access. Else you will get permission denied. If you are not rooted, this will not work either. Now that we are logged in, we will type

pm uninstall packagename

 

5. To disable an application in your device

adb shell
su
pm disable appllicationname

 

6. To re-enable an application

adb shell
su
pm enable applicationname

 

7. To reboot your device

adb reboot

 

8. to reboot into recovery mode (CWM Recovery)

adb reboot recovery

 

9. To reboot into download mode

adb reboot download

 

10. To push a file to your device

adb push filename /pathtodirectoryonphone

eg.

adb push test.txt /sdcard/

 

11. Pushing files can be done to any directory, however, some are protected. For instance, /system is going to give you a permission denied or a read only filesystem error. To get around this, the easiest thing to do is push the file to your sdcard, then log into the shell:

adb shell
su
We will then mount the system as writable
mount -o rw,remount /dev/block/stl9 /system
cp /sdcard/test.txt /system/app/test.txt

cp stands for copy and it requires the path of the file and destination path. The name of the file is optional .When you copy it, you can rename it to whatever you like. For instance, if we wanted to backup a file

cp /sdcard/test.txt /sdcard/backuptest.txt

Now, lets assume you do not have busybox installed. You non rooted users will not. Then you must use a slightly more complicated command called dd
This is used like this:

dd if=/sdcard/test.txt of=/system/app/test.txt

12. To pull a file, Lets say you want to get a file from your phone, to modify, backup, etc.
To do this, we simply use adb in this manner:

adb pull /pathtofile/filename destinationname
eg:
adb pull /system/app/ADWLaucnher.apk ADWLauncher.apk

 

13. logcat allows us to log what the OS is doing, and possibly delve information for when things are not working
its quite simple Reading it is another.
To use logcat

adb shell
logcat

To logcat to a certain file do

adb shell
logcat > /sdcard/logcat.txt

, , ,

02
Sep

The following is the equivalent of do-while loop in Corona

repeat

– body inside the loop

until (condition which should become true inorder to exit this loop)

 

This will first execute the body, then checks the condition and if the condition is false, it will loop again otherwise it will exit from the loop.

, , , , , , ,

02
Sep
local sampleArray = {}    -- initializing empty array

sampleArray[#sampleArray+1]=objecttoadd   -- Adding the object to the next index of last index of the array

#sampleArray will be returning the length of sampleArray

, , , , , , ,

06
Apr

Detecting device density, Screen-type and aspect-ratio dynamically in Android

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;

public class MainActivity extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

@Override
public void onStart() {
super.onStart();

try {
checkDensity();
} catch (Exception e) {
e.printStackTrace();
}

try {
checkSize();
} catch (Exception e) {
e.printStackTrace();
}

try {
checkAspectRatio();
} catch (Exception e) {
e.printStackTrace();
}
}

public void checkDensity() {
// reading the device density values
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

String screen_density = Integer.toString(metrics.densityDpi);
String logical_density = Float.toString(metrics.density);
}

public void checkSize() {
Configuration myConfig = new Configuration();
myConfig.setToDefaults();
myConfig = getResources().getConfiguration();

// Tests that the screen size category (small, med, large) is set
switch (myConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) {
case Configuration.SCREENLAYOUT_SIZE_LARGE: {
break;
}
case Configuration.SCREENLAYOUT_SIZE_NORMAL: {
break;
}
case Configuration.SCREENLAYOUT_SIZE_SMALL: {
break;
}
case Configuration.SCREENLAYOUT_SIZE_UNDEFINED: {
break;
}
}
}

public void checkAspectRatio() {
Configuration myConfig = new Configuration();
myConfig.setToDefaults();
myConfig = getResources().getConfiguration();

// Tests the screen aspect ratio
switch (myConfig.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) {

case Configuration.SCREENLAYOUT_LONG_NO: {
break;
}
case Configuration.SCREENLAYOUT_LONG_YES: {
break;
}
case Configuration.SCREENLAYOUT_LONG_UNDEFINED: {
break;
}
}
}
}

, , , , , , , , , , , ,

31
Mar

Strings are a sequence of characters that are used in several scenarios. Android enables developers to use three types of

string resources, namely

  • Plain Strings.
  • String formats.
  • Styled texts.

Plain Strings:

Plain string resources are declared within res/values/strings.xml These are normal text strings with no

codes or styles.
When a new project is created in Eclipse, the ADT automatically generates a sample strings.xml file containing the appname

and hello.
The ADT also adds this to the string name in layout, main.xml and in AndroidManifest.xml.

strings.xml:

<?xml version="1.0" encoding="utf-8"?>

<resources> 

<string name="hello">Hello World, SampleAPP!</string> 

<string name="app_name">SampleAPP</string>
</resources>

main.xml:



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

Strings referenced from the res/layout/main.xml.
Strings can also be referenced from the java code.
The first string is the text of a textview defined in res/layout/main.xml file.

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.schogini.SampleAPP" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SampleAPP" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Referencing Strings:

@string/Resource_Name in xml files.

R.string.Resource_Name in java files.
R.java:

package com.schogini.SampleAPP;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon =0x7f020000;
}

public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

strings.xml is never accessed or referenced directly in Java. Android converts them to R.Java and we access those stringsvia the R.java file.

The main advantage is that there is no need to parse xml file, android does this.String arrays:

String arrays can also be created.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>
</resources>

Custom String Resources:
Our own custom resource strings file can also be created.

To create go to res/values/ directory in Package Explorer in Eclipse IDE,Right click and select,

New–>File and Enter a name for the file with Extension. (See Image Attached).
Resources can be added manually by choosing the myStrings.xml tab or by clicking “Add” button and adding the name and the

value of the resource.

custom String Resources  in Android

Custom String Resources in Android

Formatted strings:
The Dalvik Virtual Machine offers string formats, which provide placeholders representing data to be replaced at runtimeby variables.
Escaping apostrophes and quotes
If you have an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the othertype of enclosing quotes. For example, here are some stings that do work and those don’t work:

<string name="good_example">"This'll work"</string>
<string name="good_example_2">This\'ll also work</string>
<string name="bad_example">This doesn't work</string>
<string name="bad_example_2">XML encodings don&apos;t work</string>

Formatting strings
Android allows strings to be formatted as in String.format(String, Object…) in java.lang.string Package. This can beaccomplished easily. The following are a few examples of exceptions.
<string name=”welcome_messages”>Hello, %1$s! You have %2$d new messages.</string>In this example, the format string has two arguments: %1$s is a string and %2$d is a decimal number. You can format the

string with arguments from your application like this:

Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages),username, mailCount);

Styled strings:
Android support the following HTML elements:

  • <b> for bold text.
  • <i> for italic text.
  • <u> for underline text.

To create a styled text resource that is also used as a format string, HTML tags can be used. Normally, this won’t workbecause the String.format(String, Object…) method will strip all the style information from the string. The work-around

to this is to write the HTML tags with escaped entities, which are then recovered with fromHtml(String), after the formatting takes place.

For example:

  • Store your styled text resource as an HTML-escaped string:
  • <resources>
      <string name="welcome_messages">Hello, %1$s! You have &lt;b>%2$d new messages&lt;/b>.</string>
    </resources>

    In this formatted string, a <b> element is added. Notice that the opening bracket is HTML-escaped, using the

    &lt; notation.

  • Then format the string as usual, but also call fromHtml(String) to convert the HTML text into styledtext:
  • Resources res = getResources();
    String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
    CharSequence styledText = Html.fromHtml(text);

    Because the fromHtml(String) method will format all HTML entities, be sure to escape any possible HTML characters in the

    strings you use with the formatted text, using htmlEncode(String). For instance, if you’ll be passing a string argument

    to String.format() that may contain characters such as “<” or “&”, then they must be escaped before formatting, so

    that when the formatted string is passed through fromHtml(String), the characters come out the way they were originally

    written.
    For example:

    String escapedUsername = TextUtil.htmlEncode(username);
    Resources res = getResources();
    String text = String.format(res.getString(R.string.welcome_messages), escapedUsername, mailCount);
    CharSequence styledText = Html.fromHtml(text);

    , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

    28
    Mar

    There are some situations where the phone should be prevented from going to sleep mode or screen lock mode. Eg. while watching a webpage/video or some presentations.

    Java Code:

    if(TASK_NOT_COMPLETED)
    {
    PowerManager pman = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wlock = pman.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
    wlock.acquire();
    //screen will stay on during this section..
    //Do the tasks here
    }
    wlock.release();
    

    Android Manifest.xml:

    <uses-permission android:name="android.permission.WAKE_LOCK" />

    Warning:
    This is a resource intensive call. It uses a considerable amount of battery and processing power. Hence usage should be minimized or avoided if possible.

    , , , , , , , , , , ,

    25
    Mar

    By the increased use of social networks and emailing, the capabilities of smartphones are convincing more and more consumers to switch from a simple mobile phone to a more sophisticated device.In the end of 2010, 23% of mobile consumers have a smartphone, up from just 16% of 2009 !.
    The fiercest competitors of smart phones are Apple, with its iconic iPhone, and Google, with its fast-growing Android operating system.

    Both Android and iPhone users are urban biased.
    Android users show a 54/46 gender split compared to iPhone’s 55/45.

    Android users tend to be slightly younger than iPhone users. ie, 55% of Android users are under the age of 34 ,while just 47% of iPhone users fall within the same demographic. As is usually the case, age is also a prime determinant of income and education, with Android users slightly less wealthy and less educated.

    80% of iPhone users want their next device to run iPhone OS while 70% of Android users want another Android device. But for other major smartphone players: only 47% of Blackberry users want another Blackberry while only 34% of Windows Mobile users want another Windows Mobile device.

    Among Android and iPhone users who would like to switch operating systems, the rate at which Android users would like to try iPhone is twice as high as that of iPhone users who would try Android.

    usage profiles for Android and iPhone are more like each other compare to rest of the smartphone market. Generally, iPhone customers are more likely to have downloaded a game or played online, but Android users appear to be using their phones for a wide range of activities as well. Android users were more likely to engage in file-transfer activities like downloading ringtones, pictures, wallpaper and uploads.

    , , , , , , , , , , , , , , , , , , ,

    24
    Mar

    To read the Information of a connection, use the following code. The code uses DhcpInfo class inside amdroid.net package.

    Code:

    package com.schogini.dhcp;
    
    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.widget.TextView;
    import android.net.*;
    import android.net.wifi.WifiManager;
    
    public class dhcpInfo extends Activity {
    public String     s_dns1 ;
    public String     s_dns2;
    public String     s_gateway;
    public String     s_ipAddress;
    public String     s_leaseDuration;
    public String     s_netmask;
    public String     s_serverAddress;
    TextView info;
    DhcpInfo d;
    WifiManager wifii;
    
    /** Called when the activity is first created. */
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    wifii= (WifiManager) getSystemService(Context.WIFI_SERVICE);
    d=wifii.getDhcpInfo();
    
    s_dns1="DNS 1: "+String.valueOf(d.dns1);
    s_dns2="DNS 2: "+String.valueOf(d.dns2);
    s_gateway="Default Gateway: "+String.valueOf(d.gateway);
    s_ipAddress="IP Address: "+String.valueOf(d.ipAddress);
    s_leaseDuration="Lease Time: "+String.valueOf(d.leaseDuration);
    s_netmask="Subnet Mask: "+String.valueOf(d.netmask);
    s_serverAddress="Server IP: "+String.valueOf(d.serverAddress);
    
    //dispaly them
    info= (TextView) findViewById(R.id.infolbl);
    info.setText("Network Info\n"+s_dns1+"\n"+s_dns2+"\n"+s_gateway+"\n"+s_ipAddress+"\n"+s_leaseDuration+"\n"+s_netmask+"\n"+s_serverAddress);
    }
    }
    

    , , , , , , , , , , , , , , , , , , , ,

    21
    Mar

    By following the practices described in this book, you can easily create an application that displays properly on all supported device screens, and you can deploy it to any device as a single apk.

    Device and Display Independent Programming in Android
    [Screen, resolution, density & API level independent applications]

    Contents

    1. Introduction

    2. Information on Displays

    3. Terms in Display Measurements

    4. Basic Rules for Screen Independence

    5. Why Pixel density?

    6. Android OS – Screen & Resource Handling

    7. Custom Display Parameters

    * 9Patch Images
    * AndroidManifest.xml Specifications
    * Custom resources with qualifiers
    * Custom Scaling and Sizing

    8. Testing Your Applications
    9. Code Samples

    Go here to buy:
    Device and Display Independent Programming in Android – Schogini Systems

    The book is simple and explains many key tools and scenarios where coding device independent is very essential. Several example codings are also provided wherever needed.

    , , , , , , , , , , , , , , , , , , ,

    21
    Mar

    Launching an application within android to handle a content like music,..etc Twitter, Facebook,..etc can also be handled.

    public void share(String subject,String text) {
     final Intent intent = new Intent(Intent.ACTION_SEND);
    
     intent.setType("text/plain");
     intent.putExtra(Intent.EXTRA_SUBJECT, subject);
     intent.putExtra(Intent.EXTRA_TEXT, text);
    
     startActivity(Intent.createChooser(intent, getString(R.string.share)));
    }
    

    , , , , , , , , ,