The principle of IP dialer developed by Android

Source: Internet
Author: User

The IP dialer, which uses the Android broadcast receiver (Broadcastreceiver), puts the saved IP number in front of the dialed phone number (Getresultdata ()) in the broadcast, and then sets the modified number to the broadcast ( Setresultdata ()).

Project creation steps and ideas:

1. Create a Java class that inherits the Android Broadcastreceiver

2. In the manifest file, define the receiver node, define the Name property, and specify the full class name of the broadcast receiver Java class

3. In the Intent-filter node, specify the action child node, and the action value must match the action in the broadcast to be accepted

4. Rewrite the OnReceive () method of the custom broadcast receiver, and when making a call, place the IP number in front of the phone number

Where you use Sharedpreferences to save the IP number

How to get to the broadcast data usage: Getresultdata ()

Put the modified data into the broadcast method: Setresultdata (Ipnumber+number);

Mainactivity Code:

1 Importandroid.app.Activity;2 Importandroid.content.SharedPreferences;3 ImportAndroid.os.Bundle;4 ImportAndroid.view.View;5 ImportAndroid.widget.EditText;6 7  Public classMainactivityextendsActivity {8 9 @OverrideTen     protected voidonCreate (Bundle savedinstancestate) { One         Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.activity_main); -     } -      the      Public voidClick (View v) { -EditText et=(EditText) Findviewbyid (r.id.et); -          -Sharedpreferences sharedpreferences = getsharedpreferences ("IP", mode_private); +Sharedpreferences.edit (). putstring ("Ipnumber", Et.gettext (). toString ()). commit (); -     } +  A}

Callreceiver Code:

1 ImportAndroid.content.BroadcastReceiver;2 ImportAndroid.content.Context;3 Importandroid.content.Intent;4 Importandroid.content.SharedPreferences;5 6  Public classCallreceiverextendsBroadcastreceiver {7 8 @Override9      Public voidOnReceive (Context context, Intent Intent) {TenString number =Getresultdata (); OneSharedpreferences sharedpreferences =Context.getsharedpreferences ( A"IP", context.mode_private); -String Ipnumber = sharedpreferences.getstring ("Ipnumber", "" "); -System.out.println (ipnumber+ "+" +Number ); theSetresultdata (ipnumber+Number ); -  -     } -  +}

Manifest file Code:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Manifestxmlns:android= "Http://schemas.android.com/apk/res/android"3  Package= "Com.lijingbo.ipdialer"4 Android:versioncode= "1"5 Android:versionname= "1.0" >6 7     <USES-SDK8         android:minsdkversion= "+"9 android:targetsdkversion= "+" />Ten  One     <uses-permissionAndroid:name= "Android.permission.PROCESS_OUTGOING_CALLS" /> A  -     <Application -         Android:allowbackup= "true" the Android:icon= "@drawable/ic_launcher" - Android:label= "@string/app_name" - Android:theme= "@style/apptheme" > -         <Activity +             Android:name=". Mainactivity " - Android:label= "@string/app_name" > +             <Intent-filter> A                 <ActionAndroid:name= "Android.intent.action.MAIN" /> at  -                 <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> -             </Intent-filter> -         </Activity> -  -         <receiverAndroid:name=". Callreceiver " > in             <Intent-filter> -                 <ActionAndroid:name= "Android.intent.action.NEW_OUTGOING_CALL" /> to             </Intent-filter> +         </receiver> -     </Application> the  * </Manifest>

The principle of IP dialer developed by Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.