Implement ipdialing using Broadcast receiver in Android

Source: Internet
Author: User

Implement ipdialing using Broadcast receiver in Android
The layout file defines the UI, although there is no UI .....

     
  
  
  
 

Implement Part of the Code in 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 number cleared successfully", 0 ). show ();} else {Toast. makeText (this, "IP number set successfully", 0 ). show ();} Editor editor = sp. edit (); editor. putString ("ipnumber", ipnumber); editor. commit ();}}

Create a new class to inherit the broadcast Receiver
Package com. wzw. ipdial;/*** define a radio */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 );}}


Permission in the configuration file
 
     
      
                          
                                  
               
                  
          
              
                                   
           
      
 


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.