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.

Get SensorManager PowerManager WindowManager Display Android example


    private SensorManager mSensorManager;
    private PowerManager mPowerManager;
    private WindowManager mWindowManager;
    private Display mDisplay;

// onCreate
   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

       // Get an instance of the SensorManager
        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

        // Get an instance of the PowerManager
        mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);

        // Get an instance of the WindowManager
        mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mDisplay = mWindowManager.getDefaultDisplay();

        setContentView(R.layout.main); // main.xml or your xml file name

}


396LW NO topic_id




AD

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


293

Get Bitmap Size Get Free Memory Exception Android | get-bitmap-size-get-free-memory-exception-android


Bitmap size calculation:
bmpHeight * bmpWidth
For example:
Resolution of image 1024x860 = 880 640 pixels
If every pixel get 4 byte of memory:
880 640x4= 3 522 560 (3.5MB)

Get bitmap size without allocation of memory:

   	BitmapFactory.Options options = new BitmapFactory.Options();
        // If set to true, the decoder will return null (no bitmap), but the out... fields will still
        // be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels. 
    	options.inJustDecodeBounds = true; 
    	BitmapFactory.decodeResource(getResources(), R.drawable.my_image, options);
    	int imageHeight = options.outHeight; // 1024
    	int imageWidth = options.outWidth; // 860
    	String imageType = options.outMimeType; // .jpg .png .gif
 


Get Memory size:
Make your bitmap not bigger as maxMemory size
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    float density = getResources().getDisplayMetrics().density;

    Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
    Debug.getMemoryInfo(memoryInfo);
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    final int freeMemory = (int) (Runtime.getRuntime().freeMemory() / 1024);
    String memMessage = String.format(
        "Free=%d kB,

MaxMem=%d kB,
Memory: Pss=%.2f MB, Private=%.2f MB, Shared=%.2f MB", freeMemory, maxMemory, memoryInfo.getTotalPss() / 1024.0, memoryInfo.getTotalPrivateDirty() / 1024.0, memoryInfo.getTotalSharedDirty() / 1024.0); ((TextView)findViewById(R.id.textViewInfo)).setText(memMessage );
392

Unchecked call to add(E) as a member of raw type java.util.List | unchecked-call-to-adde-as-a-member-of-raw-type-java-util-list



// warnning
private List list = new ArrayList();

// ok /put type of added object
private List<String> list = new ArrayList<String>();
311

Import project Android Eclipse | import-project-android-eclipse


Import a new Android project for example downloaded from internet via Eclipse into project folder.

  1. Right click into projects explorer in Eclipse and select Import

  2. Android

  3. Existing Android Code Into Workspace

  4. Root Directory (select folder of downloaded project)

  5. Check your downloaded project

  6. Check Copy project into Workspace

  7. Finish (press)




221

android - OnClickListener must override a superclass method | android-onclicklistener-must-override-a-superclass-method


The method onClick(DialogInterface, int) of type new DialogInterface.OnClickListener(){} must override a superclass method.

Try this:
Right click on project
Select Properties
In open dialogue select Java compiler
Set Enable project specific settings
Set Compiler compliance level to 1.6

android/project-properties-eclipse.png

android/java-compiler-settings-eclipse.png