Play Services 12.0.0 で android.permission.READ_PHONE_STATE が要求されている件

Google Play Console にアップすると怒られて受け付けてくれません。

"New permissions added
WARNING
Users that have the APK with version code 19 may need to accept one or more of the android.permission.READ_PHONE_STATE and android.permission.WRITE_EXTERNAL_STORAGE permissions, which may result in them not upgrading to this version of the app."

android.permission.READ_PHONE_STATE てどんな許可内容だったか。

端末のステータスとIDの読み取り
端末の電話機能へのアクセスをアプリに許可します。これにより、電話番号、端末ID、通話中かどうか、通話相手の電話番号をアプリから特定できるようになります。

危険なパーミッションです。

「通話機能の必要ないアプリでも Play Service を利用していれば弾かれる」というような状況のようです。

android.permission.READ_PHONE_STATE added with Play Services 12.0.0 [76024034] - Visible to Public - Issue Tracker

android - Why has the READ_PHONE_STATE permission been added? - Stack Overflow

以下で回避できるようです。できました。


<uses-permission
    android:name="android.permission.READ_PHONE_STATE"
    tools:node="remove" />

なんなんでしょうね。

このような混乱はきっとこの先も増えていきそうです。

ーーー
2018-04-04: 追記
修正されているようです。
Release Notes  |  Google APIs for Android  |  Google Developers


【仮想通貨】Cryptowatch Public Market REST API を眺める

キャバ嬢に

「リップル買っちゃった。名前がかわいいし。」

などと言われて即全てを手放しました、おはようございます。

そんな下落が止まらない仮想通貨たち。

仮想通貨全体の上げ下げを把握することができます。

Cryptowatch - live Bitcoin price charts

ここではAPIにてリアルタイムな情報を公開しています。

無料では当然制限はついてきますが。

Public Market REST API - Cryptowatch

いくつか簡単にデータを取得してみましょう。

Prices

Returns the current price for all supported markets. Some values may be out of date by a few seconds.

Example: https://api.cryptowat.ch/markets/prices

価格です。量が多いので日本円絡みのものだけ見てみます。


~ $ curl -s https://api.cryptowat.ch/markets/prices | jq "." | grep jpy
    "bitflyer:btcfxjpy": 990450,
    "bitflyer:btcjpy": 980519,
    "bitflyer:btcjpy-biweekly-futures": 984440,
    "bitflyer:btcjpy-weekly-futures": 984750,
    "bitmex:btcjpy-quarterly-futures": 9342,
    "kraken:btcjpy": 980085,
    "kraken:ethjpy": 102171,
    "kraken:repjpy": 0,
    "kraken:xrpjpy": 0,
    "kraken:zecjpy": 0,
    "quoine:bchjpy": 139770.97,
    "quoine:btcjpy": 1010138.75,
    "quoine:ethjpy": 107000,

いくつかは価格が「0」となっていますが。

JSON形式で、項目としては


"(取引所):(通貨ペア)": 価格円

が取得できるようです。

もうひとつみてみます。

Asset
Returns a single asset. Lists all markets which have this asset as a base or quote.

Example: https://api.cryptowat.ch/assets/btc

こちらでは以下のようなものが取得できます。


~ $ curl -s https://api.cryptowat.ch/assets/jpy | jq '.'
{
  "result": {
    "id": 104,
    "symbol": "jpy",
    "name": "Japanese Yen",
    "fiat": true,
    "markets": {
      "quote": [
        {
          "id": 89,
          "exchange": "kraken",
          "pair": "btcjpy",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/kraken/btcjpy"
        },
        {
          "id": 100,
          "exchange": "kraken",
          "pair": "ethjpy",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/kraken/ethjpy"
        },
        {
          "id": 120,
          "exchange": "kraken",
          "pair": "repjpy",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/kraken/repjpy"
        },
        {
          "id": 126,
          "exchange": "kraken",
          "pair": "zecjpy",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/kraken/zecjpy"
        },
        {
          "id": 140,
          "exchange": "kraken",
          "pair": "xrpjpy",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/kraken/xrpjpy"
        },
        {
          "id": 184,
          "exchange": "quoine",
          "pair": "btcjpy",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/quoine/btcjpy"
        },
        {
          "id": 196,
          "exchange": "quoine",
          "pair": "ethjpy",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/quoine/ethjpy"
        },
        {
          "id": 206,
          "exchange": "quoine",
          "pair": "bchjpy",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/quoine/bchjpy"
        },
        {
          "id": 215,
          "exchange": "bitflyer",
          "pair": "btcjpy",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/bitflyer/btcjpy"
        },
        {
          "id": 217,
          "exchange": "bitflyer",
          "pair": "btcjpy-weekly-futures",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/bitflyer/btcjpy-weekly-futures"
        },
        {
          "id": 218,
          "exchange": "bitflyer",
          "pair": "btcjpy-biweekly-futures",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/bitflyer/btcjpy-biweekly-futures"
        },
        {
          "id": 409,
          "exchange": "bitflyer",
          "pair": "btcfxjpy",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/bitflyer/btcfxjpy"
        },
        {
          "id": 248,
          "exchange": "bitmex",
          "pair": "btcjpy-quarterly-futures",
          "active": true,
          "route": "https://api.cryptowat.ch/markets/bitmex/btcjpy-quarterly-futures"
        },
        {
          "id": 424,
          "exchange": "bitmex",
          "pair": "btcjpy-monthly-futures",
          "active": false,
          "route": "https://api.cryptowat.ch/markets/bitmex/btcjpy-monthly-futures"
        }
      ]
    }
  },
  "allowance": {
    "cost": 162263,
    "remaining": 7999837737
  }
}

