BluetoothデバイスがAndroidデバイスに接続されているかどうかを確認するにはどうすればよいですか?
この例は、BluetoothデバイスがAndroidデバイスに接続されているかどうかを確認する方法を示しています。
ステップ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" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="24sp" android:textStyle="bold" android:text="Open bluetooth setting from your own device and check for better results."/> </LinearLayout>
ステップ3 −次のコードをsrc / MainActivity.java
に追加しますimport android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED); filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); this.registerReceiver(broadcastReceiver, filter); } private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { BluetoothDevice device; @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { Toast.makeText(getApplicationContext(), "Device is now Connected", Toast.LENGTH_SHORT).show(); } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { Toast.makeText(getApplicationContext(), "Device is disconnected", Toast.LENGTH_SHORT).show(); } } }; }
ステップ4 −次のコードをandroidManifest.xmlに追加します
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="https://schemas.android.com/apk/res/android" package="app.com.sample"> <uses-permission android:name="android.permission.BLUETOOTH" /> <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" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
-
AndroidデバイスでCyanogenModをLineageOSに置き換える方法
死にゆくCyanogenModからその精神的な後継者であるLineageOSへの大規模な移行が起こっています。 (理由と方法に関するすべての情報があります。)数百万、または少なくとも数十万のルート化されたAndroidユーザーは、CyanogenModと同様に、肥大化のない柔軟なバージョンを提供するオープンソースプロジェクトに移行しています。在庫のAndroidエクスペリエンスの。 素晴らしいニュースは、LineageOSエクスペリメンタルビルドを使用して、切り替えをかなりシームレスに行えることです。 TWRPリカバリを使用しますが、一般的なプロセスは他のリカバリツールでも同様です。 まず
-
Bluetooth キーボードを Android デバイスに接続する方法
携帯電話がよりスマートになり、一部の携帯電話はタブレット サイズまで大きくなり、ほとんどのタスクを携帯電話で実行するのがより便利になりました。これにより、タスク間で Android タブレットとラップトップを切り替える負担が軽減されました。ただし、ほとんどの人がスマートフォンやタブレットで直面する唯一の問題は、物理的なキーボードで入力できるほど速く入力できないことです。この問題をある程度解決するために、いつでも物理キーボードを電話に接続して、コンピューターで行うように入力できます。 物理キーボードを電話に接続するには、3 つの方法があります。以下に、詳細な手順を含む簡単な手順を示します。