"Turn" Android phone send SMS, vibrate, play default ringtone

Source: Internet
Author: User

Send SMS

@SuppressWarnings ("deprecation")
public void SendMessage (string Phoneno, String messagecontent)
{
Smsmanager Smsmanager = Smsmanager.getdefault ();
Smsmanager.sendtextmessage (phoneno,//receiver's mobile phone number
null,//Sender's mobile phone number
messagecontent,//Information Content
null,//whether a successful receipt is sent
null//receive a successful receipt
);
}

Play default ringtone
Private MediaPlayer MediaPlayer = new MediaPlayer ();
public Boolean ring ()
{
Uri Ringtoneuri = Ringtonemanager.getdefaulturi (Ringtonemanager.type_ringtone);
Try
{
Mediaplayer.setdatasource (this, Ringtoneuri);

Final Audiomanager Audiomanager = (audiomanager) getsystemservice (Context.audio_service);
if (Audiomanager.getstreamvolume (audiomanager.stream_voice_call)! = 0)
{
Mediaplayer.setaudiostreamtype (Audiomanager.stream_voice_call);
Mediaplayer.setlooping (FALSE);
Mediaplayer.prepare ();
Mediaplayer.start ();
return true;
}
}
catch (Exception e)
{
E.printstacktrace ();
}
return false;
}

Stop playing Ringtones
public void stopring ()
{
Mediaplayer.stop ();
}

Vibration
public void Vibrate (int ms)//input vibration milliseconds
{
Vibrator Vibrator = (Vibrator) getsystemservice (Vibrator_service);

Vibrator.vibrate (MS);
}

When using, be careful to add permissions in Androidmanifest.xml

Send SMS Permission

<uses-permission android:name= "Android.permission.SEND_SMS"/>

Vibration Permissions
<uses-permission android:name= "Android.permission.VIBRATE"/>

The implementation can be encapsulated in the service provided by the call, how to implement see Android service call, the parameters.

"Turn" Android phone send SMS, vibrate, play default ringtone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.