SynthTAROU
@SynthTAROU

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

BLE選択アクティビティからUUIDを取得したい

解決したいこと

AndroidでBLE選択ダイアログを出現させたいです。
UUIDまたは、BluetoothDeviceオブジェクトを取得したいのですが、わかりませんでした。
よろしくお願いします。

例)
ダイアログを出すところまではできましたが、結果を受け取れません。
OnActivityResultが使えなくなったのですが、
intentSender.sendIntent(context, SELECT_DEVICE_REQUEST_CODE, intent, null, null);
の結果が受け取れません。

発生している問題・エラー

なにも結果が表示されません

該当するソースコード

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    Log.e(TAG, "=====================5");
    deviceManager.associate(associationRequest, new Executor() {
        @Override
        public void execute(Runnable command) {
            command.run();
        }
    }, associationCallback);
} else {
    deviceManager.associate(associationRequest, associationCallback, null);
}


final CompanionDeviceManager.Callback associationCallback = new CompanionDeviceManager.Callback() {
    @Override
    public void onAssociationPending(@NonNull IntentSender intentSender) {
        Log.e(TAG, "=====================2 " + context.getClass());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            try {
                Intent intent = new Intent();
                BroadcastReceiver receiver = new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        Log.e(TAG, "onReceive" + intent);
                    }
                };
                IntentFilter filter = new IntentFilter();
                //filter.addAction();
                context.registerReceiver(receiver, filter);
                intentSender.sendIntent(context, SELECT_DEVICE_REQUEST_CODE, intent, null, null);
               <----- how do i get UUID from this dialog
            } catch (IntentSender.SendIntentException e) {
                throw new RuntimeException(e);
            }
            //((Activity) context).startIntentSenderForResult(intentSender, SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0);
        } else {
            // calls onDeviceFound
            super.onAssociationPending(intentSender);
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        Log.e(TAG, "=====================5");
        deviceManager.associate(associationRequest, new Executor() {
            @Override
            public void execute(Runnable command) {
                command.run();
            } }, associationCallback);
    } else {
        deviceManager.associate(associationRequest, associationCallback, null);
    }

例)

自分で試したこと

該当しそうな、メソッドは全部しらべたり、IntentFilterなども試してみましたが、
わかりませんでした。ActivityResultや、Launcherも、該当メソッドが見つかりませんでした。

0

No Answers yet.

Your answer might help someone💌