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

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

Unfortunately, Beacon Project has stopped.

这是我的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中的一种错误,但无法弄明白.

最佳答案 根据说明书

You must create a class that extends Application (shown in the example) and then declare this in your AndroidManifest.xml.

所以创建一个扩展Application类的类并将其添加到manifest.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找到

点赞