Imitation 360android phone mask number and post-call record deletion

Source: Internet
Author: User

First of all, the idea of first click Dial to enter an interface, select confirm, call the system calls directly, and then determine the status of the call, if it is dialed in the State with the window manager to write a block occlusion if not dialed state will be removed, remove the completion of the current activity, in O Perform a find call record in Nactivityforresult to delete. Okay, start on the code.

Main interface Mainactivity.class


Dial-up interface Mian2.class don't mind the names.

Package Com.example.callphone;import Android.support.v7.app.actionbaractivity;import Android.support.v7.app.actionbar;import Android.support.v4.app.fragment;import Android.content.Intent;import Android.database.cursor;import Android.net.uri;import Android.os.bundle;import Android.util.Log;import Android.view.layoutinflater;import Android.view.menu;import Android.view.menuitem;import Android.view.View;import Android.view.viewgroup;import Android.view.view.onclicklistener;import Android.widget.button;import Android.os.build;public class Mainactivity extends Actionbaractivity {private Button button1;//private WindowManager Manager; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); button1= (Button) Findviewbyid (R.id.button1); Button1.setonclicklistener ( New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubintent Intent = new Inte NT (Mainactivity.this,main2.class); StArtactivityforresult (Intent, 0); }});} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;} @Overridepublic boolean onoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The action bar will//automatically handle clicks on the Home/up button so long//as you specify a parent activity in and RoidManifest.xml.int id = item.getitemid (); if (id = = r.id.action_settings) {return true;} return super.onoptionsitemselected (item);} /** * A placeholder fragment containing a simple view. */public Static class Placeholderfragment extends Fragment {public placeholderfragment () {} @Overridepublic View Oncreateview (Layoutinflater inflater, ViewGroup container,bundle savedinstancestate) {View RootView = inflater.inflate (R.layout.fragment_main, container, false); return rootview;}} @Overrideprotected void OnDestroy () {//TODO auto-generated MethOD stub//manager.removeview (view); Super.ondestroy ();} @Overrideprotected void Onactivityresult (int requestcode, int resultcode, Intent data) {//TODO auto-generated method stub Super.onactivityresult (Requestcode, ResultCode, data); if (resultcode==1) {String num=data.getstringextra ("num"); Deletefromcalllog (num);}}        public void Deletefromcalllog (String num) {log.i ("values", "Delete call record:" + num); Uri uri = uri.parse ("Content://call_log/calls");//Gets the path of the call record content provider cursor cursor = getcontentresolver (). query (URI, n        EW string[] {"_id"}, "Number=?", new string[] {num}, NULL);                while (Cursor.movetonext ()) {String id = cursor.getstring (0);        Getcontentresolver (). Delete (URI, "_id=?", new string[] {ID}); } cursor.close ();}}

Package Com.example.callphone;import Android.app.activity;import Android.support.v4.app.fragment;import Android.telephony.phonestatelistener;import Android.telephony.telephonymanager;import android.app.Activity; Import Android.content.context;import android.content.intent;import android.net.uri;import android.os.Bundle; Import Android.view.gravity;import Android.view.keyevent;import Android.view.layoutinflater;import Android.view.menu;import Android.view.menuitem;import Android.view.view;import Android.view.View.OnClickListener; Import Android.view.viewgroup;import Android.view.windowmanager;import Android.widget.button;import Android.widget.toast;import Android.os.build;public class Main2 extends Activity {private Button btn_qs,btn_qr;// Private WindowManager manager;private view view; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.cellphone); btn_qr= (Button) Findviewbyid (R.ID.BTN_QR) ; btn_qs= (Button) Findviewbyid (r.id.BTN_QS); View=view.inflate (this, r.layout.window, null); Btn_qr.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubintent Intent = new Intent (Intent.action_call,ur I.parse ("Tel:" + "10086"); Intent.putextra ("Num", "10086"); Setresult (1, intent); startactivity (intent); Listionpho () ;}}); Btn_qs.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubfinish ();}});} private void Listionpho () {//TODO auto-generated method Stubtelephonymanager Telmanager = (telephonymanager) Getsystemse  Rvice (Context.telephony_service); Phonestatelistener listener=new Phonestatelistener () {@Overridepublic void oncallstatechanged (int state, String Incomingnumber) {//TODO auto-generated Method Stubswitch (state) {case TelephonyManager.CALL_STATE_IDLE:if (view! = nul L && View.isshown ()) {WindowManager WindowManager = (WindowManager) getapplicationcontext (). Getsystemservice ( Window_serviCE); Windowmanager.removeview (view); Finish ();} Manager=null;break;case Telephonymanager.call_state_offhook://manager.removeview (view); ShowView (view); break; Default:break;}}; Telmanager.listen (Listener, phonestatelistener.listen_call_state);} protected void ShowView (View view2) {//TODO auto-generated Method Stub//window manager WindowManager manager= (windowmanager ) Getapplicationcontext (). Getsystemservice (Window_service); Windowmanager.layoutparams params = new Windowmanager.layoutparams ();p arams.type = WindowManager.LayoutParams.TYPE_ System_alert |  WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; Set behavior Options params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; Params.gravity=gravity.top;params.width = Windowmanager.layoutparams.fill_parent;params.height = windowmanager.layoutparams.wrap_content;//settings Display the initial position screen in the upper left corner for the origin//Topwindow display to the top Manager.addview (view2, params);} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//InflateThe menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true;} @Overridepublic boolean onoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The action bar will//automatically handle clicks on the Home/up button so long//as you specify a parent activity in and RoidManifest.xml.int id = item.getitemid (); if (id = = r.id.action_settings) {return true;} return super.onoptionsitemselected (item);} /** * A placeholder fragment containing a simple view. */public Static class Placeholderfragment extends Fragment {public placeholderfragment () {} @Overridepublic View Oncreateview (Layoutinflater inflater, ViewGroup container,bundle savedinstancestate) {View RootView = inflater.inflate (R.layout.fragment_main, container, false); return rootview;}} @Overrideprotected void OnDestroy () {//TODO auto-generated method Stub//manager.removeview (view); Super.ondestroy ();}}
Checklist file attention to permissions and Mian2 theme styles

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/        Android "package=" Com.example.callphone "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "8" android:targetsdkversion= "/> <uses-permission android:name=" Android.permi Ssion. System_alert_window "/> <uses-permission android:name=" Android.permission.READ_PHONE_STATE "/> < Uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name= " Android.permission.READ_CALL_LOG "/> <uses-permission android:name=" Android.permission.CALL_PHONE "/> <         Uses-permission android:name= "Android.permission.WRITE_CALL_LOG"/> <application android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" android:theme= "@style/apptheme "> <activity android:name="Com.example.callphone.MainActivity "android:label=" @string/app_name "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "android.in Tent.category.LAUNCHER "/> </intent-filter> </activity> <activity Android:na Me= "com.example.callphone.Main2" android:theme= "@style/transparent" ></activity> </application> </manifest>

Colors.xml

<?xml version= "1.0" encoding= "Utf-8"?><resources> <color    name= "TRANS" > #b0000000 </color >     <color name= "White" > #ffffffff </color></resources>

Styles.xml

<resources> <!--Base application theme, dependent on API level.    This theme are replaced by Appbasetheme from Res/values-vxx/styles.xml on newer devices. --<style name= "Appbasetheme" parent= "Theme.AppCompat.Light" > <!--Theme customizations Available in newer API levels can go in res/values-vxx/styles.xml, while customizations related to B        Ackward-compatibility can go here. -</style> <!--application theme.  --<style name= "Apptheme" parent= "Appbasetheme" > <!--all customizations that is not specific to a Particular api-level can go here. -</style> <style name= "Transparent" > <item name= "android:windowbackground" > @color/tr ans</item> <item name= "Android:windownotitle" >true</item> <item name= "Android: Windowistranslucent ">true</item> <item name=" Android:windowanimationstyle "&GT;@+android:style/animation.translucent</item> </style></resources> 

http://download.csdn.net/detail/u012303938/8539783


Imitation 360android phone mask number and post-call record deletion

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.