案例: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類)
總結
- 上一篇: 用什么软件能测试dbm信号强度,怎么查看
- 下一篇: oracle utl_file fcop