• 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>
  • 相关阅读:
    fir.im Weekly
    【转】UITextView的使用详解
    UITextView textViewShouldEndEditing
    【转】 iOS 两种方法实现左右滑动出现侧边菜单栏 slide view
    【转】 UITableView 的indexPath
    【转】 iOS Provisioning Profile(Certificate)与Code Signing详解
    【原】AVAudio录制,播放 (解决真机播放音量太小)
    iOS开发知识点:理解assign,copy,retain变strong
    【转】 NSArray copy 问题
    UITableView中的visibleCells的用法(visibleCells帮上大忙了)
  • 原文地址:https://www.cnblogs.com/wuyou/p/3502500.html
Copyright © 2020-2023  润新知