Android set blacklist functionality based on Audiomanager, Phonestatelistener implementation _android

Source: Internet
Author: User
Tags gettext

This article describes the Android based on Audiomanager, Phonestatelistener implementation set blacklist feature. Share to everyone for your reference, specific as follows:

The mobile phone generally has the function of setting a blacklist. This example by setting the phone blacklist, when the phone call in the black list, the phone ring to mute.

The program code is as follows:

Import android.app.Activity;
Import Android.content.Context;
Import Android.media.AudioManager;
Import Android.os.Bundle;
Import Android.telephony.PhoneStateListener;
Import Android.telephony.TelephonyManager;
Import android.view.KeyEvent;
Import Android.view.View;
Import Android.view.View.OnKeyListener;
Import Android.widget.EditText;
Import Android.widget.TextView;
Import Android.widget.Toast; public class A11activity extends activity {Private EditText et;//Add input box, enter and set blacklist private TextView tv01,tv02;//tv01 to display E A blacklist entered in the Dittext; Tv02 is used to display the status of the current cell phone/** called when the active is the. */@SuppressWarnings ("static-access") @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (
    Savedinstancestate);
    Setcontentview (R.layout.main);
    tv01= (TextView) Findviewbyid (R.ID.TV01);
    Tv02= (TextView) Findviewbyid (R.ID.TV02);
    et= (EditText) Findviewbyid (r.id.et);
    /** to create Phonecalllistener objects; Phonecalllistener is * extended Phonestatelistener class * *Phonecalllistener pcl=new Phonecalllistener ();
    Telephonymanager tm= (Telephonymanager) Getsystemservice (Telephony_service); Set up the function of the listening telephone Tm.listen (PCL, PCL.
  Listen_call_state); public class Phonecalllistener extends phonestatelistener{public void oncallstatechanged (int state,string incoming Number) {When switch (state) {//Mobile status is standby, the phone ringtone is normal mode case TelephonyManager.CALL_STATE_IDLE:tv02.setText ("Call_state_
    IDLE ");
    Audiomanager am= (Audiomanager) Getsystemservice (Context.audio_service);
    Am.setmode (Audiomanager.mode_normal);
    Am.getstreamvolume (audiomanager.stream_ring);
    Break
    Mobile status for the call in case TelephonyManager.CALL_STATE_OFFHOOK:tv02.setText ("Call_state_offhook");
    Break
    Cell phone mode for the bell when Case TelephonyManager.CALL_STATE_RINGING:tv02.setText ("call_state_ringing"); When the phone number is the same as the list number in the blacklist, set the ringtone to mute if (Incomingnumber.equals (Tv01.gettext (). toString ())) {Audiomanager am01= (Audiomana
    GER) Getsystemservice (Audio_service); Am01.sEtringermode (audiomanager.ringer_mode_silent);
    Am01.getstreamvolume (audiomanager.stream_ring); Toast.maketext (A11activity.this, "The blacklist in the phone mute!!)
    ", Toast.length_long). Show ();
   } super.oncallstatechanged (state, Incomingnumber);
    Et.setonkeylistener (New Onkeylistener () {@Override public boolean onkey (View v, int keycode, keyevent event) {
    TODO auto-generated Method Stub Tv01.settext (Et.gettext ());
    Et.settext ("");
    return true;
   }
    });

 }
  }
}

More interested readers of Android-related content can view this site: "The summary of Android controls usage" and "Android Development introduction and Advanced Course"

I hope this article will help you with the Android program.

Related Article

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.