Android
 Computer >> コンピューター >  >> プログラミング >> Android

現在のBluetoothがAndroidでLe2MPyをサポートしていることを確認するにはどうすればよいですか?


この例は、Androidで現在のBluetoothがLe2MPyをサポートしていることを確認する方法を示しています。

ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。

ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。

<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android = "https://schemas.android.com/apk/res/android"
   xmlns:app = "https://schemas.android.com/apk/res-auto"
   xmlns:tools = "https://schemas.android.com/tools"
   android:layout_width = "match_parent"
   android:gravity = "center"
   android:layout_height = "match_parent"
   tools:context = ".MainActivity">
   <TextView
      android:id = "@+id/text"
      android:textSize = "30sp"
      android:layout_width = "match_parent"
      android:layout_height = "match_parent" />
</LinearLayout>

上記のコードでは、テキストビューを使用して、Le2MPyに関するBluetoothステータスを示しています。

ステップ3 −次のコードをsrc / MainActivity.java

に追加します
package com.example.myapplication;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.os.Build;
import android.os.Bundle;
import android.os.health.SystemHealthManager;
import android.provider.Telephony;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.telephony.SmsManager;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
   TextView textView;
   @RequiresApi(api = Build.VERSION_CODES.N)
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      textView = findViewById(R.id.text);
      final BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
      if (Build.VERSION.SDK_INT > = Build.VERSION_CODES.O) {
         textView.setText(""+manager.getAdapter().isLe2MPhySupported());
      }
   }
   @Override
   protected void onStop() {
      super.onStop();
   }
   @Override
   protected void onResume() {
      super.onResume();
   }
}

ステップ4 −次のコードをandroidManifest.xmlに追加します

<?xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns:android = "https://schemas.android.com/apk/res/android"
   package = "com.example.myapplication">
   <uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" />
   <uses-permission android:name = "android.permission.BLUETOOTH" />
   <uses-permission android:name = "android.permission.BLUETOOTH_ADMIN" />
   <application
      android:allowBackup = "true"
      android:icon = "@mipmap/ic_launcher"
      android:label = "@string/app_name"
      android:roundIcon = "@mipmap/ic_launcher_round"
      android:supportsRtl = "true"
      android:theme = "@style/AppTheme">
      <activity android:name = ".MainActivity">
         <intent-filter>
            <action android:name = "android.intent.action.MAIN" />
            <action android:name = "android.net.conn.CONNECTIVITY_CHANGE" />
            <category android:name = "android.intent.category.LAUNCHER" />
         </intent-filter>
      </activity>
   </application>
</manifest>

アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 android studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[実行]アイコンをクリックします。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します–

現在のBluetoothがAndroidでLe2MPyをサポートしていることを確認するにはどうすればよいですか?


  1. AndroidでArrayBlockingQueueのサイズを見つける方法は?

    例に入る前に、arrayblockingqueueとは何かを知っておく必要があります。これは、FIFO方式で移動し、最初の要素が最も長く存続し、キューの最後の要素が短期間存続します。 この例は、AndroidでArrayBlockingQueueのサイズを見つける方法について示しています ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。 ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。 <?x

  2. AndroidのConcurrentLinkedQueueで要素を見つける方法は?

    例に入る前に、ConcurrentLinkedQueueが何であるかを知っておく必要があります。これは、リンクされたノードに基づく無制限のキューです。複数のスレッドが安全にキュー要素にアクセスできます。要素はキュー戦略に基づいてFIFOとして移動し、要素はテールから挿入されます。 null値は許可されません。 この例は、AndroidのConcurrentLinkedQueueで要素を見つける方法を示しています ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力