GPS Kullanım Tamamını indir

package com.example.ali.gpskullanm;

import android.Manifest;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedWriter;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    LocationListener ll;
    LocationManager lm;
    Context c;
    double enlem, boylam;
    TextView tenlem,tboylam;
    ConnectivityManager cm;
    NetworkInfo networkinfo;
    AlertDialog.Builder dialog;
    int saat=(1000*60*60);
    vt vt_sinfi;
    SQLiteDatabase db;
    Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        c = this;
        vt_sinfi=new vt(c);
        btn=(Button)findViewById(R.id.btn);
        btn.setOnClickListener(this);

        tenlem=(TextView)findViewById(R.id.enlem);
        tboylam=(TextView)findViewById(R.id.boylam);
        dialogcreate();

    }
    public void dialogcreate()
    {
        dialog=new AlertDialog.Builder(c);
        dialog.setTitle("Konum");
        dialog.setMessage("Konumu Açınız!!");
        dialog.setPositiveButton("Tamam", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        dialog.create().show();
    }
    public void init()
    {
        lm=null;
        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        ll = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                enlem = location.getLatitude();
                boylam = location.getLongitude();
                tenlem.setText(enlem+"");
                tboylam.setText(boylam+"");
                cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
                networkinfo=(NetworkInfo) cm.getActiveNetworkInfo();
                if(networkinfo!=null&&networkinfo.isConnected())
                {
                    if(veri_kontrol())
                        sunucuya_ekle();
                    post(enlem+"",boylam+"");
                }
                else
                {
                    konum_ekle(enlem+"",boylam+"");
                    Toast.makeText(c, "Konum veritabnına kayıtedildi", Toast.LENGTH_LONG).show();
                }
                lm.removeUpdates(ll);

            }
            @Override
            public void onStatusChanged(String s, int i, Bundle bundle) {

            }
            @Override
            public void onProviderEnabled(String s) {
                Toast.makeText(c, "GPS Veri bilgileri Alınıyor...", Toast.LENGTH_LONG).show();
            }
            @Override
            public void onProviderDisabled(String s) {
                Toast.makeText(c, "GPS Bağlantı Bekleniyor...", Toast.LENGTH_LONG).show();
            }
        };
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(c,"Konum açınız!!!",Toast.LENGTH_LONG).show();
            return;
        }
        if(networkinfo!=null&&networkinfo.isConnected()) {//bağlandı ise tru döndürür
            lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,6000,0, ll);
        }
        else
        {
            lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 6000, 0, ll);
        }
    }
    public  void post(final String enlem, final String boylam)
    {

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    URL url = new URL("http://alikomesogutlu.org/yandexmap.php");
                    HttpURLConnection  conn = (HttpURLConnection) url.openConnection();
                    conn.setReadTimeout(10000);
                    conn.setConnectTimeout(15000);
                    conn.setRequestMethod("POST");
                    conn.setDoInput(true);
                    conn.setDoOutput(true);

                    Uri.Builder builder = new Uri.Builder()
                            .appendQueryParameter("enlem",enlem)
                            .appendQueryParameter("boylam", boylam);
                    String query = builder.build().getEncodedQuery();

                    OutputStream os = conn.getOutputStream();//bağlantının cıkısı
                    BufferedWriter writer = new BufferedWriter(
                            new OutputStreamWriter(os, "UTF-8"));
                    writer.write(query);
                    writer.flush();
                    writer.close();
                    os.close();
                    conn.connect();
                    Log.d("hata",conn.getResponseMessage());
                }
                catch (Exception ex)
                {

                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                        Toast.makeText(c,"Konum sunucuya kayıt edildi.",Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }).start();
    }
    public void baglan()
    {
        try {
            db=vt_sinfi.getWritableDatabase();
        }
        catch (Exception ex)
        {
            Toast.makeText(c,ex.getMessage(),Toast.LENGTH_SHORT).show();
        }
    }
    public void konum_ekle(String enlem,String boylam)
    {
        try {
            baglan();
            ContentValues par=new ContentValues();
            par.put("enlem",enlem);
            par.put("boylam",boylam);
            db.insertOrThrow("konum",null,par);
            db.close();
        }
        catch (Exception ex)
        {
            Toast.makeText(c,ex.getMessage(),Toast.LENGTH_SHORT).show();
        }
    }
    public void sunucuya_ekle()
    {
        try {
            baglan();
            Cursor cursor=db.query("konum",new String[]{"enlem","boylam"},null,null,null,null,null);
            cursor.moveToPosition(-1);
            while (cursor.moveToNext())
                post(cursor.getString(0),cursor.getString(1));
            cursor.close();
            vt_sinfi.onUpgrade(db,0,0);
            db.close();
        }
        catch (Exception ex)
        {
            Toast.makeText(c,ex.getMessage(),Toast.LENGTH_SHORT).show();
        }
    }
    public boolean veri_kontrol()
    {
        try {
            baglan();
            Cursor cursor=db.rawQuery("select * from konum",null);
            if(cursor.getCount()>0)
            {   db.close();
                return true;
            }
            else {
                db.close();
                return false;
            }
        }
        catch (Exception ex)
        {
            Toast.makeText(c,ex.getMessage(),Toast.LENGTH_SHORT).show();
            return false;
        }
    }

    @Override
    public void onClick(View view) {
        init();
    }
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<?php
$enlem='36.584014';
$boylam='36.163995'; 
if(isset($_POST['konum']))
{
	$enlem_boylam=explode(",",$_POST['konum']);
	$enlem=$enlem_boylam[0];
	$boylam=$enlem_boylam[1];

}
if(isset($_POST['enlem'])&&isset($_POST['boylam']))
{
$dosya=fopen('konum.txt','a');
fwrite($dosya,$_POST['enlem'].",".$_POST['boylam']."-");
fclose($dosya);
}
else
{
	try{
$dosya=fopen('konum.txt','r');
$boyut=filesize('konum.txt');
$veri=fread($dosya,$boyut);
fclose($dosya);
$konum=explode("-",$veri);

	}
	catch(Exception $ex)
	{
		echo $ex->getMessage();
	}
?>
    <title>YMapsML examples. Map parameters</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	 <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20src%3D%22http%3A%2F%2Fapi-maps.yandex.ru%2F2.0%2F%3Fload%3Dpackage.full%26lang%3Dtr-TR%22%20type%3D%22text%2Fjavascript%22%3E%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" />
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20type%3D%22text%2Fjavascript%22%3E%0D%0Aymaps.ready(init)%3B%0D%0Afunction%20init%20()%20%7B%0D%0A%20%20%20var%20myMap%20%3D%20new%20ymaps.Map('map'%2C%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20center%3A%20%5B%3C%3Fphp%20echo%20%24enlem%3B%3F%3E%2C%20%3C%3Fphp%20echo%20%24boylam%3B%3F%3E%5D%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20zoom%3A%2012%0D%0A%20%20%20%20%20%20%20%7D)%2C%0D%0A%20%20%20%20%20%20%20myPlacemark%20%3D%20new%20ymaps.Placemark(%5B%3C%3Fphp%20echo%20%24enlem%3B%3F%3E%2C%20%3C%3Fphp%20echo%20%24boylam%3B%3F%3E%5D%2C%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20content%3A%20'%C4%B0skenderun!'%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20balloonContent%3A%20'Buradas%C4%B1n%C4%B1z!!!!'%0D%0A%20%20%20%20%20%20%20%7D)%3B%0D%0A%20%20%20myMap.controls%0D%0A%20%20%20%20%20%20%20.add('searchControl'%2C%20%7B%20left%3A5%2C%20top%3A%205%20%7D)%0D%0A%20%20%20%20%20%20%20.add('smallZoomControl'%2C%20%7B%20left%3A%205%2C%20top%3A%20165%20%7D)%0D%0A%20%20%20%20%20%20%20.add('typeSelector')%0D%0A%20%20%20%20%20%20%20.add('mapTools'%2C%20%7B%20left%3A%205%2C%20top%3A%20460%20%7D)%0D%0A%20%20%20%20%20%20%20.add('trafficControl'%2C%20%7B%20left%3A%20270%2C%20top%3A%205%20%7D)%3B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20myMap.geoObjects.add(myPlacemark)%3B%0D%0A%7D%0D%0A%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" />
</head>
<body>
<table>
<tr><td>
<form method="post">
<select name="konum" id="konum" onchange='this.form.submit()' >
<option value="Seçiniz...">Seçiniz...</option> 
<?php
for($i=0;$i<count($konum)-1;$i++){
?>
<option value="<?php echo $konum[$i];?>"><?php echo $konum[$i];?></option> 
<?php }?>
</select>
</form>
</td><td>
<?php 
}
?>
    <div id="map" style="width:640px; height:400px;"></div>
