0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[ Android ] 画面遷移後の画面でサーバから乱数を取得 (未完)

Posted at

今回は画面遷移後の画面でHTTP通信を行うプログラムの実装を試みた。

java.net.SocketException: Socket failed: EPERM(Operation not permitted)

現在、画面遷移は以下のような流れになっている。
スクリーンショット (38).png

ボタン2を押下により画面3が呼び出し、onCreateで非同期処理を実行。
非同期処理クラスのonPostExcecuteでサーバから取得した乱数をTextViewに表示。
しかし、通信する際、
java.net.SocketException: Socket failed: EPERM(Operation not permitted)
というエラーが表示される。

調査結果

未だ解決方法はわかっていない。

調査では以下のような解決方法が示されていたが、
試してみたが、うまくいかなかった。
本実装の問題とは関係ないようである。
他の方はこれで解決できるかもしれないので、
参考にしていただきたい。

[解決方法]
・AndroidManifest.xmlに以下のコードを追加する。

<manifest>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

・参考URL
https://stackoverflow.com/questions/56266801/java-net-socketexception-socket-failed-eperm-operation-not-permitted

まとめ

私の記事「サーバクライアント通信」に記載したコードでは
HTTP通信とサーバからの値取得はうまくいっていた。
今回と過去の記事での違いは
MainActivityから非同期処理を呼び出しているか、
画面遷移後の画面から呼び出しているかである。
ここに何かヒントがあるのか…
次回はこの問題を解決できるよう頑張りたい。
以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?