Friday 26 February 2021

WIFI Enabled, Bluetooth ON OFF, Flash Light ON OFF and Vibrating a Phone Using Android

Search Any Android Programs Here:

Program Listed Here

Download Link is Bottom Side of Page


 package com.example.classworkapk;


import android.app.Activity;

import android.bluetooth.BluetoothAdapter;

import android.content.Context;

import android.hardware.Camera;

import android.net.wifi.WifiManager;

import android.os.Bundle;

import android.os.Vibrator;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.Toast;

import android.view.Menu;


public class MainActivity extends Activity {

Button b1, b2, w1, w2, f1, f2, v1;

Camera cm;

Vibrator vi;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        

        //Bluetooth Code

        

        b1 = (Button) findViewById(R.id.button1);

        b2 = (Button) findViewById(R.id.button2);

        final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        

        b1.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

    

if (!mBluetoothAdapter.isEnabled()) {

    mBluetoothAdapter.enable();     

    Toast.makeText(getApplicationContext(), "Bluetooth Enable", Toast.LENGTH_LONG).show();

}

else{

Toast.makeText(getApplicationContext(), "Bluetooth Al-Ready Enable", Toast.LENGTH_LONG).show();

}

});

        

        b2.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

if (mBluetoothAdapter.isEnabled()) {

    mBluetoothAdapter.disable();     

    Toast.makeText(getApplicationContext(), "Bluetooth Disable", Toast.LENGTH_LONG).show();

}

else{

Toast.makeText(getApplicationContext(), "Bluetooth Al-Ready Disable", Toast.LENGTH_LONG).show();

}

}

});

        

        // Wi - Fi Code

        

        w1 = (Button) findViewById(R.id.button3);

        w2 = (Button) findViewById(R.id.button4);

        

        final WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

        

        w1.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

wifi.setWifiEnabled(true);

Toast.makeText(getApplicationContext(), "Wi-Fi On", Toast.LENGTH_LONG).show();

}

});

        

        w2.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

wifi.setWifiEnabled(false);

Toast.makeText(getApplicationContext(), "Wi-Fi Off", Toast.LENGTH_LONG).show();

}

});

        

        //Flash Light Code

        

        f1 = (Button) findViewById(R.id.button5);

        f2 = (Button) findViewById(R.id.button6);            

        cm = Camera.open();

        

        final Camera.Parameters parameters = cm.getParameters();

        

        f1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);

cm.setParameters(parameters);

cm.startPreview();

Toast.makeText(getApplicationContext(), "Flash Light ON", Toast.LENGTH_LONG).show();

}

});

        

        f2.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);

cm.setParameters(parameters);

cm.startPreview();

Toast.makeText(getApplicationContext(), "Flash Light Off", Toast.LENGTH_LONG).show();

}

});

        

        // Vibrate Code

        

        v1 = (Button) findViewById(R.id.button7);

        vi = (Vibrator) getSystemService(VIBRATOR_SERVICE);

        

        v1.setOnClickListener(new OnClickListener() {


@Override

public void onClick(View arg0) {

vi.vibrate(1000);

Toast.makeText(getApplicationContext(), "Device Vibrate", Toast.LENGTH_LONG).show();

}

});

        

    }



    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.

        getMenuInflater().inflate(R.menu.main, menu);

        return true;

    }

    

}



Download Load Source Code  https://classroom.google.com/c/MjQ5MjA3MzAzNDE3/m/Mjg1MzE2NzMwMzA4/details


No comments:

Post a Comment