日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

案例:IP拨号器

發布時間:2023/12/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 案例:IP拨号器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IP撥號器對應的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:app="http://schemas.android.com/apk/res-auto"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? tools:context="com.example.a01.guangbo.MainActivity">


? ? <EditText
? ? ? ? android:id="@+id/et_ipnumber"
? ? ? ? android:layout_width="fill_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:hint="input"
? ? ? ? />
? ? <Button
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:onClick="setIP"
? ? ? ? android:layout_below="@+id/et_ipnumber"
? ? ? ? android:layout_centerHorizontal="true"
? ? ? ? android:text="設置IP號碼"/>


</RelativeLayout>


MainActivity里面的東西:

package com.example.a01.guangbo;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {
? ? EditText et_ipnumber;
? ? SharedPreferences sp;
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? //獲取EditText地址
? ? ? ? et_ipnumber=(EditText)findViewById(R.id.et_ipnumber);
? ? ? ? //創建存儲器
? ? ? ? sp=getSharedPreferences("data",MODE_PRIVATE);
? ? ? ? //設置IP號碼
? ? ? ? et_ipnumber.setText(sp.getString("ipnumber",""));
? ? }
? ? public void setIP(View view){
? ? ? ? //獲取用戶輸入的IP號碼
? ? ? ? String ipnumber=et_ipnumber.getText().toString().trim();
? ? ? ? //保存提交
? ? ? ? SharedPreferences.Editor ed=sp.edit();
? ? ? ? ed.putString("ipnumber",ipnumber);
? ? ? ? ed.commit();
? ? ? ? Toast.makeText(this,"設置成功",Toast.LENGTH_SHORT).show();


? ? }
? ? public class OutCallRecevicer extends BroadcastReceiver{


? ? ? ? @Override
? ? ? ? public void onReceive(Context context, Intent intent) {
? ? ? ? ? ? //獲取用戶撥號
? ? ? ? ? ? String outcallnumber=getResultData();
? ? ? ? ? ? //獲取存儲器
? ? ? ? ? ? SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE);
? ? ? ? ? ? //獲取ip
? ? ? ? ? ? String ipnumber=sp.getString("ipnumber","");
? ? ? ? ? ? setResultData(ipnumber+outcallnumber);
? ? ? ? }
? ? }




}


監聽廣播時間:廣播接收者(OutCallReceiver類)







總結

以上是生活随笔為你收集整理的案例:IP拨号器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。