これを見ると個別のチャートを参照できるURLは


https://api.cryptowat.ch/markets/(取引所)/(通貨ペア)

であることがわかります。

他にもたくさんのデータが取得できるようです。

さあ、みんなもやってみよう。

 

👉 Kotlin 今どきよくある JSON リクエストからのパース hatena-bookmark


Architecture Blueprints の非同期処理実装にみる Android SDK の方向性

MVP、MVVM、Clean Architecture、Dagger2、Data Binding、Archtecture Components などいろいろな組み合わせの実装例が ToDoアプリにて公開されています。

googlesamples/android-architecture: A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.

非同期処理部分を見てみると現在はすべて(todo-mvp-rxjavaを除く)が以下の実装となり、非同期処理の主役であった AsyncTask/Loader API を利用した記述は消え去っています。

まず、java.util.concurrent.Executor(s) を使って、AppExecutors を作っておいて、


open class AppExecutors constructor(
    val diskIO: Executor = DiskIOThreadExecutor(),
    val networkIO: Executor = Executors.newFixedThreadPool(THREAD_COUNT),
    val mainThread: Executor = MainThreadExecutor()
) {

  private class MainThreadExecutor : Executor {

    private val mainThreadHandler = Handler(Looper.getMainLooper())

    override fun execute(command: Runnable) {
      mainThreadHandler.post(command)
    }
  }
}

AppExecutors.kt

それに対応するデータベースやストレージ向けのExecutorを作ります。


class DiskIOThreadExecutor : Executor {

  private val diskIO = Executors.newSingleThreadExecutor()

  override fun execute(command: Runnable) { diskIO.execute(command) }
}

DiskIOThreadExecutor.kt

これらを使って以下のようにして非同期処理を実装します。


appExecutors.diskIO.execute {

  // IOスレッドで実行する
  // ...

  appExecutors.mainThread.execute {

    // メインスレッドで実行する
    // ...

  }

}

実装例では、コールバックを使ってPresenterまで伝達しています。


override fun getTasks(callback: TasksDataSource.LoadTasksCallback) {

  appExecutors.diskIO.execute {

    // IOスレッドで実行する
    val tasks = tasksDao.getTasks()

    appExecutors.mainThread.execute {

      // メインスレッドで実行する
      if (tasks.isEmpty()) {
        callback.onDataNotAvailable()
      } else {
        callback.onTasksLoaded(tasks)
      }

    }

  }
}

TasksLocalDataSource.kt

AsyncTask/Loader APIs の排除の方向性は、「Deprecated(廃止予定) samples」に移動されたブランチからも認識できます。

googlesamples/android-architecture: A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.

この流れについては、droidcon NYC 2017 - Android Architecture Round Table でも、話が挙がっていました。

it looks like Google is abandoning old API is like loaders and recommending patterns there are much less coupled with the framework, which is good but what happens with these API is are we abundant in then and I'm talking about classes like sync adapters loader async tasks etc

Google はLoaderのような古いAPI や フレームワークと関係の薄いパターンを推奨することをやめているように見えます。 それはいいことですが、それら古いAPIを捨てることは何を引き起こすか、AsyncAdapter や Loaderなどについて話したいと思います。

今後の、Android SDKは、フレームワークを意識したAPIが増えていくのでしょう。