"Android" call Hover window

Source: Internet
Author: User

Let's see.

Next idea:

1: Listen to the call broadcast

2: According to the call number, and the local database to do matching, recorded, then extract the avatar, name, position, create a suspended window

3: Listen to the call broadcast, if the current behavior is idle (no call behavior), delete the suspended window.

Tips: The original use of services to monitor, unfortunately in the background service lock screen after a period of time is very easy to kill, tried various methods ineffective, so the use of listening to the broadcast, but in the Meizu mobile testing, found that need to allow (boot from the boot), or the same can not listen to the broadcast

After talking about the idea, we put the code on, the logic is very simple, not much to repeat.

1: Listen to incoming call class

Remember to add a permission statement to Androidmanifest.xml

 <receiverAndroid:name= ". Call. Incomingcallbroadcastreceiver ">            <Intent-filterandroid:priority= "+">                <ActionAndroid:name= "Android.intent.action.PHONE_STATE" />            </Intent-filter>        </receiver>

 PackageZhexian.app.smartcall.call;ImportAndroid.app.Service;ImportAndroid.content.BroadcastReceiver;ImportAndroid.content.Context;Importandroid.content.Intent;ImportAndroid.telephony.TelephonyManager;ImportAndroid.view.View;ImportAndroid.view.WindowManager;Importzhexian.app.smartcall.base.BaseApplication; Public classIncomingcallbroadcastreceiverextendsBroadcastreceiver {Private StaticView Addedview =NULL; @Override Public voidOnReceive (Context context, Intent Intent) {Telephonymanager Tmanager=(Telephonymanager) Context.getsystemservice (Service.telephony_service); intCallstate =tmanager.getcallstate (); Switch(callstate) { CaseTelephonyManager.CALL_STATE_RINGING:removeView (context); Callflatwindowmanager WindowManager=NewCallflatwindowmanager ((baseapplication) Context.getapplicationcontext ()); String Incomingnumber= Intent.getstringextra ("Incoming_number"); Addedview=Windowmanager.oncall (Incomingnumber);  Break;  CaseTelephonyManager.CALL_STATE_IDLE:removeView (context);  Break; }    }    voidRemoveview (Context context) {if(Addedview = =NULL)            return; Try{WindowManager WindowManager=(WindowManager) Context.getsystemservice (Context.window_service);        Windowmanager.removeviewimmediate (Addedview); } Catch(Exception e) {e.printstacktrace (); } finally{Addedview=NULL; }    }}

Suspended window Implementation code is also posted, for your reference only

Create a non-touchable form with WindowManager

 PackageZhexian.app.smartcall.call;ImportAndroid.content.Context;ImportAndroid.graphics.PixelFormat;Importandroid.view.Gravity;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.WindowManager;ImportAndroid.widget.ImageView;ImportAndroid.widget.TextView;ImportZHEXIAN.APP.SMARTCALL.R;Importzhexian.app.smartcall.base.BaseApplication;Importzhexian.app.smartcall.lib.ZContact;ImportZhexian.app.smartcall.lib.ZIO;Importzhexian.app.smartcall.lib.ZString;Importzhexian.app.smartcall.tools.Utils;/*** Call Suspension Window Management class*/ Public classCallflatwindowmanager {Private intimage_size = 128; PrivateWindowManager Mwindowmanager; PrivateWindowmanager.layoutparams Layoutparams; Privateview view; PrivateTextView Musername; PrivateTextView Mjob; Privatebaseapplication Baseapp; PrivateImageView ImageView;  PublicCallflatwindowmanager (baseapplication baseapp) { This. Baseapp =Baseapp;        Initwindow ();    Contactsqlhelper.init (Baseapp); }     PublicView OnCall (String incomingnumber) {if(Zcontact.isphoneexists (Baseapp, incomingnumber))return NULL; Calluserentity Entity=contactsqlhelper.getinstance (). GetContact (Incomingnumber); if(Entity = =NULL)            return NULL; returnAttachwindow (Entity.getname (), Entity.getjob (), Entity.getavatarurl ()); }    PrivateView Attachwindow (String userName, String job, string url) {musername.settext (userName);        Mjob.settext (Job);        LoadImage (URL);        Mwindowmanager.addview (view, layoutparams); returnview; }    Private voidInitwindow () {Mwindowmanager=(WindowManager) Baseapp.getsystemservice (Context.window_service); Layoutparams=NewWindowmanager.layoutparams (); Layoutparams.width=WindowManager.LayoutParams.WRAP_CONTENT; Layoutparams.height=WindowManager.LayoutParams.WRAP_CONTENT; Layoutparams.gravity= Gravity.top |Gravity.center_horizontal; Layoutparams.format=pixelformat.rgba_8888; Layoutparams.type=WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; Layoutparams.flags= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; Layoutinflater Inflater=(Layoutinflater) Baseapp.getsystemservice (Context.layout_inflater_service); View= Inflater.inflate (R.layout.call_flat_window,NULL); Musername=(TextView) View.findviewbyid (r.id.flat_user_name); ImageView=(ImageView) View.findviewbyid (R.id.flat_user_avatar); Mjob=(TextView) View.findviewbyid (r.id.flat_user_job); }    Private voidloadimage (String url) {if(Url.isempty ()) {imageview.setvisibility (view.gone); return; } String Cachedurl=zstring.getfilecacheddir (URL, Baseapp.getfilepath ()); if(Zio.isexist (Cachedurl)) Imageview.setimagebitmap (Utils.getscaledbitmap (Cachedurl, image_size, IMAGE_SIZE)        ); Elseimageview.setvisibility (View.gone); }}

Android call Hover window

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.