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( ...
随机推荐
- 【转】PL/SQL编辑数据"这些查询结果不可更新,请包括ROWID或使用SELECT...FOR UPDATE获得可更新结果"处理
[转]PL/SQL编辑数据"这些查询结果不可更新,请包括ROWID或使用SELECT...FOR UPDATE获得可更新结果"处理 只要有人用了: select t.* from ...
- linux shell if参数
shell 编程中使用到得if语句内判断参数 –b 当file存在并且是块文件时返回真 -c 当file存在并且是字符文件时返回真 -d 当pathname存在并且是一个目录时返回真 -e 当path ...
- oc语言学习之基础知识点介绍(一):OC介绍
一.第一个OC程序 #import <Foundation/Foundation.h> //导入头文件 int main(int argc, const char * argv[]) ...
- 接收Firfox RESTClient #Post请求
什么是 RESTClient 请参考:http://www.blogjava.net/paulwong/archive/2014/04/19/412688.html 对接接口时经常会需要传个异步回调消 ...
- QT/C++ 智能指针
什么是智能指针? 为什么用智能指针? 还有哪些关于内存管理方面的知识点,需要注意的?
- 关于“undefined reference to”错误
哪些问题可能产生undefined reference to错误? 1.没用生成目标文件 比如说hello.o文件,由于名字写错.路径不对.Makefile缺少. 2.没用添加相应的库文件.so/dl ...
- 代码静态分析工具PCLint, Splint
一.PCLint REFER: 代码静态检查工具PC-Lint运用实践 二.Splint 1.在PC-Linux上安装 ①make error undefined reference toyywrap ...
- SVN: revert all command
If you accidentally marked all your files as "delete" (your file/folder has a red x on it) ...
- Java初始化理解与总结 转载
Java的初始化可以分为两个部分: (a)类的初始化 (b)对象的创建 一.类的初始化 1.1 概念介绍: 一个类(class)要被使用必须经过装载,连接,初始化这样的过程. 在装载阶段,类装载器会把 ...
- [翻译][MVC 5 + EF 6] 5:Code First数据库迁移与程序部署
原文:Code First Migrations and Deployment with the Entity Framework in an ASP.NET MVC Application 1.启用 ...