Android中使用广播接收者实现IP拨号
来源:互联网 发布:云计算一般用什么语言 编辑:程序博客网 时间:2024/05/10 03:20
布局文件中定义一下UI,虽然没什么UI.....
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /><EditText android:id="@+id/et_number" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="phone" /><Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="保存ip号码" android:onClick="save" /></LinearLayout >
在mainactivity中实现部分代码
package com.wzw.ipdial;import android.app.Activity;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;import android.os.Bundle;import android.text.TextUtils;import android.view.View;import android.widget.EditText;import android.widget.Toast;public class MainActivity extends Activity {private EditText etNumber;private SharedPreferences sp;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);etNumber=(EditText) findViewById(R.id.et_number);sp=getSharedPreferences("config", MODE_PRIVATE);}public void save(View v){String ipnumber=etNumber.getText().toString().trim();if(TextUtils.isEmpty(ipnumber)){Toast.makeText(this, "清除IP号码成功", 0).show();}else{Toast.makeText(this, "设置IP号码成功", 0).show();}Editor editor=sp.edit();editor.putString("ipnumber", ipnumber);editor.commit();}}
新建一个类继承广播接收者
package com.wzw.ipdial;/** * 定义一个收音机 */import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.SharedPreferences;import android.util.Log;public class Ipdial extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stubString number=getResultData();SharedPreferences sp=context.getSharedPreferences("config", context.MODE_PRIVATE);String ipnumber=sp.getString("ipnumber", "");setResultData(ipnumber+number);}}
清单文件中给权限
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wzw.ipdial" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.wzw.ipdial.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> <!-- 设置广播接受者,并指定接收拨打电话的动作 --> <receiver android:name="com.wzw.ipdial.Ipdial"> <intent-filter > <action android:name="android.intent.action.NEW_OUTGOING_CALL"/> </intent-filter> </receiver> </application></manifest>
0 0
- Android中使用广播接收者实现IP拨号
- android,广播接收者,实现IP拨号
- IP拨号广播接收者
- 广播接收者ip拨号器
- android广播接收者实例_IP拨号器
- Android中广播接收者BroadcastReceiver使用
- Android中广播接收者
- 广播接收者,IP拨号器,简单的描述
- 【黑马Android】(08)activity生命周期/横竖屏切换的生命周期/任务栈的概念/广播接收者ip拨号器/进程的优先级&为什么使用服务
- 利用广播实现ip拨号
- 利用广播实现ip拨号
- 利用广播实现IP拨号
- Android BroadCastReceiver 广播接收者使用
- Android广播接收者使用总结
- Android广播接收者使用总结
- Adroid中广播接收者的使用,实现强制下线功能
- android广播接收者 ip电话拔号器
- Android中使用广播接收者来弹出对话框的坑
- 怎样把ppt转成pdf
- hdu2021 发工资咯:)
- 易语言表白示爱程序
- 高通平台常用缩写(持续更新中)
- PDF转Excel转换器
- Android中使用广播接收者实现IP拨号
- Liunx环境下如何修改用户名
- pdf转word转换器在线
- poj1562
- hd 2503 a/b + c/d
- 可并堆与二叉堆
- ppt如何转换为pdf
- hdu 4616 Game
- <转载>Android通过onDraw实现在View中绘图操作