Android Managers

1,445 views

Published on

Simple Usage of Android Managers

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,445
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Android Managers

    1. 1. paranoid android murat yener, eteration
    2. 2. news news news...
    3. 3. android developer ...where no manhas ever gone before
    4. 4. managers!!• Location• Telephony• Sms• Alarm• Notification• ...
    5. 5. ...where am i??// Acquire a reference to the system Location ManagerLocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);// Define a listener that responds to location updatesLocationListener locationListener = new LocationListener() {    public void onLocationChanged(Location location) {      // Called when a new location is found by the network location provider.      makeUseOfNewLocation(location);    }    public void onStatusChanged(String provider, int status, Bundle extras) {}    public void onProviderEnabled(String provider) {}    public void onProviderDisabled(String provider) {}  };// Register the listener with the Location Manager to receive location updateslocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); *will appear on market: Access your location
    6. 6. is my phone ringin’TelephonyManager tm = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE);if (tm.getCallState() != TelephonyManager.CALL_STATE_RINGING) { //do something}
    7. 7. lets move it!!SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);sensorManager.registerListener(this, sensorManager .getSensorList(Sensor.TYPE_ACCELEROMETER).get(0), SensorManager.SENSOR_DELAY_FASTEST);@Overridepublic void onAccuracyChanged(Sensor sensor, int accuracy) { // TODO Auto-generated method stub}@Overridepublic void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { ...
    8. 8. her yone 30000 sms!?1 SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(“5326167484”, null, “ara beniiii :P”, new PendingIntent(), null);*will appear on market:Services that can cost you money
    9. 9. let users know...NotificationManager mManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE);Notification mNotification = new Notification(R.drawable.icon, "Unanswered call!", // the text to display in the ticker System.currentTimeMillis()); // the time for the notificationmNotification.flags = Notification.FLAG_AUTO_CANCEL;/* Starting an intent */Intent myIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+ phoneNumber));myIntent.putExtra("extendedTitle", myNotifyTitle);myIntent.putExtra("extendedText", myNotifiyText);PendingIntent startIntent = PendingIntent.getActivity(context, 0,myIntent, 0);/* Set notification message */mNotification.setLatestEventInfo(context, myNotifyTitle,myNotifiyText, startIntent);/* Sent Notification to notification bar */mManager.notify(index++, mNotification);
    10. 10. NFC!!!!!NfcManager nfcManager = (NfcManager) this.getSystemService(Context.NFC_SERVICE); *coming to iOS sooooon...
    11. 11. user preferencesSharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences(); sharedPreferences.registerOnSharedPreferenceChangeListener(this); addPreferencesFromResource(R.xml.preferences);String message = sharedPreferences.getString("title", "My application");@Overridepublic void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {}
    12. 12. silence my phone AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);*will appear on market:Modifies your audio settings
    13. 13. laying outLayoutInflater inflater = (LayoutInflater) getContext().getSystemService (Context.LAYOUT_INFLATER_SERVICE);inflater.inflate(R.layout.second_preference, null);
    14. 14. toothacheBluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();if (mBluetoothAdapter == null) { // Device does not support Bluetooth}if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = newIntent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);}
    15. 15. who is there? // Create a BroadcastReceiver for ACTION_FOUNDprivate final BroadcastReceiver mReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); // When discovery finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); // Add the name and address to an array adapter to show in a ListView mArrayAdapter.add(device.getName() + "n" + device.getAddress()); } }};// Register the BroadcastReceiverIntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);registerReceiver(mReceiver, filter); // Dont forget to unregister during onDestroy
    16. 16. getting paired Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() > 0) { // Loop through paired devices for (BluetoothDevice device : pairedDevices) { // Add the name and address to an array adapter to show in a // ListView mArrayAdapter.add(device.getName() + "n" + device.getAddress()); } }*http://developer.android.com/guide/topics/wireless/bluetooth.html
    17. 17. many managers...• PowerManager• AccountManager• ActivityManager• AlarmManager• ServiceManager
    18. 18. many more managers...• WallpaperManager• ClipboardManager• DownloadManager• StorageManager

    ×