</td>
</tr>
</table>
</body>
</html>

OnlineDBIslemler Tamamını İndir

package com.example.ali.onlinedbkullanim;

import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;


import org.json.JSONArray;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,AdapterView.OnItemClickListener{
    Context c;
    EditText tad,tgun;
    Button btn;
    int[] id;
    String[] ad;
    ListView lv;
    ArrayList<String> liste;
    ArrayAdapter<String> adp;
    AlertDialog.Builder dialog;
    int secilen_id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        c=this;
        liste=new ArrayList<String>();
        lv=(ListView)findViewById(R.id.list);
        lv.setOnItemClickListener(this);
        adp=new ArrayAdapter<String>(c,android.R.layout.simple_list_item_1,liste);
        lv.setAdapter(adp);
        btn=(Button)findViewById(R.id.btn_ekle);
        btn.setOnClickListener(this);
        tad=(EditText)findViewById(R.id.tad);
        veri_getir();

    }
    public  void post(final Uri.Builder builder)
    {

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    URL url = new URL("http://alikomesogutlu.com/db.php");
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setReadTimeout(10000);
                    conn.setConnectTimeout(15000);
                    conn.setRequestMethod("POST");
                    conn.setDoInput(true);
                    conn.setDoOutput(true);

                    String query = builder.build().getEncodedQuery();

                    OutputStream os = conn.getOutputStream();//bağlantının cıkısı
                    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
                    writer.write(query);
                    writer.flush();
                    writer.close();
                    os.close();

                }
                catch (Exception ex)
                {
                    Log.d("hata",ex.getMessage());
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        veri_getir();
                    }
                });
            }
        }).start();
    }
