Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Android Api level - SDK version - how get Api level on device - sample




import android.os.Build.VERSION;
//
int nSdkVersion = Integer.parseInt(Build.VERSION.SDK);
int nApiVersion = VERSION.SDK;






















Platform Version API Level
Android 4.0 14
Android 3.2 13
Android 3.1.x 12
Android 3.0.x 11
Android 2.3.4 10
Android 2.3.3 10
Android 2.3.2 9
Android 2.3.1 9
Android 2.3 9
Android 2.2.x 8
Android 2.1.x 7
Android 2.0.1 6
Android 2.0 5
Android 1.6 4
Android 1.5 3
Android 1.1 2
Android 1.0 1

397LW NO topic_id



Další témata ....(Topics)


206

java.lang.NullPointerException: println needs a message | java-lang-nullpointerexception-println-needs-a-message


Problemi is in e.getMessage() what can return null and Log.e (String tag, String msg) will throws an new exception !!!!
Problem and solution:

      	try {
      		int [] i = {1};
      		int z = i[5];
      	} catch (ArrayIndexOutOfBoundsException e) {
      		String s = e.toString(); // s == java.lang.ArrayIndexOutOfBoundsException
                // try to testing String s for null value
      		if(s != null)
      		 Log.e("bla", s);
      		else 
      		 Log.e("bla", "My error text 1");
      		
      		String s2 = e.getMessage(); // s2 == null !!!!!!!
                // you need to testing String s2 for null value , or you get FATAL EXCEPTION: main
                // and application will be crashed
       		String s2 = e.getMessage(); // s2 == null !!!!!!!
      		if(s2 != null)
      		 Log.e("bla2", e.getMessage());
      		else 
      		 Log.e("bla2", "My error text 2");
     		
                // this is OK
      		e.printStackTrace();
      	}


LogCat:

E/bla(855): java.lang.ArrayIndexOutOfBoundsException

 E/bla2(855): My error text 2

 W/System.err(855): java.lang.ArrayIndexOutOfBoundsException
 W/System.err(855): 	at cz.okhelp.motion._MotionActivity.onTouchEvent(_MotionActivity.java:54)
 W/System.err(855): 	at android.app.Activity.dispatchTouchEvent(Activity.java:2099)
 W/System.err(855): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
 W/System.err(855): 	at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
 W/System.err(855): 	at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
 W/System.err(855): 	at android.os.Handler.dispatchMessage(Handler.java:99)
 W/System.err(855): 	at android.os.Looper.loop(Looper.java:123)
 W/System.err(855): 	at android.app.ActivityThread.main(ActivityThread.java:3683)
 W/System.err(855): 	at java.lang.reflect.Method.invokeNative(Native Method)
 W/System.err(855): 	at java.lang.reflect.Method.invoke(Method.java:507)
 W/System.err(855): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 W/System.err(855): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 W/System.err(855): 	at dalvik.system.NativeStart.main(Native Method)




Or you can using this code:

      	try {
      		int [] i = {1};
      		int z = i[5];
      	} catch (Exception e) {
      		
      		
      		StringBuilder sb = new  StringBuilder().append(e.getClass().getSimpleName()); 
          if  (e.getMessage() != null) { 
              sb.append("

"); sb.append(e.getMessage()); } Log.e("err", sb.toString()); // E/err(336): ArrayIndexOutOfBoundsException // this code write out all message Log.e("myError", "methodName", e); } // E/myError(371): methodName // E/myError(371): java.lang.ArrayIndexOutOfBoundsException // E/myError(371): at cz.okhelp.motion._MotionActivity.onTouchEvent(_MotionActivity.java:54) // E/myError(371): at android.app.Activity.dispatchTouchEvent(Activity.java:2099) // E/myError(371): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675) // E/myError(371): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194) // E/myError(371): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878) // E/myError(371): at android.os.Handler.dispatchMessage(Handler.java:99) // E/myError(371): at android.os.Looper.loop(Looper.java:123) // E/myError(371): at android.app.ActivityThread.main(ActivityThread.java:3683) // E/myError(371): at java.lang.reflect.Method.invokeNative(Native Method) // E/myError(371): at java.lang.reflect.Method.invoke(Method.java:507) // E/myError(371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) // E/myError(371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) // E/myError(371): at dalvik.system.NativeStart.main(Native Method)

357

Android Studio formatting code Ctrl + Alt + L | android-studio-formatting-code-ctrl-alt-l


Shortcut
Windows
Ctrl + Alt + L (format selection or all page)
Ctrl + Alt + Shift + L (show a dialog)
Linux
Ctrl + Windows Key + Alt + L

From menu Code
Code > Reformat Code
334

Lenovo A6000 smartphone pictures from camera 8mpx review | lenovo-a6000-smartphone-pictures-from-camera-8mpx


Pictures taken by front camera Lenovo A6000 smartpohone - review.
Do not take pictures against the sun.
Stay in the shade. Keep lens clean.

Night without flash

Lenovo A6000 pictures quality
Lenovo A6000 pictures quality
Lenovo A6000 pictures quality
Lenovo A6000 pictures quality




Misty - smog


Without flash in room - TV screen


lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
lenovo-a6000-pictures-from-camera
272

How to Add Home Screen Widgets on Your Android Phone | how-to-add-home-screen-widgets-on-your-android-phone


Long press by finger on screen
From dialogue select Widgets
Select your widget
Put your widget on the screen

Video tutorial - to add home screen widgets - Android 2.1
104

Unable to find explicit activity class Android Eclipse error | unable-to-find-explicit-activity-class-android-eclipse-error


android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.my_package/com.example.my_package.MainClass}; have you declared this activity in your AndroidManifest.xml?

Is MainClass.java in AndroidManifest as a activity ?
AndroidManifest.xml example

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="//schemas.android.com/apk/res/android"
      package="com.example.my_packag"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainClass"
                  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>


Editace Jana Žákovská : 2011-10-29 08:52:36
Počet článků v kategorii: 397
Url:android-api-level-sdk-version-how-get-api-level-on-device-sample
Share
Share
Tweet