不幸的是,[Beacon Project名称]已停止

时间:2018-02-05 23:43:11

标签: java android-studio bluetooth-lowenergy android-manifest android-ibeacon

当我尝试运行我的beacon finder项目时出现以下错误:

  

不幸的是,Beacon Project已经停止了。

这是我的logcat:

02-06 02:57:39.960 23145-23145/project.rssi.beacon.com.beaconproject W/System: ClassLoader referenced unknown path: /data/app/project.rssi.beacon.com.beaconproject-1/lib/arm64
02-06 02:57:39.995 23145-23145/project.rssi.beacon.com.beaconproject I/HwCust: Constructor found for class android.app.HwCustActivityImpl
02-06 02:57:40.002 23145-23145/project.rssi.beacon.com.beaconproject I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
02-06 02:57:40.069 23145-23145/project.rssi.beacon.com.beaconproject I/BeaconManager: BeaconManager started up on pid 23145 named 'project.rssi.beacon.com.beaconproject' for application package 'project.rssi.beacon.com.beaconproject'.  isMainProcess=true
02-06 02:57:40.072 23145-23145/project.rssi.beacon.com.beaconproject E/AndroidRuntime: FATAL EXCEPTION: main
   Process: project.rssi.beacon.com.beaconproject, PID: 23145
   java.lang.RuntimeException: Unable to start activity ComponentInfo{project.rssi.beacon.com.beaconproject/project.rssi.beacon.com.beaconproject.MainActivity}: org.altbeacon.beacon.BeaconManager$ServiceNotDeclaredException: The BeaconService is not properly declared in AndroidManifest.xml.  If using Eclipse, please verify that your project.properties has manifestmerger.enabled=true
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2793)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
       at android.app.ActivityThread.-wrap12(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:156)
       at android.app.ActivityThread.main(ActivityThread.java:6577)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
    Caused by: org.altbeacon.beacon.BeaconManager$ServiceNotDeclaredException: The BeaconService is not properly declared in AndroidManifest.xml.  If using Eclipse, please verify that your project.properties has manifestmerger.enabled=true
       at org.altbeacon.beacon.BeaconManager.verifyServiceDeclaration(BeaconManager.java:1213)
       at org.altbeacon.beacon.BeaconManager.<init>(BeaconManager.java:321)
       at org.altbeacon.beacon.BeaconManager.getInstanceForApplication(BeaconManager.java:310)
       at project.rssi.beacon.com.beaconproject.MainActivity.onCreate(MainActivity.java:22)
       at android.app.Activity.performCreate(Activity.java:6910)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864) 
       at android.app.ActivityThread.-wrap12(ActivityThread.java) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567) 
       at android.os.Handler.dispatchMessage(Handler.java:105) 
       at android.os.Looper.loop(Looper.java:156) 
       at android.app.ActivityThread.main(ActivityThread.java:6577) 
       at java.lang.reflect.Method.invoke(Native Method) 
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

  02-06 02:57:40.081 23145-23145/project.rssi.beacon.com.beaconproject I/Process: Sending signal. PID: 23145 SIG: 9

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="project.rssi.beacon.com.beaconproject">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        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>

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

</manifest>

代码没有任何问题,我猜我认为这是Android Studio中的一种错误,但无法弄清楚。

1 个答案:

答案 0 :(得分:1)

根据文件说明

  

您必须创建一个扩展Application的类(如示例所示),然后在AndroidManifest.xml中声明它。

所以创建一个扩展Application类的类并将其添加到清单。android:name="com.example.MyApplicationName"

还会将此添加到您的活动android:launchMode="singleInstance"

Application类的一个例子是:

public class MyApplicationName extends Application implements BootstrapNotifier {
private static final String TAG = ".MyApplicationName";
private RegionBootstrap regionBootstrap;

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "App started up");
    BeaconManager beaconManager = 
    BeaconManager.getInstanceForApplication(this);


}

@Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
    // Don't care
}

@Override
public void didEnterRegion(Region arg0) {

    regionBootstrap.disable();
    Intent intent = new Intent(this, MainActivity.class);
    // IMPORTANT: in the AndroidManifest.xml definition of this activity, you must set android:launchMode="singleInstance" or you will get two instances
    // created when a user launches the activity manually and it gets launched from here.
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    this.startActivity(intent);
}

@Override
public void didExitRegion(Region arg0) {

  }        
}

可以找到更多信息here