25 Ocak 2017 Çarşamba

ActivityManager Sınıfı

constructor
Şöyle yaparız.
ActivityManager am = (ActivityManager)
  context.getSystemService(Context.ACTIVITY_SERVICE);
getRunningAppProcesses metodu
RunningAppProcessInfo dizisi döndürür. Şöyle yaparız.
List<ActivityManager.RunningAppProcessInfo> appProcesses = 
  am.getRunningAppProcesses();
if (appProcesses == null) {
  return;
}

for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {

  Log.e(TAG, "Process Name : " + appProcess.processName);

  ...
}

17 Ocak 2017 Salı

Google-Maps GoogleMap.OnMapReadyCallback Arayüzü

Giriş
Şu satırı dahil ederiz.
import com.google.android.gms.maps.OnMapReadyCallback;
GoogleMap ile gelen SupportMapFragment kullanarak şöyle yaparız.
@Override
public 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);
    new GetAddress().execute();
}
onMapReady metodu
Şöyle yaparız
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

public GoogleMap mMap;
...


  @Override
  public void onMapReady(GoogleMap googleMap) {

    mMap = googleMap;
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    if (ContextCompat.checkSelfPermission(this,
      Manifest.permission.ACCESS_FINE_LOCATION)
        == PackageManager.PERMISSION_GRANTED) {
    mMap.setMyLocationEnabled(true);
  }
    mMap.getUiSettings().setCompassEnabled(true);
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(true);
  ...
  }
...
}

14 Ocak 2017 Cumartesi

FirebaseDatabase Sınıfı

Giriş
Şu satırı dahil ederiz.
import com.google.firebase.database.FirebaseDatabase;
Eğer security ayarlarında "public" seçili ise URL'yi bilen herkes veritabanına erişebilir.

getInstance metodu
Şöyle yaparız.
FirebaseDatabase db = FirebaseDatabase.getInstance();
getReference metodu
Şöyle yaparız.
DatabaseReference ref = db.getReference("Movie");
setPersistenceEnabled metodu
Açıklaması şöyle
public synchronized void setPersistenceEnabled (boolean isEnabled)
The Firebase Database client will cache synchronized data and keep track of all writes you've initiated while your application is running. It seamlessly handles intermittent network connections and re-sends write operations when the network connection is restored. However by default your write operations and cached data are only stored in-memory and will be lost when your app restarts. By setting this value to true, the data will be persisted to on-device (disk) storage and will thus be available again when the app is restarted (even when there is no network connectivity at that time). Note that this method must be called before creating your first Database reference and only needs to be called once per application.
Şöyle yaparız.
db.setPersistenceEnabled (true);

6 Ocak 2017 Cuma

Manifest Sınıfı

Giriş
Şu satırı dahil ederiz.
import android.Manifest;
permission Alanı
Her alan bir String. Şöyle yaparız.
Manifest.permission.ACCESS_COARSE_LOCATION
Manifest.permission.ACCESS_FINE_LOCATION
Manifest.permission.CALL_PHONE
Manifest.permission.CAMERA
Manifest.permission.READ_EXTERNAL_STORAGE
Manifest.permission.READ_SMS
Manifest.permission.WRITE_EXTERNAL_STORAGE

AppCompatActivity Sınıfı

Giriş
Şu satırı dahil ederiz.
import android.support.v7.app.AppCompatActivity;
Kalıtmak şöyle yaparız.
public class MainActivity extends AppCompatActivity {...}
OnCreate metodu
Şöyle yaparız.
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  ...
}
OnDestroy metodu
Şöyle yaparız.
@Override
protected void onDestroy() {
  super.onDestroy();
  ...
}

PowerManager Sınıfı

newWakeLock metodu
Şöyle yaparız.
WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 
"abc");
wakeLock.acquire();

2 Ocak 2017 Pazartesi

AndroidManifest.xml

Manifest Tag
En dıştadır. Şeklen şöyledir.
<manifest>
  <application>
    ...
  </application>
</manifest>
Application Tag
Application tag içinde Activity Tag'leri bulunur. Şeklen şöyledir.
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>

  <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity ...>
      ...
    </activity>

  </application>
</manifest>
icon
Şöyle yaparız.
<application
    android:name="Yourpackage.MyApplication"
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:logo="@drawable/your_logo"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:replace="android:icon">

    <!-- Your activities -->
</application>
label - Uygulama Adı
Şöyle atanır.
<application>
    android:label="App name here" 
    ...
</application>
name - Sınıf Adı
Şöyle bir  sınıfımız olsun
public class MyApplication extends Aplication {
   public static MusicService serviceMusic;  
}
Şöyle tanımlarız.
<application ...
    android:name="YourPackage.MyApplication">
Kod içinde public static alanlara erişirmek için şöyle yaparız.

MyApplication.serviceMusic;  
supportsRtl - Right to Left
Açıklaması şöyle. Sağdan sonra yazıyı destekleyip desteklemediğiniz gösterir.
Declares whether your application is willing to support right-to-left (RTL) layouts.
If set to true and targetSdkVersion is set to 17 or higher, various RTL APIs will be activated and used by the system so your app can display RTL layouts. If set to false or if targetSdkVersion is set to 16 or lower, the RTL APIs will be ignored or will have no effect and your app will behave the same regardless of the layout direction associated to the user's Locale choice (your layouts will always be left-to-right).
The default value of this attribute is false.
This attribute was added in API level 17.
Şöyle yaparız
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
...
</application>
Activity Tag
launchMode
4 farklı değer alabilir

Permission Tag
Şöyle yaparız.
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
  <uses-permission android:name = "android.permission.INTERNET"/>

  <application ...>
    <activity ...>

      <intent-filter>
          <action .../>
          <category .../>
      </intent-filter>
    </activity>
  </application>

</manifest>
Provider Tag
Application Tag içindedir. Şeklen şöyledir
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.rlaville.gestionsav" >

  <application ...>
    ...
    <provider
      android:name="..."
      android:authorities="..."
      android:exported="true">    </provider>

  </application>
</manifest>


1 Ocak 2017 Pazar

FirebaseRecyclerAdapter Sınıfı

constructor
Şöyle yaparız.
FirebaseRecyclerAdapter<Foo, FooViewHolder> firebaseRecyclerAdapter = 
  new FirebaseRecyclerAdapter<Foo, FooViewHolder>(
    Foo.class, R.layout.foo_list_item, FooViewHolder.class,
    databaseReference);
populateViewHolder metodu
Şöyle yaparız.
@Override
protected void populateViewHolder(FooViewHolder viewHolder,
  Foo model, int position) {
  viewHolder.setX(model.getX());
  viewHolder.setY(model.getY());
  viewHolder.setZ(getApplicationContext(), model.getZ());
}