Followers

Sunday, February 1, 2015

Android ေဆာ့ဖ္၀ဲတစ္ခုစေရးၾကမယ္။ Flash Light Apk(ေလ့က်င့္ခန္း-၁၃)

Android ေဆာ့ဖ္၀ဲတစ္ခုစေရးၾကမယ္။ Flash Light 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" />
  

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

Credit >> ေဇယ်ာလင္း

အခုလိုအားေပးတ့ဲအတြက္ အထူးေက်းဇူးတင္ပါေၾကာင္း ေျပာျပရပါေစ........ IT Learner & Sharer မွနည္းပညာမ်ားအား မည္သူမဆိုလြတ္လပ္စြာကူးယူသုံးစြဲႏိုင္ပါ ေၾကာင္း.....ကြ်န္ေတာ္ ပိုင္ဆိုင္ေသာေနရာေလးသို႔ လာလည္တဲ့အတြက္ေက်းဇူးတင္ပါသည္။

No comments:

Post a Comment