GeofenceTransitionsIntentService'没有默认的构造函数

时间:2019-03-08 11:51:10

标签: geofencing

我正在使用地理围栏。 我编写了服务类GeofenceTransitionsIntentService,它显示红色标记,并说没有Default构造函数。请帮助我。

它是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
     <!--optional (needed if default theme has no action bar) -->
    <activity android:name=".loginpage"></activity>
    <activity android:name=".Userlogin" />
    <activity android:name=".Register" />
    <activity android:name=".MainActivity">

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


        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

    <service android:name=".GeofenceTransitionsIntentService"/> // here's the error. it turned up red.


</application>

这是我的java类。它有一个构造函数,但没有默认构造函数,如果我手动放置一个构造函数,则会显示错误。

package com.example.foodtag;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.GeofencingEvent;

import java.util.ArrayList;
import java.util.List;

public class GeofenceTransitionsIntentService extends IntentService {
    GeofencingEvent geofencingEvent;
/**
 * Creates an IntentService.  Invoked by your subclass's constructor.
 *
 * @param name Used to name the worker thread, important only for debugging.
 */
public GeofenceTransitionsIntentService(String name) { //here is the constructor but it is not default constructor.
    super(name);
}

GeofenceTransitionsIntentService(){ // and if i create constructor without parameters, it is showing an error "There is no default constructor available in 'android.app.IntentService'"

}


@Override
protected void onHandleIntent( Intent intent) {  

    geofencingEvent = GeofencingEvent.fromIntent(intent);
    if(geofencingEvent.hasError()){
        Toast.makeText(this, "Event has error", Toast.LENGTH_SHORT).show();
    return;
    }

    int geoFenceTransition = geofencingEvent.getGeofenceTransition();

    if (geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER){

        List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
      // String geofenceTransitionDetails = getGeofenceTransitionDetails(this, geoFenceTransition,triggeringGeofences);

      //  sendNotofication();

    }else {
        Toast.makeText(this, "geofence transition invalid", Toast.LENGTH_SHORT).show();        }
}

private  String getGeofenceTransitionDetails(
        Context context,
        int geofenceTransition,
        List<Geofence> triggeringGeofences){
   // String geofenceTransitionString = getTransitionString(geofenceTransition);//getTransitionString(geoFenceTransition)

    ArrayList triggeringgeofencesIdsList = new ArrayList();
    for (Geofence geofence : triggeringGeofences){
        triggeringgeofencesIdsList.add(geofence.getRequestId());
    }

    String triggeringgeofencesIdsString = TextUtils.join(",",triggeringgeofencesIdsList);

    return  triggeringgeofencesIdsString;
}

}

1 个答案:

答案 0 :(得分:0)

创建一个默认的构造函数(不带参数),并在super上加上类名。

#pragma omp atomic 
{
if(a = getmystring(fp)) fprintf(fpw, "A: %s\n", a);
if(b = getmystring(fp)) fprintf(fpw, "B: %s\n", b);
}