public void veri_getir()
{
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    URL url = new URL("http://alikomesogutlu.com/db.php");
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

                    StringBuilder builder=new StringBuilder();
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

                    String json="";

                    while ((json = bufferedReader.readLine()) != null)
                        builder.append(json + "\n");

                    JSONArray jsonArray = new JSONArray(builder.toString().trim());
                     id = new int[jsonArray.length()];
                     ad = new String[jsonArray.length()];

                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject obj = jsonArray.getJSONObject(i);

                        id[i] = obj.getInt("id");
                        ad[i]=obj.getString("ad");
                    }
                }
                catch (Exception ex)
                {
                    Log.d("hata",ex.getMessage());
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                     liste.clear();
                     adp.notifyDataSetChanged();
                    for (int i=0;i<id.length;i++)
                        adp.add(ad[i]);
                    }
                });
            }
        }).start();
}
    @Override
    public void onClick(View view) {
        if(tad.getText().length()>0)
        {
            Uri.Builder builder = new Uri.Builder();//post paremetreleri ayarlanıyor
            builder.appendQueryParameter("ad",tad.getText()+"");
            builder.appendQueryParameter("durum", "0");
            post(builder);
            tad.setText("");
        }

    }
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        dialog=new AlertDialog.Builder(c);
        tgun=new EditText(c);
        tgun.setText(liste.get(i));
        secilen_id=id[i];
        dialog.setView(tgun);
        dialog.setTitle("Güncelle/Sil");
        dialog.setPositiveButton("Sil", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Uri.Builder builder = new Uri.Builder();//post paremetreleri ayarlanıyor
                builder.appendQueryParameter("id",secilen_id+"");
                builder.appendQueryParameter("durum", "1");
                post(builder);
            }
        });
        dialog.setNegativeButton("Güncelle", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                if(tgun.getText().length()>0) {
                    Uri.Builder builder = new Uri.Builder();//post paremetreleri ayarlanıyor
                    builder.appendQueryParameter("ad", tgun.getText() + "");
                    builder.appendQueryParameter("durum", "2");
                    builder.appendQueryParameter("id", secilen_id + "");
                    post(builder);
                }
                else
                    Toast.makeText(c,"Alan Boş bırakılamaz!!",Toast.LENGTH_LONG).show();
            }
        });
        dialog.create().show();
    }
}
<span id="mce_marker" data-mce-type="bookmark" data-mce-fragment="1">​</span>
<?php
 function conn(){
	 try{
	 return	$baglanti=new PDO('mysql:host=localhost;port=3306;dbname=Veritabanı ismi;charset=utf8',"Kulanıcı ismi","Şifre");
	}
	catch(PDOException $ex)
	{
		$ex->getMessage();
	}
 }
 
 function insert($ad)
 {
	 try{
		 $baglanti=conn();
	$sorgu1=$baglanti->prepare("insert into kisiler(ad) values(?)");
    $sorgu1->bindParam(1,$ad);
    $sorgu1->execute();
    $baglanti=null;
	}
	catch(PDOException $ex)
	{
		$ex->getMessage();
	}
 }
 function get_data()
 {
	 try{
		 $baglanti=conn();
	$sorgu=$baglanti->prepare("select * from kisiler order by id desc");
    $sorgu->execute();
	$veri=$sorgu->fetchAll(PDO::FETCH_ASSOC);
    $dizi;
	$sayac=0;
	foreach($veri as $deger)
	{
		$dizi[$sayac++]=['id'=>$deger["id"],'ad'=>$deger["ad"]];
	}
	$baglanti=null;
	echo json_encode($dizi);
	}
	catch(PDOException $ex)
	{
		$ex->getMessage();
	}
 }
  function update($ad,$id)
 {
	 try{
		 $baglanti=conn();
	$sorgu1=$baglanti->prepare("update kisiler set ad=? where id=?");
    $sorgu1->bindParam(1,$ad);
	$sorgu1->bindParam(2,$id);
    $sorgu1->execute();
    $baglanti=null;
	}
	catch(PDOException $ex)
	{
		$ex->getMessage();
	}
 }
  function data_delete($id)
 {
	 try{
		 $baglanti=conn();
	$sorgu1=$baglanti->prepare("delete from kisiler where id=?");
	$sorgu1->bindParam(1,$id);
    $sorgu1->execute();
    $baglanti=null;
	}
	catch(PDOException $ex)
	{
		$ex->getMessage();
	}	 
 }
  if(isset($_POST['ad'])&&isset($_POST['durum'])&&$_POST['durum']=='0')
 {
    insert($_POST['ad']);	 
 }
 else if(isset($_POST['id'])&&isset($_POST['durum'])&&$_POST['durum']=='1')
 {
    data_delete($_POST['id']);
 }
 else if(isset($_POST['ad'])&&isset($_POST['id'])&&isset($_POST['durum'])&&$_POST['durum']=='2')
 {
    update($_POST['ad'],$_POST['id']);
 }
 else{
	get_data();
 }
?>