2016-09-12 3 views
0

BLE 서비스를 처리하기 위해 AndroidL에서 BluetoothLeGatt Example Project를 구현하려고합니다. BluetoothLeGatt 구현

BluetoothLeGatt Example Android

실제 상태

내가 하나의 활동이 내 자신의 응용 프로그램을 가지고 내가 파편과 다른 페이지 사이를 전환하고 있다는 점이다. 나는 안드로이드 예제를 구현하여 블루투스 데이터를 수신하고이를 자신의 데이터 클래스에 저장할 수있다.

블루투스 예제는 내 장치에서 실행중인 경우 문제없이 작동합니다. 나는 또한 내 애플 리케이션에 예를 구현하는 다음과 같은 매니페스트에 "활동을 시작합니다"로 사용할 수 있습니다 :

<?xml version="1.0" encoding="utf-8"?> 
 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 
    package="com.example.bb.app"> 
 
    <uses-permission android:name="android.permission.BLUETOOTH"/> 
 
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> 
 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
 

 
    <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/> 
 

 
    <application 
 
     android:allowBackup="true" 
 
     android:icon="@mipmap/ic_launcher" 
 
     android:label="@string/app_name" 
 
     android:supportsRtl="true" 
 
     android:debuggable="true"> 
 

 

 
     <activity 
 
      android:name=".DeviceScanActivity" 
 
      android:configChanges="keyboardHidden|orientation|screenSize" 
 
      android:label="@string/app_name"> 
 
      <!--android:theme="@style/AppTheme.NoActionBar"--> 
 
      <intent-filter> 
 
       <action android:name="android.intent.action.MAIN" /> 
 
       <category android:name="android.intent.category.LAUNCHER" /> 
 
      </intent-filter> 
 
     </activity> 
 
     
 
     <activity android:name=".DeviceControlActivity"/> 
 
     <activity android:name=".MyActivity"/> 
 
     <service android:name=".BluetoothLeService" android:enabled="true"/> 
 
     
 
     <meta-data 
 
      android:name="com.google.android.gms.version" 
 
      android:value="@integer/google_play_services_version" /> 
 
    </application> 
 
</manifest>

하지만 난 예제 활동과 내 자신의 사이를 전환 할 수 없습니다입니다.

buttonChangeActivity = (Button) findViewById(R.id.buttonChangeActivity); 
 

 
     buttonChangeActivity.setOnClickListener(new View.OnClickListener() { 
 
      @Override 
 
      public void onClick(View v) { 
 
       Toast.makeText(DeviceControlActivity.this, "PRESSED", Toast.LENGTH_SHORT).show(); 
 

 
       try{ 
 
        Intent myIntent = new Intent(DeviceControlActivity.this, MyActivity.class); 
 
        DeviceControlActivity.this.startActivity(myIntent); 
 
       }catch (Exception e){ 
 
        Toast.makeText(DeviceControlActivity.this, "ERROR", Toast.LENGTH_SHORT).show(); 
 
       } 
 

 
      } 
 
     });

을 그리고 그것은 여전히 ​​작동한다 : 나는 그런 식으로 전환하는 OnClickListener를 함께 간단한 버튼을 사용하고 있습니다. 하지만 MyActivity 클래스는 Theme.AppCompat를 사용해야하지만 이미 사용 중입니다.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bb.app/com.example.bb.app.MyActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) 
 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
 
                     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
 
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
 
                     at android.os.Handler.dispatchMessage(Handler.java:102) 
 
                     at android.os.Looper.loop(Looper.java:135) 
 
                     at android.app.ActivityThread.main(ActivityThread.java:5258) 
 
                     at java.lang.reflect.Method.invoke(Native Method) 
 
                     at java.lang.reflect.Method.invoke(Method.java:372) 
 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
 
                    Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
 
                     at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:343) 
 
                     at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312) 
 
                     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277) 
 
                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
 
                     at com.example.bb.app.MyActivity.onCreate(MyActivity.java:262) 
 
                     at android.app.Activity.performCreate(Activity.java:5990) 
 
                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)  
 
                     at android.app.ActivityThread.access$800(ActivityThread.java:151)  
 
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)

내 활동 도구 모음을 사용하고 있습니다 및 예제 프로젝트는 액션 바을 사용 그래서 내가 주제 잠시 사이에 "스위치"필요 확신 다음은 전체 오류 코드는 내 프로젝트가 실행되고 있지만 어떻게해야할지 모르겠다. 이미이 문제에 대한 몇 가지 다른 경우를 읽었습니다 :

Stackoverflow 1

어떤 조언을 어떻게 테마를 전환 할 수있는 프로젝트가 어디에 내 안드로이드 Studio에서 변경하는 실행 중이거나 동안?

답변

0

몇 분만 더 기다려주세요. 내 문제는 해결되었습니다.

그냥 같이 매니페스트를 변경 :

<?xml version="1.0" encoding="utf-8"?> 
 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 
    package="com.example.bb.app"> 
 
    <uses-permission android:name="android.permission.BLUETOOTH"/> 
 
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> 
 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
 

 
    <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/> 
 

 
    <application 
 
     android:allowBackup="true" 
 
     android:icon="@mipmap/ic_launcher" 
 
     android:label="@string/app_name" 
 
     android:supportsRtl="true" 
 
     android:theme="@style/AppTheme.NoActionBar" 
 
     android:debuggable="true"> 
 

 

 
     <activity 
 
      android:name=".MyActivity" 
 
      android:configChanges="keyboardHidden|orientation|screenSize" 
 
      android:label="@string/app_name"> 
 
      <!--android:theme="@style/AppTheme.NoActionBar"--> 
 
      <intent-filter> 
 
       <action android:name="android.intent.action.MAIN" /> 
 
       <category android:name="android.intent.category.LAUNCHER" /> 
 
      </intent-filter> 
 
     </activity> 
 

 
     <activity android:name=".DeviceControlActivity" 
 
        android:theme="@android:style/Theme.Holo.Light"/> 
 
     <activity android:name=".DeviceScanActivity" 
 
        android:theme="@android:style/Theme.Holo.Light"/> 
 
     <service android:name=".BluetoothLeService" android:enabled="true"/> 
 

 
     <meta-data 
 
      android:name="com.google.android.gms.version" 
 
      android:value="@integer/google_play_services_version" /> 
 
    </application> 
 
</manifest>

그래서 어쨌든, 각 활동에 대한 감사를 테마로 변경.