/ / ब्लूटूथ चालू कैसे करें - c #, android, unity3d, plugins, bluetooth

ब्लूटूथ कैसे चालू करें - सी #, एंड्रॉइड, एकता 3 डी, प्लगइन्स, ब्लूटूथ

मैं एंड्रॉइड प्लगइन के माध्यम से एकता परियोजना में ब्लूटूथ संचार करने की कोशिश कर रहा हूं और शुरुआत में मैं ब्लूटूथ चालू करना चाहता हूं।

जावा कोड इस तरह दिखता है

package com.example.unityplugin;

import android.bluetooth.BluetoothAdapter;

public class PluginClass {
public static String testMessage(){
return "I AM WORKING";
}

public static String TurnOnBluetooth(){
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter != null) {
if (!bluetoothAdapter.isEnabled()) {
bluetoothAdapter.enable();
return "BLUETOOTH ON";
} else {
return "WAS ON";
}
}
return "no bluetooth adapter";
}

}

और एकता में उतना ही सरल है

void Start () {
textMEsh = GetComponent<TextMesh>();
var plugin = new AndroidJavaClass("com.example.unityplugin.PluginClass");
textMEsh.text = plugin.CallStatic<string>("testMessage");
textMEsh.text = plugin.CallStatic<string>("TurnOnBluetooth");
}

इसलिए ऐप में प्रदर्शित होने वाला टेक्स्ट पहले के बाद बदल जाता हैपद्धति "testMessage" को "I AM WORKING" लेकिन फिर कुछ भी नहीं होता है और मैं वास्तव में नहीं समझता "- ब्लूटूथ चालू नहीं हो रहा है और मुझे लॉग से निम्न त्रुटि दिखाई दे रही है:

मैं / एकता: AndroidJavaException: java.lang.SecurityException: Need BLUETOOTH ADMIN अनुमति: न तो उपयोगकर्ता 10069 और न ही वर्तमान प्रक्रिया है android.permission.BLUETOOTH_ADMIN।

मुझे उस अनुमति को एकता में ठीक से कैसे सेट करना चाहिए?

उत्तर:

उत्तर № 1 के लिए 1

यह एक अनुमति त्रुटि है। आपको ब्लूटूथ की अनुमति को एकता में जोड़ने की आवश्यकता है।

1।के लिए जाओ <UnityInstallationDirecory>EditorDataPlaybackEnginesAndroidPlayerApk, कॉपी करें AndroidManifest.xml आपके लिए फ़ाइल <ProjectName>AssetsPluginsAndroid.

अगर <ProjectName>AssetsPluginsAndroid doesn "टी अभी तक मौजूद है, इसे बनाएँ। फ़ोल्डर की वर्तनी संवेदनशील है और सही वर्तनी होनी चाहिए।

2से कॉपी की गई मैनिफ़ेस्ट फ़ाइल को खोलें <ProjectName>AssetsPluginsAndroid और अपना प्रकटीकरण जोड़ें।

इसमें निम्नलिखित अनुमति जोड़ें:

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

3AndroidManifest संशोधन, बनाएँ और भागो।

एकता अब अंतिम निर्माण में ब्लूटूथ की अनुमति शामिल करेगी।