Tuesday, January 13, 2015

Flashlight Apk (ဓာတ္​မီး)


အ​ေပၚမွာ ​ေျပာထားတဲ့အတိုင္​း AIDE Apk စတင္​ဖြင္​့ပါ။ၿပီးရင္​ res>>>>layout>>>>main.xmlကိုဖြင္​့ပါ။
​ေအာက္​က code ကို ထည္​့ပါ။

<Button
      android:id="@+id/button"
      android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_centerVertical="true"
   android:layout_centerHorizontal="true"
        android:text="Torch" />





src >>> MainActivity.java ကိုဖြင္​့ပါ။ ​ေအာက္​က code ကို ထည္​့ပါ။

import(အပိုင္​း)

import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;



//flag to detect flash is on or off
private boolean isLighOn = false;
private Camera camera;
   private Button button;
@Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.release();
}
}


Source(အပိုင္​း)


button = (Button) findViewById(R.id.button);
Context context = this;
PackageManager pm = context.getPackageManager();
// if device support camera?
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.e("err", "Device has no camera!");
return;
}
camera = Camera.open();
final Parameters p = camera.getParameters();
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (isLighOn) {
Log.i("info", "torch is turn off!");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.stopPreview();
isLighOn = false;
} else {
Log.i("info", "torch is turn on!");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
isLighOn = true;}}});




AndroidManifest.xml(အပိုင္​း)


<uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
  


အဆင္​​ေျပပါ​ေစ။


​ေရးသားသူ=​ေဇယ်ာလင္​း

No comments:

Post a Comment