Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Saturday, 6 April 2013

Android Devices-How to lock the screen in an Android app?


Remember you need to give permissions for it:

KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();




Android System How to get your application informations?

      Want to print what you put in your manifest? 


PackageManager manager = this.getPackageManager();
try {
   PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
   String packageName = info.packageName;
   int versionCode = info.versionCode;
   String versionName = info.versionName;
   } catch (NameNotFoundException e) {
   // TODO Auto-generated catch block
   }

Android Using devices How to vibrate the phone for a certain time?



   This code vibrates the phone for 1000 milliseconds. After getting the vibrator service with Context.getSystemService we call Vibrator.vibrate for a given time in milliseconds. 

   Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

   // 1. Vibrate for 1000 milliseconds
    long milliseconds = 1000;
    v.vibrate(milliseconds);

   // 2. Vibrate in a Pattern with 500ms on, 500ms off for 5 times
    long[] pattern = { 500, 300 };
    v.vibrate(pattern, 5);

Disqus for Android