├── .DS_Store
├── .classpath
├── .project
├── .settings
└── org.eclipse.core.resources.prefs
├── AndroidManifest.xml
├── README.md
├── bin
├── AndroidManifest.xml
├── WiFiDirectTestApp.apk
├── classes.dex
├── classes
│ ├── .DS_Store
│ └── com
│ │ ├── .DS_Store
│ │ └── example
│ │ ├── .DS_Store
│ │ └── p2p
│ │ ├── .DS_Store
│ │ └── apitest
│ │ ├── .DS_Store
│ │ ├── BuildConfig.class
│ │ ├── R$array.class
│ │ ├── R$attr.class
│ │ ├── R$drawable.class
│ │ ├── R$id.class
│ │ ├── R$layout.class
│ │ ├── R$string.class
│ │ ├── R.class
│ │ ├── WiFiDirectTestAppActivity$1.class
│ │ ├── WiFiDirectTestAppActivity$2$1.class
│ │ ├── WiFiDirectTestAppActivity$2.class
│ │ ├── WiFiDirectTestAppActivity$3.class
│ │ ├── WiFiDirectTestAppActivity$4.class
│ │ ├── WiFiDirectTestAppActivity$5.class
│ │ ├── WiFiDirectTestAppActivity$6.class
│ │ ├── WiFiDirectTestAppActivity$7.class
│ │ ├── WiFiDirectTestAppActivity$8.class
│ │ ├── WiFiDirectTestAppActivity$ActionListenerAdapter.class
│ │ ├── WiFiDirectTestAppActivity$ReceiverState.class
│ │ ├── WiFiDirectTestAppActivity$WDBR_P2P_CONNECTION_CHANGED_ACTION.class
│ │ ├── WiFiDirectTestAppActivity$WDBR_P2P_PEERS_CHANGED_ACTION.class
│ │ ├── WiFiDirectTestAppActivity$WDBR_P2P_STATE_CHANGED_ACTION.class
│ │ ├── WiFiDirectTestAppActivity$WDBR_P2P_THIS_DEVICE_CHANGED_ACTION.class
│ │ ├── WiFiDirectTestAppActivity$WiFiDirectBroadcastReceiver.class
│ │ └── WiFiDirectTestAppActivity.class
├── dexedLibs
│ └── annotations-2232578836842558934a49ac0785a0e9.jar
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ └── drawable-xhdpi
│ │ └── ic_launcher.png
└── resources.ap_
├── gen
└── com
│ └── example
│ └── p2p
│ └── apitest
│ ├── BuildConfig.java
│ └── R.java
├── proguard-project.txt
├── project.properties
├── res
├── .DS_Store
├── drawable-hdpi
│ ├── .DS_Store
│ └── ic_launcher.png
├── drawable-ldpi
│ ├── .DS_Store
│ └── ic_launcher.png
├── drawable-mdpi
│ ├── .DS_Store
│ └── ic_launcher.png
├── drawable-xhdpi
│ ├── .DS_Store
│ └── ic_launcher.png
├── layout
│ ├── .DS_Store
│ └── main.xml
└── values
│ ├── .DS_Store
│ └── strings.xml
└── src
├── .DS_Store
└── com
├── .DS_Store
└── example
├── .DS_Store
└── p2p
├── .DS_Store
└── apitest
├── .DS_Store
└── WiFiDirectTestAppActivity.java
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/.DS_Store
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | WiFiDirectTestApp
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
16 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | WiFiDirectTestApp
2 | =================
3 |
4 | Android Wi-Fi DirectのAPIを個別に実行し、Wi-Fi Directの動きを見るアプリ。
5 |
6 | #### 対応しているインテントフィルタ
7 |
8 | * WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION
9 | * WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION
10 | * WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION
11 | * WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
12 |
13 | #### 対応しているメソッド
14 |
15 | ##### Android
16 | * getSystemService
17 |
18 | ##### WifiP2pManager
19 |
20 | * 初期化 initialize
21 | * 発見 discoverPeers
22 | * 発見結果取得 requestPeers
23 | * 接続 connect
24 | * 接続キャンセル cancelConnect
25 | * グループ生成 createGroup
26 | * グループ削除・切断 removeGroup
27 | * 接続情報取得 requestConnectionInfo
28 | * グループ情報取得 requestGroupInfo
29 |
30 |
31 | #### やりたい
32 |
33 | * 前回実行時の設定状態をPrefへ保存し、次回実行時にリストア
34 | * ログ関連
35 | - ログ出力をクラス化
36 | - ログをSDカードへ保存
37 | - ログ文字サイズ変更
38 | * WFD正規表現修正
39 | * ブロードキャストレシーバのコードリファイン
40 | * startActivity()をstartPreferencePanel()へ変更(Wi-Fi Directの画面を表示)
41 | * Wi-Fi Direct
42 | - WPS PIN UI追加
43 | - サービス検出 API追加
44 | - DNS API追加
45 |
46 | ----
47 |
48 | #### ライセンス
49 | NYSL
50 |
--------------------------------------------------------------------------------
/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
16 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/bin/WiFiDirectTestApp.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/WiFiDirectTestApp.apk
--------------------------------------------------------------------------------
/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes.dex
--------------------------------------------------------------------------------
/bin/classes/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/.DS_Store
--------------------------------------------------------------------------------
/bin/classes/com/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/.DS_Store
--------------------------------------------------------------------------------
/bin/classes/com/example/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/.DS_Store
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/.DS_Store
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/.DS_Store
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/BuildConfig.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/R$array.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/R$array.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/R$attr.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/R$drawable.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/R$id.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/R$layout.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/R$string.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/R.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$1.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$2$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$2$1.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$2.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$3.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$4.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$5.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$5.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$6.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$6.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$7.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$7.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$8.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$8.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$ActionListenerAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$ActionListenerAdapter.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$ReceiverState.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$ReceiverState.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$WDBR_P2P_CONNECTION_CHANGED_ACTION.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$WDBR_P2P_CONNECTION_CHANGED_ACTION.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$WDBR_P2P_PEERS_CHANGED_ACTION.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$WDBR_P2P_PEERS_CHANGED_ACTION.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$WDBR_P2P_STATE_CHANGED_ACTION.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$WDBR_P2P_STATE_CHANGED_ACTION.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$WDBR_P2P_THIS_DEVICE_CHANGED_ACTION.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$WDBR_P2P_THIS_DEVICE_CHANGED_ACTION.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$WiFiDirectBroadcastReceiver.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity$WiFiDirectBroadcastReceiver.class
--------------------------------------------------------------------------------
/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/classes/com/example/p2p/apitest/WiFiDirectTestAppActivity.class
--------------------------------------------------------------------------------
/bin/dexedLibs/annotations-2232578836842558934a49ac0785a0e9.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/dexedLibs/annotations-2232578836842558934a49ac0785a0e9.jar
--------------------------------------------------------------------------------
/bin/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/bin/resources.ap_
--------------------------------------------------------------------------------
/gen/com/example/p2p/apitest/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.example.p2p.apitest;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/gen/com/example/p2p/apitest/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.example.p2p.apitest;
9 |
10 | public final class R {
11 | public static final class array {
12 | /** array.xml ^^;;
13 | */
14 | public static final int spinner_go_entry=0x7f050000;
15 | public static final int spinner_wps_entry=0x7f050001;
16 | }
17 | public static final class attr {
18 | }
19 | public static final class drawable {
20 | public static final int ic_launcher=0x7f020000;
21 | }
22 | public static final class id {
23 | public static final int layout_apibuttons=0x7f060000;
24 | public static final int radiobutton_html=0x7f06000a;
25 | public static final int radiobutton_mono=0x7f06000b;
26 | public static final int radiogroup_logkind=0x7f060009;
27 | public static final int scrollview_log=0x7f06000d;
28 | public static final int spinner_go=0x7f060007;
29 | public static final int spinner_peers=0x7f060006;
30 | public static final int spinner_wps=0x7f060008;
31 | public static final int textView_log=0x7f06000e;
32 | public static final int toggle_autoscroll=0x7f06000c;
33 | public static final int toggle_bc_all=0x7f060001;
34 | public static final int toggle_bc_connection=0x7f060003;
35 | public static final int toggle_bc_peers=0x7f060004;
36 | public static final int toggle_bc_state=0x7f060002;
37 | public static final int toggle_bc_this=0x7f060005;
38 | }
39 | public static final class layout {
40 | public static final int main=0x7f030000;
41 | }
42 | public static final class string {
43 | public static final int app_about=0x7f040001;
44 | public static final int app_name=0x7f040000;
45 | public static final int button_autoscroll_off=0x7f04001f;
46 | public static final int button_autoscroll_on=0x7f04001e;
47 | public static final int button_broadcast_connection_regist=0x7f040006;
48 | public static final int button_broadcast_connection_unregist=0x7f040007;
49 | public static final int button_broadcast_peers_regist=0x7f040008;
50 | public static final int button_broadcast_peers_unregist=0x7f040009;
51 | public static final int button_broadcast_regist=0x7f040002;
52 | public static final int button_broadcast_state_regist=0x7f040004;
53 | public static final int button_broadcast_state_unregist=0x7f040005;
54 | public static final int button_broadcast_this_regist=0x7f04000a;
55 | public static final int button_broadcast_this_unregist=0x7f04000b;
56 | public static final int button_broadcast_unregist=0x7f040003;
57 | public static final int button_cancelConnect=0x7f040014;
58 | public static final int button_colorlog=0x7f04001c;
59 | public static final int button_connect=0x7f040011;
60 | public static final int button_createGroup=0x7f040015;
61 | public static final int button_discoverPeers=0x7f04000e;
62 | public static final int button_getSystemService=0x7f04000c;
63 | public static final int button_gotosetting=0x7f040019;
64 | public static final int button_initialize=0x7f04000d;
65 | public static final int button_monolog=0x7f04001d;
66 | public static final int button_removeGroup=0x7f040016;
67 | public static final int button_requestConnectionInfo=0x7f040017;
68 | public static final int button_requestGroupInfo=0x7f040018;
69 | public static final int button_requestPeers=0x7f04000f;
70 | public static final int button_resetlog=0x7f04001a;
71 | public static final int button_savelog=0x7f04001b;
72 | public static final int spinner_go=0x7f040012;
73 | public static final int spinner_peers=0x7f040010;
74 | public static final int spinner_wps=0x7f040013;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-14
15 |
--------------------------------------------------------------------------------
/res/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/.DS_Store
--------------------------------------------------------------------------------
/res/drawable-hdpi/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/drawable-hdpi/.DS_Store
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/drawable-ldpi/.DS_Store
--------------------------------------------------------------------------------
/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/drawable-mdpi/.DS_Store
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/drawable-xhdpi/.DS_Store
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/layout/.DS_Store
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
18 |
19 |
24 |
25 |
33 |
34 |
42 |
43 |
51 |
52 |
60 |
61 |
69 |
70 |
76 |
77 |
82 |
83 |
89 |
90 |
94 |
95 |
100 |
101 |
109 |
110 |
111 |
116 |
117 |
122 |
123 |
133 |
134 |
144 |
145 |
146 |
151 |
152 |
158 |
159 |
164 |
165 |
171 |
172 |
177 |
178 |
184 |
185 |
190 |
191 |
197 |
198 |
203 |
204 |
210 |
211 |
212 |
218 |
219 |
225 |
226 |
231 |
232 |
233 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
251 |
252 |
258 |
259 |
264 |
265 |
266 |
267 |
--------------------------------------------------------------------------------
/res/values/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/res/values/.DS_Store
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WiFiDirectTestApp
5 | About this App...
6 |
7 | BroadcastReceiver Registered
8 | BroadcastReceiver UnRegistered
9 | STATE_CHANGED Registered
10 | STATE_CHANGED UnRegistered
11 | CONNECTION_CHANGED Registered
12 | CONNECTION_CHANGED UnRegistered
13 | PEERS_CHANGED Registered
14 | PEERS_CHANGED UnRegistered
15 | THIS_DEVICE_CHANGED Registered
16 | THIS_DEVICE_CHANGED UnRegistered
17 |
18 | getSystemService
19 | initialize
20 | discoverPeers
21 | requestPeers
22 | Peers
23 | connect
24 | Group Owner Intent
25 | Wi-Fi Protected Setup
26 | cancelConnect
27 | createGroup
28 | removeGroup
29 | requestConnectionInfo
30 | requestGroupInfo
31 |
32 | Go To Wi-Fi Setting Menu
33 | Reset Log
34 | Save Log
35 | Color Log
36 | Mono Log
37 | AutoScroll On
38 | AutoScroll Off
39 |
40 |
41 |
42 | - -1:system can choose an appropriate value
43 | - 0:least inclination to be a group owner
44 | - 1
45 | - 2
46 | - 3
47 | - 4
48 | - 5
49 | - 6
50 | - 7
51 | - 8
52 | - 9
53 | - 10
54 | - 11
55 | - 12
56 | - 13
57 | - 14
58 | - 15:highest inclination to be a group owner
59 |
60 |
61 |
62 | - PBC : Push button configuration
63 | - DISPLAY : Display pin method configuration
64 | - KEYPAD : Keypad pin method configuration
65 | - LABEL : Label pin method configuration
66 | - INVALID : Invalid configuration
67 |
68 |
69 |
--------------------------------------------------------------------------------
/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/src/.DS_Store
--------------------------------------------------------------------------------
/src/com/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/src/com/.DS_Store
--------------------------------------------------------------------------------
/src/com/example/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/src/com/example/.DS_Store
--------------------------------------------------------------------------------
/src/com/example/p2p/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/src/com/example/p2p/.DS_Store
--------------------------------------------------------------------------------
/src/com/example/p2p/apitest/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kensuke/WiFiDirectTestApp/641f17b98e3134d1520aa6c68d6c5ca95821f34e/src/com/example/p2p/apitest/.DS_Store
--------------------------------------------------------------------------------
/src/com/example/p2p/apitest/WiFiDirectTestAppActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.p2p.apitest;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.app.Activity;
7 | import android.content.ActivityNotFoundException;
8 | import android.content.BroadcastReceiver;
9 | import android.content.Context;
10 | import android.content.Intent;
11 | import android.content.IntentFilter;
12 | import android.content.pm.PackageInfo;
13 | import android.content.pm.PackageManager;
14 | import android.content.pm.PackageManager.NameNotFoundException;
15 | import android.graphics.Color;
16 | import android.net.NetworkInfo;
17 | import android.net.wifi.WifiInfo;
18 | import android.net.wifi.WifiManager;
19 | import android.net.wifi.WpsInfo;
20 | import android.net.wifi.p2p.WifiP2pConfig;
21 | import android.net.wifi.p2p.WifiP2pDevice;
22 | import android.net.wifi.p2p.WifiP2pDeviceList;
23 | import android.net.wifi.p2p.WifiP2pGroup;
24 | import android.net.wifi.p2p.WifiP2pInfo;
25 | import android.net.wifi.p2p.WifiP2pManager;
26 | import android.net.wifi.p2p.WifiP2pManager.Channel;
27 | import android.net.wifi.p2p.WifiP2pManager.ChannelListener;
28 | import android.net.wifi.p2p.WifiP2pManager.ConnectionInfoListener;
29 | import android.net.wifi.p2p.WifiP2pManager.GroupInfoListener;
30 | import android.net.wifi.p2p.WifiP2pManager.PeerListListener;
31 | import android.os.Build;
32 | import android.os.Bundle;
33 | import android.provider.Settings;
34 | import android.text.Editable;
35 | import android.text.Html;
36 | import android.text.TextWatcher;
37 | import android.util.Log;
38 | import android.view.Menu;
39 | import android.view.MenuItem;
40 | import android.view.View;
41 | import android.widget.AdapterView;
42 | import android.widget.AdapterView.OnItemSelectedListener;
43 | import android.widget.ArrayAdapter;
44 | import android.widget.RadioGroup;
45 | import android.widget.RadioGroup.OnCheckedChangeListener;
46 | import android.widget.CompoundButton;
47 | import android.widget.ScrollView;
48 | import android.widget.Spinner;
49 | import android.widget.TextView;
50 | import android.widget.Toast;
51 | import android.widget.ToggleButton;
52 |
53 | /**
54 | * P2P API テストアプリ
55 | */
56 | public class WiFiDirectTestAppActivity extends Activity {
57 |
58 | /** ログ出力用TAG */
59 | private final String TAG = "WiFiDirectTestAppActivity";
60 |
61 | /** ログ */
62 | private TextView mTextView_Log;
63 | /** 改行 */
64 | private final String LINE_SEPARATOR = System.getProperty("line.separator");
65 | private final String LINE_SEPARATOR_HTML = "
";
66 | /** ログをHTML(色付き文字列)で出力
67 | * TODO 前回実行時の値をPrefへ保存/読込
68 | */
69 | private boolean HTML_OUT = true;
70 |
71 | /** BroadcastReceiver */
72 | private enum ReceiverState {
73 | All,
74 | StateChange,
75 | PeersChange,
76 | ConnectionChange,
77 | ThisDeviceChange,
78 | }
79 |
80 | /** BroadcastReceiver 全部 */
81 | private BroadcastReceiver mReceiver;
82 | /** BroadcastReceiver P2P_STATE_CHANGED_ACTION */
83 | private WDBR_P2P_STATE_CHANGED_ACTION mWDBR_P2P_STATE_CHANGED_ACTION;
84 | /** BroadcastReceiver P2P_PEERS_CHANGED_ACTION */
85 | private WDBR_P2P_PEERS_CHANGED_ACTION mWDBR_P2P_PEERS_CHANGED_ACTION;
86 | /** BroadcastReceiver P2P_CONNECTION_CHANGED_ACTION */
87 | private WDBR_P2P_CONNECTION_CHANGED_ACTION mWDBR_P2P_CONNECTION_CHANGED_ACTION;
88 | /** BroadcastReceiver THIS_DEVICE_CHANGED_ACTION */
89 | private WDBR_P2P_THIS_DEVICE_CHANGED_ACTION mWDBR_THIS_DEVICE_CHANGED_ACTION;
90 |
91 | /** Wi-Fi Direct 有効/無効状態 */
92 | private boolean mIsWiFiDirectEnabled;
93 |
94 | /** WifiP2pManager */
95 | private WifiP2pManager mWifiP2pManager;
96 | /** Channel */
97 | private Channel mChannel;
98 | /** peers */
99 | private List mPeers = new ArrayList();
100 | /** リスナアダプタ */
101 | private ActionListenerAdapter mActionListenerAdapter;
102 |
103 | /** 子リスト保持 */
104 | private Spinner mPeersSpinner;
105 | /** 選択中の子 */
106 | private String mSelectedDevice;
107 |
108 | /* ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
109 | * Activity API
110 | */
111 |
112 | @Override
113 | public void onCreate(Bundle savedInstanceState) {
114 | super.onCreate(savedInstanceState);
115 |
116 | setContentView(R.layout.main);
117 |
118 | String title = "ANDROID_ID[" + getAndroid_ID() + "]";
119 | title += " MAC[" + getMACAddress() + "]";
120 | setTitle(title);
121 |
122 | initializeLog();
123 | initBroadcastToggle();
124 |
125 | addLog("onCreate()");
126 |
127 | // アプリ内で捕捉していない例外をキャッチし、ログ出力
128 | //Thread.setDefaultUncaughtExceptionHandler( new UncaughtExceptionHandler() {
129 | // public void uncaughtException(Thread thread, Throwable ex) {
130 | // addLog("uncaughtException()");
131 | // addLog(ex.toString());
132 | // }
133 | //});
134 |
135 | if (!hasP2P()) {
136 | toastAndLog("onCreate()", "This Device Has Not P2P Feature!!");
137 | }
138 | }
139 |
140 | @Override
141 | protected void onResume() {
142 | super.onResume();
143 | addLog("onResume()");
144 |
145 | // ブロードキャストレシーバで、WIFI_P2P_STATE_CHANGED_ACTIONのコールバックを持ってWi-Fi Direct ON/OFFを判定する
146 | mIsWiFiDirectEnabled = false;
147 |
148 | // たぶんこのタイミングでブロードキャストレシーバを登録するのがbetter
149 | registerBroadcastReceiver(ReceiverState.All);
150 | }
151 |
152 | @Override
153 | protected void onPause() {
154 | super.onPause();
155 | addLog("onPause()");
156 |
157 | // ブロードキャストレシーバ解除
158 | unRegisterBroadcastReceiver(ReceiverState.All);
159 | }
160 |
161 | /**
162 | * ブロードキャストレシーバ登録
163 | */
164 | private void registerBroadcastReceiver(ReceiverState rs) {
165 | IntentFilter filter = new IntentFilter();
166 |
167 | switch (rs) {
168 | case All:
169 | filter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
170 | filter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
171 | filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
172 | filter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
173 | mReceiver = new WiFiDirectBroadcastReceiver();
174 | registerReceiver(mReceiver, filter);
175 | addLog("registerBroadcastReceiver() BroadcastReceiver");
176 | break;
177 |
178 | case StateChange:
179 | filter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
180 | mWDBR_P2P_STATE_CHANGED_ACTION = new WDBR_P2P_STATE_CHANGED_ACTION();
181 | registerReceiver(mWDBR_P2P_STATE_CHANGED_ACTION, filter);
182 | addLog("registerBroadcastReceiver() P2P_STATE_CHANGED_ACTION");
183 | break;
184 |
185 | case PeersChange:
186 | filter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
187 | mWDBR_P2P_PEERS_CHANGED_ACTION = new WDBR_P2P_PEERS_CHANGED_ACTION();
188 | registerReceiver(mWDBR_P2P_PEERS_CHANGED_ACTION, filter);
189 | addLog("registerBroadcastReceiver() P2P_PEERS_CHANGED_ACTION");
190 | break;
191 |
192 | case ConnectionChange:
193 | filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
194 | mWDBR_P2P_CONNECTION_CHANGED_ACTION = new WDBR_P2P_CONNECTION_CHANGED_ACTION();
195 | registerReceiver(mWDBR_P2P_CONNECTION_CHANGED_ACTION, filter);
196 | addLog("registerBroadcastReceiver() P2P_CONNECTION_CHANGED_ACTION");
197 | break;
198 |
199 | case ThisDeviceChange:
200 | filter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
201 | mWDBR_THIS_DEVICE_CHANGED_ACTION = new WDBR_P2P_THIS_DEVICE_CHANGED_ACTION();
202 | registerReceiver(mWDBR_THIS_DEVICE_CHANGED_ACTION, filter);
203 | addLog("registerBroadcastReceiver() THIS_DEVICE_CHANGED_ACTION");
204 | break;
205 |
206 | default:
207 | toastAndLog("registerBroadcastReceiver()", "Unknown ReceiverState["+rs+"]");
208 | break;
209 | }
210 | }
211 |
212 | /**
213 | * ブロードキャストレシーバ解除
214 | */
215 | private void unRegisterBroadcastReceiver(ReceiverState rs) {
216 | switch (rs) {
217 | case All:
218 | if (mReceiver != null) {
219 | unregisterReceiver(mReceiver);
220 | mReceiver = null;
221 | addLog("unRegisterBroadcastReceiver() BroadcastReceiver");
222 | }
223 | break;
224 |
225 | case StateChange:
226 | if (mWDBR_P2P_STATE_CHANGED_ACTION != null) {
227 | unregisterReceiver(mWDBR_P2P_STATE_CHANGED_ACTION);
228 | mWDBR_P2P_STATE_CHANGED_ACTION = null;
229 | addLog("unRegisterBroadcastReceiver() P2P_STATE_CHANGED_ACTION");
230 | }
231 | break;
232 |
233 | case PeersChange:
234 | if (mWDBR_P2P_PEERS_CHANGED_ACTION != null) {
235 | unregisterReceiver(mWDBR_P2P_PEERS_CHANGED_ACTION);
236 | mWDBR_P2P_PEERS_CHANGED_ACTION = null;
237 | addLog("unRegisterBroadcastReceiver() P2P_PEERS_CHANGED_ACTION");
238 | }
239 | break;
240 |
241 | case ConnectionChange:
242 | if (mWDBR_P2P_CONNECTION_CHANGED_ACTION != null) {
243 | unregisterReceiver(mWDBR_P2P_CONNECTION_CHANGED_ACTION);
244 | mWDBR_P2P_CONNECTION_CHANGED_ACTION = null;
245 | addLog("unRegisterBroadcastReceiver() P2P_CONNECTION_CHANGED_ACTION");
246 | }
247 | break;
248 |
249 | case ThisDeviceChange:
250 | if (mWDBR_THIS_DEVICE_CHANGED_ACTION != null) {
251 | unregisterReceiver(mWDBR_THIS_DEVICE_CHANGED_ACTION);
252 | mWDBR_THIS_DEVICE_CHANGED_ACTION = null;
253 | addLog("unRegisterBroadcastReceiver() THIS_DEVICE_CHANGED_ACTION");
254 | }
255 | break;
256 |
257 | default:
258 | toastAndLog("unRegisterBroadcastReceiver()", "Unknown ReceiverState["+rs+"]");
259 | break;
260 | }
261 | }
262 |
263 | /**
264 | * ブロードキャストレシーバ トグルボタン初期化 入り口
265 | */
266 | private void initBroadcastToggle() {
267 | initBroadcastToggleInner(R.id.toggle_bc_all);
268 | initBroadcastToggleInner(R.id.toggle_bc_state);
269 | initBroadcastToggleInner(R.id.toggle_bc_peers);
270 | initBroadcastToggleInner(R.id.toggle_bc_connection);
271 | initBroadcastToggleInner(R.id.toggle_bc_this);
272 | }
273 |
274 | /**
275 | * ブロードキャストレシーバ トグルボタン初期化
276 | */
277 | private void initBroadcastToggleInner(final int rId_Toggle) {
278 | // トグルボタンのON/OFF変更を検知
279 | ToggleButton tb = (ToggleButton)findViewById(rId_Toggle);
280 | tb.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() {
281 | @Override
282 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
283 | ReceiverState rs = ReceiverState.All;
284 | switch (rId_Toggle) {
285 | case R.id.toggle_bc_all:
286 | rs = ReceiverState.All;
287 | break;
288 | case R.id.toggle_bc_state:
289 | rs = ReceiverState.StateChange;
290 | break;
291 | case R.id.toggle_bc_peers:
292 | rs = ReceiverState.PeersChange;
293 | break;
294 | case R.id.toggle_bc_connection:
295 | rs = ReceiverState.ConnectionChange;
296 | break;
297 | case R.id.toggle_bc_this:
298 | rs = ReceiverState.ThisDeviceChange;
299 | break;
300 | default:
301 | toastAndLog("initBroadcastToggleInner()", "Unknown ReceiverState["+rs+"]");
302 | return;
303 | }
304 |
305 | if (isChecked) {
306 | registerBroadcastReceiver(rs);
307 | } else {
308 | unRegisterBroadcastReceiver(rs);
309 | }
310 | }
311 | });
312 | }
313 |
314 | /**
315 | * オプションメニューが最初に呼び出される時に1度だけ呼び出されます
316 | */
317 | @Override
318 | public boolean onCreateOptionsMenu(Menu menu) {
319 | // メニューアイテムを追加します
320 | menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.app_about));
321 | return super.onCreateOptionsMenu(menu);
322 | }
323 |
324 | /**
325 | * オプションメニューアイテムが選択された時に呼び出されます
326 | */
327 | @Override
328 | public boolean onOptionsItemSelected(MenuItem item) {
329 | boolean ret = true;
330 | int id = item.getItemId();
331 | switch (id) {
332 | default:
333 | toastAndLog("onOptionsItemSelected()", "Unknown Item Id["+id+"]");
334 | break;
335 | case 0:
336 | Toast.makeText(this, getAppVersion(), Toast.LENGTH_SHORT).show();
337 | break;
338 | }
339 | return ret;
340 | }
341 |
342 | /* ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
343 | * ログ出力
344 | * TODO ログ関連をごそっとクラス化したほうがおしゃれだと思う
345 | */
346 |
347 | /**
348 | * ログ関係初期化
349 | */
350 | private void initializeLog() {
351 | if (mTextView_Log != null) {
352 | return;
353 | }
354 |
355 | mTextView_Log = (TextView)findViewById(R.id.textView_log);
356 |
357 | // テキスト変更(=ログ出力追加)を検知
358 | mTextView_Log.addTextChangedListener( new TextWatcher() {
359 | public void onTextChanged(CharSequence s, int start, int before, int count) {
360 | // オートスクロール可否チェック
361 | ToggleButton tb = (ToggleButton)findViewById(R.id.toggle_autoscroll);
362 | if (!tb.isChecked()) {
363 | return;
364 | }
365 |
366 | // テキスト変更時にログウィンドウを末尾へ自動スクロール
367 | final ScrollView sv = (ScrollView)findViewById(R.id.scrollview_log);
368 | sv.post( new Runnable() {
369 | public void run() {
370 | sv.fullScroll(View.FOCUS_DOWN);
371 | }
372 | });
373 | }
374 |
375 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
376 | public void afterTextChanged(Editable s) {}
377 | });
378 |
379 | // ログ種別(色付き(HTML)、モノクロ)変更検知
380 | RadioGroup rg = (RadioGroup)findViewById(R.id.radiogroup_logkind);
381 | rg.setOnCheckedChangeListener( new OnCheckedChangeListener() {
382 | @Override
383 | public void onCheckedChanged(RadioGroup group, int checkedId) {
384 | switch (checkedId) {
385 | case R.id.radiobutton_html: // 色付き
386 | HTML_OUT = true;
387 | break;
388 | case R.id.radiobutton_mono: // モノクロ
389 | HTML_OUT = false;
390 | break;
391 | default:
392 | addLog("initializeLog() Unknown Log Kind["+checkedId+"]");
393 | HTML_OUT = false;
394 | break;
395 | }
396 | }
397 | });
398 | }
399 |
400 | /**
401 | * ログ出力
402 | */
403 | private void addLog(String log) {
404 | Log.d(TAG, log);
405 |
406 | log = log + nl();
407 | if (mTextView_Log == null) {
408 | initializeLog();
409 | }
410 | mTextView_Log.append( HTML_OUT ? convHtmlStr2CS(log) : log );
411 | }
412 |
413 | /**
414 | * HTMl文字列変換
415 | */
416 | private CharSequence convHtmlStr2CS(String htmlStr) {
417 | return Html.fromHtml(htmlStr);
418 | }
419 |
420 | /**
421 | * ログ出力書式に応じた改行コード取得
422 | */
423 | private String nl() {
424 | return HTML_OUT ? LINE_SEPARATOR_HTML : LINE_SEPARATOR;
425 | }
426 |
427 | /**
428 | * ”P2Pメソッドのログ出力”用メソッド
429 | */
430 | private void addMethodLog(String method) {
431 | if (HTML_OUT) method = ""+method+"";
432 | addLog(nl() + method);
433 | }
434 |
435 | /**
436 | * トーストあんどログ
437 | */
438 | private void toastAndLog(String msg1, String msg2) {
439 | String log = msg1 + LINE_SEPARATOR + msg2;
440 | Toast.makeText(this, log, Toast.LENGTH_SHORT).show();
441 |
442 | if (HTML_OUT) log = "" + msg1 + nl() + msg2 + "";
443 | addLog(log);
444 | }
445 |
446 | /**
447 | * ログリセット
448 | */
449 | public void onClickResetLog(View view) {
450 | mTextView_Log.setText("");
451 | }
452 |
453 | /**
454 | * ログ保存
455 | * TODO ログをSDカードへ保存
456 | */
457 | public void onClickSaveLog(View view) {
458 | String log = mTextView_Log.getText().toString();
459 | Log.d(TAG, "onClickSaveLog() LOG["+log+"]");
460 | }
461 |
462 | /**
463 | * デバイス文字列(ログ出力用)
464 | */
465 | private String toStringDevice(WifiP2pDevice device) {
466 | String log = separateCSV(device.toString()) + nl() + " " + getDeviceStatus(device.status);
467 | return HTML_OUT ? ""+log+"" : log;
468 | }
469 |
470 | // ":"区切り文字列へ改行付与
471 | // " Device: Galaxy_Nexus"+
472 | // " primary type: 12345-xyz"
473 | // ↓
474 | // " Device: Galaxy_Nexus
"+
475 | // " primary type: 12345-xyz
"
476 | private String separateCSV(String csvStr) {
477 | //return csvStr;
478 | return csvStr.replaceAll("[^:yWFD] ", nl()+" "); // ": "、"y " でない半角スペース(=文頭の半角スペース)にマッチする
479 | // 以下の”意図しない場所での改行"を除外する
480 | //"deviceAddress: AB:CD"を"deviceAddress:
AB:CD"としない
481 | //"primary type:"を"primary
type:"としない
482 | //"WFD CtrlPort: 554"を”WFD
CtrlPort: 554”としない <= Android 4.2以降のMiracastに対応
483 | }
484 |
485 | // TODO FIXME 上記正規表現ではWFD情報がうまいこと出力されないバグあり
486 | //sbuf.append("Device: ").append(deviceName);
487 | //sbuf.append("\n deviceAddress: ").append(deviceAddress);
488 | //sbuf.append("\n primary type: ").append(primaryDeviceType);
489 | //sbuf.append("\n secondary type: ").append(secondaryDeviceType);
490 | //sbuf.append("\n wps: ").append(wpsConfigMethodsSupported);
491 | //sbuf.append("\n grpcapab: ").append(groupCapability);
492 | //sbuf.append("\n devcapab: ").append(deviceCapability);
493 | //sbuf.append("\n status: ").append(status);
494 | //sbuf.append("\n wfdInfo: ").append(wfdInfo);
495 | // wfdInfo: WFD enabled: trueWFD DeviceInfo: 349
496 | // WFD CtrlPort: 554
497 | // WFD MaxThroughput: 50
498 |
499 | // デバイス状態文字列変換
500 | private String getDeviceStatus(int deviceStatus) {
501 | String status = "";
502 | switch (deviceStatus) {
503 | case WifiP2pDevice.AVAILABLE:
504 | status = "Available";
505 | break;
506 | case WifiP2pDevice.INVITED:
507 | status = "Invited";
508 | break;
509 | case WifiP2pDevice.CONNECTED:
510 | status = "Connected";
511 | break;
512 | case WifiP2pDevice.FAILED:
513 | status = "Failed";
514 | break;
515 | case WifiP2pDevice.UNAVAILABLE:
516 | status = "Unavailable";
517 | break;
518 | default:
519 | status = "Unknown";
520 | break;
521 | }
522 | return HTML_OUT ? "["+status+"]" : "["+status+"]";
523 | }
524 |
525 | /* ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
526 | * P2P API
527 | */
528 |
529 | /**
530 | * リスナアダプタ
531 | * WifiP2pManagerクラスの各メソッドは、WifiP2pManager.ActionListenerによって、メソッドの実行結果を知ることができる
532 | * ただし、successと出たのに失敗したり、failureと出たのに成功したりする
533 | */
534 | class ActionListenerAdapter implements WifiP2pManager.ActionListener {
535 |
536 | // 成功
537 | public void onSuccess() {
538 | String log = " onSuccess()";
539 | if (HTML_OUT) log = " "+log+"";
540 | addLog(log);
541 | }
542 |
543 | // 失敗
544 | public void onFailure(int reason) {
545 | String log = " onFailure("+getReason(reason)+")";
546 | if (HTML_OUT) log = " "+log+"";
547 | addLog(log);
548 | }
549 |
550 | // 失敗理由intコード -> 文字列変換
551 | private String getReason(int reason) {
552 | String[] strs = {"ERROR", "P2P_UNSUPPORTED", "BUSY"};
553 | try {
554 | return strs[reason] + "("+reason+")";
555 | } catch (ArrayIndexOutOfBoundsException e) {
556 | return "UNKNOWN REASON CODE("+reason+")";
557 | }
558 | }
559 | }
560 |
561 | /**
562 | * P2Pメソッド実行前のNULLチェック
563 | */
564 | private boolean isNull(boolean both) {
565 | if (mActionListenerAdapter == null) {
566 | mActionListenerAdapter = new ActionListenerAdapter();
567 | }
568 |
569 | if (!mIsWiFiDirectEnabled) {
570 | toastAndLog(" Wi-Fi Direct is OFF!", "try Setting Menu");
571 | return true;
572 | }
573 |
574 | if (mWifiP2pManager == null) {
575 | toastAndLog(" mWifiP2pManager is NULL!", " try getSystemService");
576 | return true;
577 | }
578 | if (both && (mChannel == null) ) {
579 | toastAndLog(" mChannel is NULL!", " try initialize");
580 | return true;
581 | }
582 |
583 | return false;
584 | }
585 |
586 | /**
587 | * インスタンス取得
588 | */
589 | public void onClickGetSystemService(View view) {
590 | addMethodLog("getSystemService(Context.WIFI_P2P_SERVICE)");
591 |
592 | mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
593 |
594 | addLog(" Result["+(mWifiP2pManager != null)+"]");
595 | }
596 |
597 | /**
598 | * 初期化
599 | */
600 | public void onClickInitialize(View view) {
601 | addMethodLog("mWifiP2pManager.initialize()");
602 | if (isNull(false)) { return; }
603 |
604 | mChannel = mWifiP2pManager.initialize(this, getMainLooper(), new ChannelListener() {
605 | public void onChannelDisconnected() {
606 | addLog("mWifiP2pManager.initialize() -> onChannelDisconnected()");
607 | }
608 | });
609 |
610 | addLog(" Result["+(mChannel != null)+"]");
611 | }
612 |
613 | /**
614 | * デバイス発見
615 | */
616 | public void onClickDiscoverPeers(View view) {
617 | addMethodLog("mWifiP2pManager.discoverPeers()");
618 | if (isNull(true)) { return; }
619 |
620 | mWifiP2pManager.discoverPeers(mChannel, mActionListenerAdapter);
621 | }
622 |
623 | /**
624 | * 接続
625 | */
626 | public void onClickConnect(View view) {
627 | addMethodLog("mWifiP2pManager.connect()");
628 | if (isNull(true)) { return; }
629 |
630 | // ピアが存在しない(、ピア検索をしていない)
631 | int cnt = mPeers.size();
632 | if (cnt == 0) {
633 | addLog(" peer not found! try discoverPeers & requestPeers");
634 | return;
635 | }
636 |
637 | // 選択中のデバイス確定
638 | int idx = 0;
639 | for (WifiP2pDevice device : mPeers) {
640 | if (device.deviceName.equals(mSelectedDevice)) {
641 | break;
642 | }
643 | idx += 1;
644 | }
645 |
646 | // コンフィグオブジェクト生成
647 | WifiP2pConfig config = new WifiP2pConfig();
648 | config.deviceAddress = mPeers.get(idx).deviceAddress;
649 |
650 | // http://developer.android.com/reference/android/net/wifi/p2p/WifiP2pConfig.html#groupOwnerIntent
651 | // -1 = フレームワークがG.O.を決定する(自分 or 接続先)
652 | // 0 = 接続先がG.O.になる(可能性が高い)
653 | // 15 = 自分がG.O.になる(可能性が高い)
654 | config.groupOwnerIntent = getOwnerIntentValue();
655 |
656 | // http://developer.android.com/reference/android/net/wifi/WpsInfo.html
657 | // PBC Push button configuration
658 | // DISPLAY pin method configuration - pin is generated and displayed on device
659 | // KEYPAD pin method configuration - pin is entered on device
660 | // LABEL pin method configuration - pin is labelled on device
661 | // INVALID configuration
662 | config.wps.setup = getWPSSetupValue();
663 |
664 | addLog(" connecting to ["+mSelectedDevice+"]["+config.deviceAddress+"] G.O.["+config.groupOwnerIntent+"] WPS["+config.wps.setup+"]");
665 |
666 | mWifiP2pManager.connect(mChannel, config, mActionListenerAdapter);
667 | }
668 |
669 | /**
670 | * スピナからG.O.インテント値を取得
671 | */
672 | private int getOwnerIntentValue() {
673 | Spinner sp = (Spinner)findViewById(R.id.spinner_go);
674 | int v = sp.getSelectedItemPosition();
675 | return v-1; // G.O.の値域は、 -1 <= G.O <= 15
676 | }
677 |
678 | /**
679 | * スピナからWps値を取得
680 | */
681 | private int getWPSSetupValue() {
682 | Spinner sp = (Spinner)findViewById(R.id.spinner_wps);
683 | int v = sp.getSelectedItemPosition();
684 | switch (v) {
685 | case 0:
686 | return WpsInfo.PBC;
687 | case 1:
688 | return WpsInfo.DISPLAY;
689 | case 2:
690 | return WpsInfo.KEYPAD;
691 | case 3:
692 | return WpsInfo.LABEL;
693 | case 4:
694 | return WpsInfo.INVALID;
695 | default:
696 | toastAndLog("getWPSSetupValue()", "Unknown WPS Index["+v+"]");
697 | return WpsInfo.INVALID;
698 | }
699 | }
700 |
701 | /**
702 | * 接続キャンセル
703 | */
704 | public void onClickCancelConnect(View view) {
705 | addMethodLog("mWifiP2pManager.cancelConnect()");
706 | if (isNull(true)) { return; }
707 |
708 | mWifiP2pManager.cancelConnect(mChannel, mActionListenerAdapter);
709 | }
710 |
711 | /**
712 | * グループ作成
713 | */
714 | public void onClickCreateGroup(View view) {
715 | addMethodLog("mWifiP2pManager.createGroup()");
716 | if (isNull(true)) { return; }
717 |
718 | mWifiP2pManager.createGroup(mChannel, mActionListenerAdapter);
719 | }
720 |
721 | /**
722 | * グループ削除
723 | */
724 | public void onClickRemoveGroup(View view) {
725 | addMethodLog("mWifiP2pManager.removeGroup()");
726 | if (isNull(true)) { return; }
727 |
728 | mWifiP2pManager.removeGroup(mChannel, mActionListenerAdapter);
729 | }
730 |
731 | /**
732 | * 接続情報要求
733 | */
734 | public void onClickRequestConnectionInfo(View view) {
735 | addMethodLog("mWifiP2pManager.requestConnectionInfo()");
736 | if (isNull(true)) { return; }
737 |
738 | mWifiP2pManager.requestConnectionInfo(mChannel, new ConnectionInfoListener() {
739 | // requestConnectionInfo()実行後、非同期応答あり
740 | public void onConnectionInfoAvailable(WifiP2pInfo info) {
741 | addLog(" onConnectionInfoAvailable():");
742 | if (info == null) {
743 | addLog(" info is NULL!");
744 | return;
745 | }
746 | addLog(" groupFormed:" + info.groupFormed);
747 | addLog(" isGroupOwner:" + info.isGroupOwner);
748 | addLog(" groupOwnerAddress:" + info.groupOwnerAddress);
749 | }
750 | });
751 | }
752 |
753 | /**
754 | * グループ情報要求
755 | */
756 | public void onClickRequestGroupInfo(View view) {
757 | addMethodLog("mWifiP2pManager.requestGroupInfo()");
758 | if (isNull(true)) { return; }
759 |
760 | mWifiP2pManager.requestGroupInfo(mChannel, new GroupInfoListener() {
761 | // requestGroupInfo()実行後、非同期応答あり
762 | public void onGroupInfoAvailable(WifiP2pGroup group) {
763 | addLog(" onGroupInfoAvailable():");
764 | if (group == null) {
765 | addLog(" group is NULL!");
766 | return;
767 | }
768 |
769 | String log = separateCSV(group.toString());
770 |
771 | // パスワードは、G.O.のみ取得可能
772 | String pass = nl() + " password: ";
773 | if (group.isGroupOwner()) {
774 | pass += group.getPassphrase();
775 | } else {
776 | pass += "Client Couldn't Get Password";
777 | }
778 | if (HTML_OUT) pass = ""+pass+""; // たぶんfont colorのネストはできない(パスワードが赤にならない)
779 | log += pass;
780 | if (HTML_OUT) log = ""+log+""; // color=lemonchiffon
781 | addLog(log);
782 | }
783 | });
784 | }
785 |
786 | /**
787 | * ピアリスト要求
788 | */
789 | public void onClickRequestPeers(View view) {
790 | addMethodLog("mWifiP2pManager.requestPeers()");
791 | if (isNull(true)) { return; }
792 |
793 | mWifiP2pManager.requestPeers(mChannel, new PeerListListener() {
794 | // requestPeers()実行後、非同期応答あり
795 | public void onPeersAvailable(WifiP2pDeviceList peers) {
796 | mPeers.clear();
797 | mPeers.addAll(peers.getDeviceList());
798 | int cnt = mPeers.size();
799 | addLog(" onPeersAvailable() : num of peers["+cnt+"]");
800 | for (int i = 0; i < cnt; i++) {
801 | addLog(nl() + " ***********["+i+"]***********");
802 | addLog(" " + toStringDevice(mPeers.get(i)));
803 | }
804 |
805 | updatePeersSpinner();
806 | }
807 | });
808 | }
809 |
810 | /**
811 | * 子リストUI処理
812 | */
813 | private void updatePeersSpinner() {
814 | // スピナーインスタンス取得、アイテム選択イベントハンドラ設定
815 | if (mPeersSpinner == null) {
816 | mPeersSpinner = (Spinner)findViewById(R.id.spinner_peers);
817 | mPeersSpinner.setOnItemSelectedListener( new OnItemSelectedListener() {
818 | public void onItemSelected(AdapterView> parent, View view, int position, long id) {
819 | mSelectedDevice = mPeers.get(position).deviceName;
820 | addLog(nl() + "Selected Peer["+mSelectedDevice+"]");
821 | }
822 |
823 | public void onNothingSelected(AdapterView> arg0) {}
824 | });
825 | }
826 |
827 | // 子リストからデバイス名の配列を生成し、スピナーのアイテムとして設定
828 | int cnt = mPeers.size();
829 | String[] peers = new String[cnt];
830 | for (int i = 0; i < cnt; i++) {
831 | peers[i] = mPeers.get(i).deviceName;
832 | }
833 | ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, peers);
834 | mPeersSpinner.setAdapter(adapter);
835 | }
836 |
837 | /* ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
838 | * ブロードキャストレシーバ
839 | * TODO デコレータパターンを適用できそう??(あまり興味ない)
840 | * レシーバの登録/解除メソッドを含めて見直す余地はありそう
841 | */
842 |
843 | /**
844 | * ブロードキャストレシーバ 全部
845 | */
846 | public class WiFiDirectBroadcastReceiver extends BroadcastReceiver {
847 |
848 | @Override
849 | public void onReceive(Context context, Intent intent) {
850 | String action = intent.getAction();
851 | String log = "onReceive() ["+action+"]";
852 | if (HTML_OUT) log = ""+log+"";
853 | addLog(nl() + log);
854 |
855 | if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
856 | mIsWiFiDirectEnabled = false;
857 | int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
858 | String sttStr;
859 | switch (state) {
860 | case WifiP2pManager.WIFI_P2P_STATE_ENABLED:
861 | mIsWiFiDirectEnabled = true;
862 | sttStr = "ENABLED";
863 | break;
864 | case WifiP2pManager.WIFI_P2P_STATE_DISABLED:
865 | sttStr = "DISABLED";
866 | break;
867 | default:
868 | sttStr = "UNKNOWN";
869 | break;
870 | }
871 | addLog("state["+sttStr+"]("+state+")");
872 | changeBackgroundColor();
873 | } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
874 | // このタイミングでrequestPeers()を呼び出すと、peerの変化(ステータス変更とか)がわかる
875 | // 本テストアプリは、メソッド単位での実行をテストしたいので、ここではrequestPeers()を実行しない
876 | addLog("try requestPeers()");
877 | } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
878 | NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
879 | // networkInfo.toString()はCSV文字列(1行)を返す。そのままでは読みにくいので、カンマを改行へ変換する。
880 | String nlog = networkInfo.toString().replaceAll(",", nl()+" ");
881 | if (HTML_OUT) nlog = ""+nlog+""; // khaki
882 | addLog(nlog);
883 | } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
884 | WifiP2pDevice device = (WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
885 | addLog(toStringDevice(device));
886 | }
887 | }
888 | }
889 |
890 | /**
891 | * ブロードキャストレシーバ P2P ON/OFF状態変更検知
892 | */
893 | public class WDBR_P2P_STATE_CHANGED_ACTION extends BroadcastReceiver {
894 | @Override
895 | public void onReceive(Context context, Intent intent) {
896 | String action = intent.getAction();
897 | String log = "onReceive() ["+action+"]";
898 | if (HTML_OUT) log = ""+log+"";
899 | addLog(nl() + log);
900 |
901 | if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
902 | mIsWiFiDirectEnabled = false;
903 | int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
904 | String sttStr;
905 | switch (state) {
906 | case WifiP2pManager.WIFI_P2P_STATE_ENABLED:
907 | mIsWiFiDirectEnabled = true;
908 | sttStr = "ENABLED";
909 | break;
910 | case WifiP2pManager.WIFI_P2P_STATE_DISABLED:
911 | sttStr = "DISABLED";
912 | break;
913 | default:
914 | sttStr = "UNKNOWN";
915 | break;
916 | }
917 | addLog("state["+sttStr+"]("+state+")");
918 | changeBackgroundColor();
919 | }
920 | }
921 | }
922 |
923 | /**
924 | * ブロードキャストレシーバ 周辺のP2Pデバイス検出
925 | */
926 | public class WDBR_P2P_PEERS_CHANGED_ACTION extends BroadcastReceiver {
927 | @Override
928 | public void onReceive(Context context, Intent intent) {
929 | String action = intent.getAction();
930 | String log = "onReceive() ["+action+"]";
931 | if (HTML_OUT) log = ""+log+"";
932 | addLog(nl() + log);
933 |
934 | if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
935 | // このタイミングでrequestPeers()を呼び出すと、peerの変化(ステータス変更とか)がわかる
936 | // 本テストアプリは、メソッド単位での実行をテストしたいので、ここではrequestPeers()を実行しない
937 | addLog("try requestPeers()");
938 | }
939 | }
940 | }
941 |
942 | /**
943 | * ブロードキャストレシーバ 接続状態変更(CONNECT/DISCONNECT)検知
944 | */
945 | public class WDBR_P2P_CONNECTION_CHANGED_ACTION extends BroadcastReceiver {
946 | @Override
947 | public void onReceive(Context context, Intent intent) {
948 | String action = intent.getAction();
949 | String log = "onReceive() ["+action+"]";
950 | if (HTML_OUT) log = ""+log+"";
951 | addLog(nl() + log);
952 |
953 | if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
954 | NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
955 | // networkInfo.toString()はCSV文字列(1行)を返す。そのままでは読みにくいので、カンマを改行へ変換する。
956 | String nlog = networkInfo.toString().replaceAll(",", nl()+" ");
957 | if (HTML_OUT) nlog = ""+nlog+""; // khaki
958 | addLog(nlog);
959 | }
960 | }
961 | }
962 |
963 | /**
964 | * ブロードキャストレシーバ 自端末検知
965 | */
966 | public class WDBR_P2P_THIS_DEVICE_CHANGED_ACTION extends BroadcastReceiver {
967 | @Override
968 | public void onReceive(Context context, Intent intent) {
969 | String action = intent.getAction();
970 | String log = "onReceive() ["+action+"]";
971 | if (HTML_OUT) log = ""+log+"";
972 | addLog(nl() + log);
973 |
974 | if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
975 | WifiP2pDevice device = (WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
976 | addLog(toStringDevice(device));
977 | }
978 | }
979 | }
980 |
981 | /**
982 | * APIボタンエリアの背景色をWi-Fi Direct有効/無効フラグで色分けする
983 | * 有効 青
984 | * 無効 赤
985 | */
986 | private void changeBackgroundColor() {
987 | ScrollView sc = (ScrollView)findViewById(R.id.layout_apibuttons);
988 | sc.setBackgroundColor( mIsWiFiDirectEnabled ? Color.BLUE : Color.RED );
989 | }
990 |
991 | /* ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
992 | * 割りとどうでもいいメソッド
993 | */
994 |
995 | /**
996 | * ANDROID_ID取得
997 | */
998 | private String getAndroid_ID() {
999 | return Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
1000 | }
1001 |
1002 | /**
1003 | * Wi-Fi MACアドレス取得
1004 | */
1005 | private String getMACAddress() {
1006 | WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
1007 | WifiInfo wifiInfo = manager.getConnectionInfo();
1008 | String mac = wifiInfo.getMacAddress();
1009 | return mac;
1010 | }
1011 |
1012 | /**
1013 | * アプリバージョン取得
1014 | */
1015 | private String getAppVersion() {
1016 | PackageInfo packageInfo = null;
1017 | try {
1018 | packageInfo = getPackageManager().getPackageInfo("com.example.p2p.apitest", PackageManager.GET_META_DATA);
1019 | String ver = "versionCode : "+packageInfo.versionCode+" / "+"versionName : "+packageInfo.versionName;
1020 | return ver;
1021 | } catch (NameNotFoundException e) {
1022 | e.printStackTrace();
1023 | }
1024 | return null;
1025 | }
1026 |
1027 | /**
1028 | * 端末はp2p featureを持っているか?
1029 | */
1030 | private boolean hasP2P() {
1031 | return getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT);
1032 | }
1033 |
1034 | /**
1035 | * Wi-Fi Direct 設定画面表示
1036 | */
1037 | public void onClickGotoWiFiSetting(View view) {
1038 | String pac = "com.android.settings";
1039 | Intent i = new Intent();
1040 |
1041 | // まずはこの画面を出してみる(Galaxy Nexus 4.0はこれだったと思う)
1042 | i.setClassName(pac, pac + ".wifi.p2p.WifiP2pSettings");
1043 | try {
1044 | startActivity(i);
1045 | } catch (ActivityNotFoundException e) {
1046 | Log.e(TAG, "onClickGotoWiFiSetting() " + e.getMessage());
1047 | // 17 4.2 JELLY_BEAN_MR1
1048 | // 16 4.1, 4.1.1 JELLY_BEAN
1049 | // 15 4.0.3, 4.0.4 ICE_CREAM_SANDWICH_MR1
1050 | // 14 4.0, 4.0.1, 4.0.2 ICE_CREAM_SANDWICH
1051 | if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH+1) { // 14, 15 = ICS
1052 | startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); // ICSの場合は、たぶん、"Wi-Fi→その他"にWi-Fi DirectのON/OFFがあると思う
1053 | } else {
1054 | i.setClassName(pac, pac + ".wifi.WifiSettings"); // その他(JB)の場合はとりあえずWi-Fi設定画面を出しておく^^;
1055 | // TODO 4.1以降は、startActivity()ではなく、startPreferencePanel()なのかも
1056 | //if (getActivity() instanceof PreferenceActivity) {
1057 | // ((PreferenceActivity) getActivity()).startPreferencePanel(
1058 | // WifiP2pSettings.class.getCanonicalName(), null, R.string.wifi_p2p_settings_title, null, this, 0);
1059 | try {
1060 | startActivity(i);
1061 | Toast.makeText(this, "TRY menu -> Wi-Fi Direct", Toast.LENGTH_LONG).show();
1062 | } catch (ActivityNotFoundException e2) {
1063 | Log.e(TAG, "onClickGotoWiFiSetting() " + e2.getMessage());
1064 | }
1065 | }
1066 | }
1067 | }
1068 |
1069 | /**
1070 | * ICSかつAndroidのソースツリー内でビルドした場合のにみ有効
1071 | * enable/disableはhideメソッドなため、通常のアプリビルドだとメソッドが見えない
1072 | * かつ、JB以降ではenable/disableはたぶん排除された・・
1073 | */
1074 | public void onClickEnable(View view) {
1075 | if (isNull(true)) {
1076 | return;
1077 | }
1078 | if (mIsWiFiDirectEnabled) {
1079 | //mWifiP2pManager.disableP2p(mChannel);
1080 | Log.w(TAG, "onClickEnable() Skip disableP2p()");
1081 | } else {
1082 | //mWifiP2pManager.enableP2p(mChannel);
1083 | Log.w(TAG, "onClickEnable() Skip enableP2p()");
1084 | }
1085 | }
1086 |
1087 | }
--------------------------------------------------------------------------------