仿360android打电话遮挡号码与通话后记录删除
来源:互联网 发布:mysql表格创建 编辑:程序博客网 时间:2024/06/06 03:04
先说下思路 首先点击拨号 进入一个是否拨通界面,选择确认后,调用系统直接拨打电话,然后判断拨打电话的状态,如果是拨通的状态下 用窗口管理器写一个遮挡物 遮挡住 如果不是拨通状态将遮挡物去掉,去掉完成当前activity,在onactivityforresult中执行查找通话记录进行删除。好了 开始上代码。
主界面mainactivity.class
拨号界面 mian2.class不要在意名字 随意写的
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 Intent(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 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 AndroidManifest.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 stubsuper.onActivityResult(requestCode, resultCode, data);if(resultCode==1){String num=data.getStringExtra("num");deleteFromCallLog(num);}}public void deleteFromCallLog(String num) { Log.i("values", "删除呼叫记录:" + num); Uri uri = Uri.parse("content://call_log/calls");// 得到呼叫记录内容提供者的路径 Cursor cursor = getContentResolver().query(uri, new 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,Uri.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) getSystemService(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 != null && 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 //窗口管理器WindowManager manager=(WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);WindowManager.LayoutParams params = new WindowManager.LayoutParams();params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; // 设置行为选项 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;//设置显示初始位置 屏幕左上角为原点// topWindow显示到最顶部manager.addView(view2, params);}@Overridepublic 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;}@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 AndroidManifest.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();}}清单文件 注意权限 和mian2的主题风格
<?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="19" /> <uses-permission android:name="android.permission.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.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="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 is 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 backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> <style name="Transparent"> <item name="android:windowBackground">@color/TRANS</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item> </style></resources>
下载地址http://download.csdn.net/detail/u012303938/8539783
0 1
- 仿360android打电话遮挡号码与通话后记录删除
- 【Android通话记录】仿小米通话
- 通话录
- 监控打电话与通话一段时间后自动挂断
- android 拨打紧急号码,通话时开启免提功能实现
- 《Head First HTML与CSS、XHTML》读后记录
- Android 遇到方法数上限65536后记录总结
- android根据号码删除短信
- android 发短信与打电话
- Android实现通话呼叫转移与监听通话录音功能
- android 拨号盘输入号码时来电,通话结束后回到拨号盘,如何保存之前输入的号码
- Android仿qq聊天记录待定与删除功能效果
- Android仿QQ聊天记录待定与删除功能效果
- Android仿QQ聊天记录待定与删除功能效果
- android删除某个号码的通话记录
- Android设定指定号码监听电话不弹拨号、通话界面,自动接听,关闭声音输出
- android通话
- Android 仿QQ 滑动删除
- Intel Thread Building Blocks (TBB) 入门篇
- clojure-基本语法-流程控制(一)
- Linux Kernel-3.10.72 Makefiles
- 理解SSL(https)中的对称加密与非对称加密
- 理解JavaScript中的事件路由冒泡过程及委托代理机制
- 仿360android打电话遮挡号码与通话后记录删除
- STL系列(7): 关联容器特点
- 第四周项目一 三角形的构造函数(4)
- ios开发之如何跳到AppStore给应用评分
- VS2010下64位Mongodb环境配置过程
- clojure-基本语法-流程控制(二)
- 重置遗忘的mysql密码
- 题目1055 数组逆置 九度Online Judge
- rewind函数