Tuesday, September 7, 2010

Vibrate ,Lock the screen,getPhonenumber in android

Vibrate the Phone


You can vibrate the phone for a specified duration like so: 
(Vibrator) getSystemService(Context.VIBRATOR_SERVICE).vibrate(milliseconds);


You can use the AudioManager to enable and disable silent mode. 
mAudio = (AudioManager) getSystemService(Activity.AUDIO_SERVICE);
mAudio.setRingerMode(AudioManager.RINGER_MODE_SILENT);  

 to lock the screen in an Android app?

Remember you need to give permissions for it:
and add these lines to code.
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE); 
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); 
lock.disableKeyguard(); 

How to get my telephone number?

add the line uses-permission android:name="android.permission.READ_PHONE_STATE" to the manifest.xml 
 TelephonyManager mTelephonyMgr;
 mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
 String phonenumber= mTelephonyMgr.getLine1Number();


No comments:

Post a Comment

Android Developers Blog

Ram's shared items