android 监听去电实现ip拨号 广播接收者
利用广播实现ip拨号
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
> <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="请输入ip号码前缀"
/> <EditText
android:id="@+id/phoneNum"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"/> <Button
android:text="保存"
android:onClick="click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
activity:
package com.heyiyong.ipdial; import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText; public class MyActivity extends Activity {
EditText editText; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); this.editText = (EditText) findViewById(R.id.phoneNum); SharedPreferences sharedPreferences = getSharedPreferences("config", Context.MODE_PRIVATE);
String number = sharedPreferences.getString("number", "");
editText.setText(number);
} public void click(View view) {
SharedPreferences sharedPreferences = getSharedPreferences("config", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("number", editText.getText().toString());
editor.commit();
}
}
接收者:
package com.heyiyong.ipdial; import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; /**
* Created by Administrator on 14-1-2.
*/
public class DialReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String currentNumber = getResultData();
//获取设置的ip号前缀
SharedPreferences sharedPreferences = context.getSharedPreferences("config", Context.MODE_PRIVATE);
String ipNumber = sharedPreferences.getString("number","");
String newNumber = ipNumber+currentNumber;
setResultData(newNumber);
}
}
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.heyiyong.ipdial"
android:versionCode="1"
android:versionName="1.0"> <uses-sdk android:minSdkVersion="18"/> <!--去电号码获取-->
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> <application
android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity
android:name="MyActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity> <!-- 去电广播接收者 -->
<receiver android:name=".DialReceiver">
<intent-filter>
<!--监听去电-->
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver> </application>
</manifest>
android 监听去电实现ip拨号 广播接收者的更多相关文章
- 【Android】Android 监听apk安装替换卸载广播
[Android]Android 监听apk安装替换卸载广播 首先是要获取应用的安装状态,通过广播的形式 以下是和应用程序相关的Broadcast Action ACTION_PACKAGE_ADDE ...
- Android 监听apk安装替换卸载广播
首先是要获取应用的安装状态,通过广播的形式 以下是和应用程序相关的Broadcast Action ACTION_PACKAGE_ADDED 一个新应用包已经安装在设备上,数据包括包名(最新安装的包程 ...
- Android监听来电和去电
要监听android打电话和接电话,只需下面2步骤1.第一步,写一个Receiver继承自BroadcastReceiver import android.app.Service; import an ...
- Android 监听wifi广播的两种方式
1.XML中声明 <receiver android:name=".NetworkConnectChangedReceiver" > <i ...
- Android监听系统短信数据库变化-提取短信内容
由于监听系统短信广播受到权限的限制,所以很多手机可能使用这种方式没法监听广播,从而没办法获取到系统短信,所以又重新开辟一条路. Android监听系统短信数据库内容变化使用场景: 1.监听短信数据库的 ...
- Android监听应用程序安装和卸载
Android监听应用程序安装和卸载 第一. 新建监听类:BootReceiver继承BroadcastReceiver package com.rongfzh.yc; import android. ...
- Android监听手机网络变化
Android监听手机网络变化 手机网络状态发生变化会发送广播,利用广播接收者,监听手机网络变化 效果图 注册广播接收者 <?xml version="1.0" encodi ...
- Android监听自身卸载,弹出用户反馈调查
1,情景分析 在上上篇博客中我写了一下NDK开发实践项目,使用开源的LAME库转码MP3,作为前面几篇基础博客的加深理解使用的,但是这样的项目用处不大,除了练练NDK功底.这篇博客,我将讲述一下一个各 ...
- Android监听返回键、Home键+再按一次返回键退出应用
Android监听返回键需重写onKeyDown()方法 Home键keyCode==KeyEvent.KEYCODE_HOME @Override public boolean onKeyDown( ...
随机推荐
- Linq 查询 与方法调用
通常,使用linq查询时需要一个实现IQueryable<T> 的查询对象 public class DataA<T> : IQueryable<T> {....} ...
- Java实战之04JavaWeb-04JSP、EL表达式、JSTL标签库
一.jsp部分 只要是与页面显示相关的都是重点 1.jsp的脚本 <%java代码%>:被翻译到service方法内部,局部变量,局部的功能 <%=表达式或变量%>:翻译成se ...
- [Effective Objective-C 读书笔记] 第1章 几条基本写法 (2~5条)
我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3575599.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...
- OpenJudge / Poj 1928 The Peanuts C++
链接地址:http://bailian.openjudge.cn/practice/1928 题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 Mr. Robinson and h ...
- BootstrapDialog点击空白处禁止关闭
在乐学一百的项目当中引用到了BootstrapDialog,其中后台发送短信时,为了防止管理员编辑了半天的短息,突然间因为点击某个空白区域导致丢失,所以在此禁用掉点击空白关闭弹出框. 主要属性为: c ...
- mysql---多表关联
首先要介绍一下集合的概念:集合具有无序性.唯一性. 无序性:指集合内部元素没有相对顺序的概念,对于两个集合而言,只要元素值和元素个数相同则两个集合相等. 唯一性:指集合内部元素不存在值相等的元素. 上 ...
- javascript调用外部wpf的方法
今天因为项目需要在wpf嵌入web页面,然后在web页面调用wpf的方法,于是突击学习了一下,记下备忘.^_^ 1.wpf中新建一个类WpfForScriptingHelper namespace w ...
- Sublime Text 3使用技巧总结--快捷键及常用插件
1.Goto Anything(快速搜索) |--Ctrl+p 输入|--①文件名 |--②@+函数名 |--③:+数字 ->跳转到相应行 |--④#+变量名 2.多行游标 |--|--Alt+ ...
- 解决IE6下Position:fixed问题(只用css)
在IE6.0及以下版本的浏览器里是不支持position:fixed.而在IE7,IE8,firefox,opera,chrome都可以完美的支持此特性的.解决此问题的要点主要有: 1).容器要有一个 ...
- bootstrap .col-md-6 文字居中问题处理