码迷,mamicode.com
首页 > 其他好文 > 详细

ip电话拨号器

时间:2014-10-19 12:45:19      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   io   os   ar   java   sp   

ip电话拨号器的好处在于  当需要在每次拨打电话是添加一个前缀,如17951,来降低长途话费的资费,可以实现自动添加,而不用每次都手动添加,其中主要涉及到一下几个方面

1 先定义一个sharedpreferences,用来保存需要拨打电话时需要添加的前缀

package com.djf.ipnumber;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
private EditText et_number;
private SharedPreferences sp;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  et_number = (EditText) findViewById(R.id.et_number);
  sp = getSharedPreferences("ipnumber", MODE_PRIVATE);
 }
 
 public void save(View view) {
  String ipnumber = et_number.getText().toString().trim();
  Editor editor =  sp.edit();
  editor.putString("ipnumber", ipnumber);
  editor.commit();
  Toast.makeText(this, "保存成功", 0).show();
  
 }
}

 

2 再定义一个广播接收者 broadcastreceiver ,用来监听当有电话拨出的事件,然后在拨出之前,将要拨打的电话加上一个前缀

package com.djf.ipnumber;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

public class OutCallReceiver extends BroadcastReceiver {
private SharedPreferences sp;
	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		String number = getResultData();
		sp = context.getSharedPreferences("ipnumber",context.MODE_PRIVATE);
		String ipnumber = sp.getString("ipnumber", "");
		setResultData(ipnumber+number);
	}

}

 

3 注意需要添加的权限

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.djf.ipnumber"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="9"
        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.djf.ipnumber.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.djf.ipnumber.OutCallReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" >
                </action>
            </intent-filter>
        </receiver>
    </application>

</manifest>

ip电话拨号器

标签:android   style   blog   http   io   os   ar   java   sp   

原文地址:http://www.cnblogs.com/jiefeiduan/p/4034501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!