Wednesday, October 17, 2018

Service Demo Working code



MainActivity.java



import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {
//String msg="android:";    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Log.d(msg, "The onCreate() event");    }

    public void startService(View view) {
        startService(new Intent(getBaseContext(), Myservice.class));
    }

    // Method to stop the service    public void stopService(View view) {
        stopService(new Intent(getBaseContext(), Myservice.class));
    }

}

Myservice.java

public class Myservice extends Service {
    @Nullable    @Override    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override    public int onStartCommand(Intent intent, int flags, int startId) {
        // Let it continue running until it is stopped.        Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
        return START_STICKY;
    }

    @Override    public void onDestroy() {
        super.onDestroy();
        Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
    }
}

Manifest.xml code ( adding service tag components )
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.admin.servicedemo">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name=".Myservice" />

        <activity android:name=".abc"></activity>
    </application>

</manifest>







 Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button2"
        android:layout_centerVertical="true"
        android:onClick="stopService"
        android:text="stop service"
        tools:layout_editor_absoluteX="96dp"
        tools:layout_editor_absoluteY="130dp" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="111dp"
        android:layout_marginTop="104dp"
        android:onClick="startService"
        android:text="start service"
        tools:layout_editor_absoluteX="61dp"
        tools:layout_editor_absoluteY="293dp" />
</RelativeLayout






Tuesday, October 9, 2018

Current Location Finding

package com.example.lenovo.mapsdemo;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.io.IOException;
import java.util.List;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

   
private GoogleMap mMap;
    LocationManager
locationManager;

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_maps);
       
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
       
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.
map);
        mapFragment.getMapAsync(
this);
       
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
       
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
           
// TODO: Consider calling
           
//    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
           
return;
        }

       
if(locationManager.isProviderEnabled(locationManager.NETWORK_PROVIDER))
        {
           
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() {
               
@Override
               
public void onLocationChanged(Location location) {
                   
double lat=location.getLatitude();
                   
double longitud=location.getLongitude();
                    LatLng latLng=
new LatLng(lat,longitud);

                    Geocoder geocoder=
new Geocoder(getApplicationContext());
                   
try {
                        List<Address> addressList=geocoder.getFromLocation(lat,longitud,
1);
                        String st=addressList.get(
0).getLocality();
                        st+=addressList.get(
0).getCountryName();
                       
mMap.addMarker(new MarkerOptions().position(latLng).title(st));
                        
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,20.6f));

                    }
catch (IOException e) {
                        e.printStackTrace();
                    }


                }

               
@Override
                
public void onStatusChanged(String provider, int status, Bundle extras) {

                }

               
@Override
               
public void onProviderEnabled(String provider) {

                }

               
@Override
               
public void onProviderDisabled(String provider) {

                }            });
        }
       
else if(locationManager.isProviderEnabled(locationManager.GPS_PROVIDER))
        {
           
locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
               
@Override
               
public void onLocationChanged(Location location) {
                   
double lat=location.getLatitude();
                   
double longitud=location.getLongitude();
                    LatLng latLng=
new LatLng(lat,longitud);
                    Geocoder geocoder=
new Geocoder(getApplicationContext());
                   
try {
                        List<Address> addressList=geocoder.getFromLocation(lat,longitud,
1);
                        String st=addressList.get(
0).getLocality();
                        st+=addressList.get(
0).getCountryName();
                       
mMap.addMarker(new MarkerOptions().position(latLng).title(st));
                       
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,20.6f));
                    }
catch (IOException e) {
                        e.printStackTrace();
                    }
                }
               
@Override
               
public void onStatusChanged(String provider, int status, Bundle extras) {
                }
               
@Override
               
public void onProviderEnabled(String provider) {
                }
               
@Override
               
public void onProviderDisabled(String provider) {

                }
            });
        }
    }
   
/**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
   
@Override
   
public void onMapReady(GoogleMap googleMap) {
       
mMap = googleMap;

       
// Add a marker in Sydney and move the camera
       // LatLng sydney = new LatLng(-34, 151);
       // mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
       // mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,20.6f));
   
}
}

Monday, October 1, 2018

Plsql Programs


Write an anonymous PL/SQL block that fetches and displays the data from employee table to the console.


 declare
 essn number:=&amp;
 sal employee.salary% type;
 name employee.minit%type;
 begin
 select salary,minit into sal,name from employee
 where ssn=essn;
 DBMS_OUTPUT.PUT_LINE(sal);
 DBMS_OUTPUT.PUT_LINE(name);
exception
 when no_data_found then
 DBMS_OUTPUT.PUT_LINE('no data found');
 end;
 /
 

output:

 Enter value for amp: 102
old   2:  essn number:=&amp;
new   2:  essn number:=102;
no data found

PL/SQL procedure successfully completed.

SQL> /
Enter value for amp: 333445555
old   2:  essn number:=&amp;
new   2:  essn number:=333445555;
40000
T

PL/SQL procedure successfully completed.









Write a program that updates salaries of all employees with 10 % hike (use cursors).



declare
name employee.fname%type;
 salary employee.salary%type;
cursor c2 is select fname,salary from employee;
 BEGIN
 open c2;
 UPDATE EMPLOYEE SET SALARY=SALARY+(SALARY*0.1);
 loop
 fetch c2 into name,salary;
 exit when c2%NOTFOUND;
 DBMS_OUTPUT.PUT_LINE(name||'--->'||salary);
 end loop;
 END;





 14  /




output:


update
john--->30000
franklin--->40000
alicia--->25000
jennifer--->43000
ramesh--->38000
Joyce--->25000
Ahmad--->25000
james--->55000

PL/SQL procedure successfully completed.














 https://meet.google.com/tcg-zgzv-dye