Programmatically determine if App is running on Android Emulator
You can get list by class Build
For example:
List of Build class getting from emulator:
"BOARD=unknown
BRAND=generic
CPU_ABI=armeabi
DEVICE=generic
DISPLAY=sdk-eng 2.1-update1 ECLAIR 35983 test-keys
FINGERPRINT=generic/sdk/generic/:2.1-update1/ECLAIR/35983:eng/test-keys
HOST=android-test-13.mtv.corp.google.com
ID=ECLAIR
MANUFACTURER=unknown
MODEL=sdk
PRODUCT=sdk
TAGS=test-keys
TIME=1273161972000
TYPE=eng
USER=android-build
"
For example:
if(Build.MANUFACTURER.equals("unknown")) {
// Emulator
}
List of Build class getting from emulator:
"BOARD=unknown
BRAND=generic
CPU_ABI=armeabi
DEVICE=generic
DISPLAY=sdk-eng 2.1-update1 ECLAIR 35983 test-keys
FINGERPRINT=generic/sdk/generic/:2.1-update1/ECLAIR/35983:eng/test-keys
HOST=android-test-13.mtv.corp.google.com
ID=ECLAIR
MANUFACTURER=unknown
MODEL=sdk
PRODUCT=sdk
TAGS=test-keys
TIME=1273161972000
TYPE=eng
USER=android-build
"
396LW NO topic_id
AD
Další témata ....(Topics)
Basic shortcuts for Android Emulator.
More about Android Emulator
Emulated Device Key | Keyboard Key |
---|---|
Home | HOME |
Menu (left softkey) | F2 or Page-up button |
Star (right softkey) | Shift-F2 or Page Down |
Back | ESC |
Call/dial button | F3 |
Hangup/end call button | F4 |
Search | F5 |
Power button | F7 |
Audio volume up button | KEYPAD_PLUS, Ctrl-5 |
Audio volume down button | KEYPAD_MINUS, Ctrl-F6 |
Camera button | Ctrl-KEYPAD_5, Ctrl-F3 |
Switch to previous layout orientation (for example, portrait, landscape) | KEYPAD_7, Ctrl-F11 |
Switch to next layout orientation (for example, portrait, landscape) | KEYPAD_9, Ctrl-F12 |
Toggle cell networking on/off | F8 |
Toggle code profiling | F9 (only with -trace startup option) |
Toggle fullscreen mode | Alt-Enter |
Toggle trackball mode | F6 |
Enter trackball mode temporarily (while key is pressed) | Delete |
DPad left/up/right/down | KEYPAD_4/8/6/2 |
DPad center click | KEYPAD_5 |
Onion alpha increase/decrease | KEYPAD_MULTIPLY(*) / KEYPAD_DIVIDE(/) |
More about Android Emulator
Put extends PreferenceFragment API level 11 instead PreferenceActivity
public class SettingsActivity extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
// or insert suppresswarning
public class SettingsActivity extends PreferenceActivity {
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
Example source code for Android development. How set gray text to EditText when EditText is blank.
Hint text to display when the text is empty.
In layout/main.xml insert to EditText row Attribute Name android:hint="Some text"
Programatically you can use method setHint:
Hint text to display when the text is empty.
In layout/main.xml insert to EditText row Attribute Name android:hint="Some text"
<EditText
android:id="@+id/myEdit"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:hint="Some text"
android:singleLine="true"
</EditText>
Programatically you can use method setHint:
// setHint(CharSequence hint) example
(EditText)findViewById(R.id.myEdit).setHint("My text");
// or int resId as method setHint(int resId)
EditText myEdit = findViewById(R.id.myEdit);
myEdit.setHint(R.string.app_name);
Window>Preference>Java>Editor>Typing and check the "Escape text when pasting into a string literal".
While cycle Java basic example with array of strings.
MainClass.java
MainClass.java
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "Hello", "people", "hello", "world!" };
int i = 0;
while ( i < arrayOfString.length ){
System.out.println(arrayOfString[i]);
i++;
}
}
}
Editace: 2012-12-12 19:47:42
Počet článků v kategorii: 396
Url:programmatically-determine-if-app-is-running-on-android-emulator