利用广播实现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拨号 广播接收者的更多相关文章

  1. 【Android】Android 监听apk安装替换卸载广播

    [Android]Android 监听apk安装替换卸载广播 首先是要获取应用的安装状态,通过广播的形式 以下是和应用程序相关的Broadcast Action ACTION_PACKAGE_ADDE ...

  2. Android 监听apk安装替换卸载广播

    首先是要获取应用的安装状态,通过广播的形式 以下是和应用程序相关的Broadcast Action ACTION_PACKAGE_ADDED 一个新应用包已经安装在设备上,数据包括包名(最新安装的包程 ...

  3. Android监听来电和去电

    要监听android打电话和接电话,只需下面2步骤1.第一步,写一个Receiver继承自BroadcastReceiver import android.app.Service; import an ...

  4. Android 监听wifi广播的两种方式

    1.XML中声明 <receiver android:name=".NetworkConnectChangedReceiver" >             <i ...

  5. Android监听系统短信数据库变化-提取短信内容

    由于监听系统短信广播受到权限的限制,所以很多手机可能使用这种方式没法监听广播,从而没办法获取到系统短信,所以又重新开辟一条路. Android监听系统短信数据库内容变化使用场景: 1.监听短信数据库的 ...

  6. Android监听应用程序安装和卸载

    Android监听应用程序安装和卸载 第一. 新建监听类:BootReceiver继承BroadcastReceiver package com.rongfzh.yc; import android. ...

  7. Android监听手机网络变化

    Android监听手机网络变化 手机网络状态发生变化会发送广播,利用广播接收者,监听手机网络变化 效果图 注册广播接收者 <?xml version="1.0" encodi ...

  8. Android监听自身卸载,弹出用户反馈调查

    1,情景分析 在上上篇博客中我写了一下NDK开发实践项目,使用开源的LAME库转码MP3,作为前面几篇基础博客的加深理解使用的,但是这样的项目用处不大,除了练练NDK功底.这篇博客,我将讲述一下一个各 ...

  9. Android监听返回键、Home键+再按一次返回键退出应用

    Android监听返回键需重写onKeyDown()方法 Home键keyCode==KeyEvent.KEYCODE_HOME @Override public boolean onKeyDown( ...

随机推荐

  1. oracle怎么查看表字段的类型

    select column_name,data_type,DATA_LENGTH From all_tab_columns where table_name=upper('表名') AND owner ...

  2. T-SQL切割字符串方法小结

    T-SQL切割字符串方法小结,只有表值函数那个是自己的思想,其它都是来源于网络的思想,请大家不要笑话,嘻嘻~网上大牛太多,这点东西虽然上不了台面,但是也算是自己的一个学习吧,能够对一个人有用也行.再不 ...

  3. anyConnect连接VPN后无法上网

    最近想使用学校图书馆的VPN, 使用的是anyConnect的客户端.每次连接后都显示连接成功,但是马上就无法上网了. 开始以为是win10系统不兼容的问题,在虚拟机里面用win7测试可以成功,但是因 ...

  4. Merge Into example

    merge into users a using temp_users b on (a.userid = b.user_id) when matched then update set a.passw ...

  5. GDI+中发生一般性错误之文件被占用

    有多种原因可能导致这个异常出现,比如创建文件的权限不足.文件被占用等. 这里提供一个使用Stream读取图片避免文件被占用的方法. public Image GetImageFromStream(st ...

  6. spring mvc 全局异常处理

    package com.tool; public class MyException extends Exception{ public String Msg; public String ErrCo ...

  7. java集合 collection-list-LinkedList 模拟一个堆栈或者队列数据结构。

    /* 使用LinkedList模拟一个堆栈或者队列数据结构. 堆栈:先进后出 如同一个杯子. 队列:先进先出 First in First out FIFO 如同一个水管. */ import jav ...

  8. LNK1169 和 LNK2005

    错误重现: 1> vs2010创建 C++ win32 project, Application type: DLL. 2>为了在工程中使用 CString, 在 stdafx.h 中 I ...

  9. 九度OJ 1510 替换空格

    题目地址:http://ac.jobdu.com/problem.php?pid=1510 题目描述: 请实现一个函数,将一个字符串中的空格替换成"%20".例如,当字符串为We ...

  10. CentOS 7 install LNMP

    CentOS 7 install LNMP 关于 Nginx (发音 “engine x”)这是一款免费.开源.高效的 HTTP 服务器,Nginx是以稳定著称,丰富的功能,结构简单,低资源消耗.本教 ...