1

在我的 android 应用程序中,我使用最新的 Geoloqi API 来实现 Geofence 概念。当用户进入他通知的某个区域时,为此我使用 Push Notifications.in GeoReceiver 类三个回调方法正在调用但不是 onPushMessageReceived()。请帮助我该怎么办?我正在使用当前位置创建触发器是否需要手动进入区域,或者因为我已经在该位置它没有调用?注意:我在 assets/geoloqi.properties 文件中提供了所需的凭据。当在 logcat 中启动应用程序“成功注册 C2DM 服务”消息时也会显示。我的代码:

GeoloqiExampleActivity.java

public class GeoloqiExampleActivity extends Activity{
    String TAG = "Geoloqi Example";

     private LQService mService;
     private boolean mBound;
     GeoReceiver geoReceiver = new GeoReceiver();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent intent = new Intent(this, LQService.class);
        startService(intent);
    }


    @Override
    public void onResume() {
        super.onResume();

        // Bind to the tracking service so we can call public methods on it
        Intent intent = new Intent(this, LQService.class);
        bindService(intent, mConnection, 0);

        // Wire up the sample location receiver
        final IntentFilter filter = new IntentFilter();
        filter.addAction(GeoReceiver.ACTION_LOCATION_CHANGED);
        filter.addAction(GeoReceiver.ACTION_TRACKER_PROFILE_CHANGED);
        filter.addAction(GeoReceiver.ACTION_LOCATION_UPLOADED);
        filter.addAction(GeoReceiver.ACTION_PUSH_MESSAGE_RECEIVED);
        registerReceiver(geoReceiver, filter);

    }

    @Override
    public void onPause() {
        super.onPause();

        // Unbind from LQService
        if (mBound) {
            unbindService(mConnection);
            mBound = false;
        }
        // Unregister our location receiver
        unregisterReceiver(geoReceiver);
    }
    public void sendRequest() {

         // Performing a Trigger POST request
        if (mService != null) {
            LQSession session = mService.getSession();
            LQTracker tracker = mService.getTracker();
            tracker.setSession(session);
            // Build your request
            JSONObject trigger = new JSONObject();
            try {
                trigger.put("text", "Popcornapps");
                trigger.put("type", "message");
                trigger.put("latitude", 17.42557068);
                trigger.put("longitude",  78.42022822);
                trigger.put("radius", 500);
                trigger.put("place_name", "Banjara Hills");
            } catch (JSONException e) {
               Log.d(TAG, e.getMessage());
            }

            // Send the request
            session.runPostRequest("trigger/create", trigger, new OnRunApiRequestListener() {
                @Override
                public void onSuccess(LQSession session, HttpResponse response) {

                    Toast.makeText(GeoloqiExampleActivity.this, "Success", Toast.LENGTH_SHORT).show();
                    try {
                        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
                        StringBuilder s = new StringBuilder();
                        String sResponse;
                        while ((sResponse = reader.readLine()) != null) {
                            s = s.append(sResponse);
                        }
                    String result = s.toString().trim();
                    Log.d("On success Result", result);

                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    } catch (IllegalStateException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                @Override
                public void onFailure(LQSession session, LQException e) {
                    Log.e(TAG, e.getMessage());
                    Toast.makeText(GeoloqiExampleActivity.this, "Fail", Toast.LENGTH_LONG).show();
                }
                @Override
                public void onComplete(LQSession session, HttpResponse response, StatusLine status) {
                    Toast.makeText(GeoloqiExampleActivity.this, "Complete", Toast.LENGTH_LONG).show();
                }
            });
        } else{
            Toast.makeText(this, "service null", Toast.LENGTH_LONG).show();
        }
    }

     /** Defines callbacks for service binding, passed to bindService() */
    private ServiceConnection mConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            try {
                // We've bound to LocalService, cast the IBinder and get LocalService instance.
                LQBinder binder = (LQBinder) service;
                mService = binder.getService();
                mBound = true;
                sendRequest();//Sending API Request
            } catch (ClassCastException e) {
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            mBound = false;
        }
    };
}

GeoReceiver.java

public class GeoReceiver extends LQBroadcastReceiver {

    @Override
    public void onLocationChanged(Context arg0, Location arg1) {
        Toast.makeText(arg0, "Loc Changed ", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onPushMessageReceived(Context context, Bundle data) {
        Toast.makeText(context, "Push Msg Received ", Toast.LENGTH_LONG).show();

    }

    @Override
    public void onLocationUploaded(Context arg0, int arg1) {
        Toast.makeText(arg0, "Location Uploaded ", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onTrackerProfileChanged(Context arg0, LQTrackerProfile oldp,
            LQTrackerProfile newp) {
        Toast.makeText(arg0, "onTrackerProfileChanged ",Toast.LENGTH_SHORT).show();
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pop.geoloqi"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

    <permission
        android:name="com.pop.geoloqi.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.pop.geoloqi.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

         <activity
            android:name=".GeoloqiExampleActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <service
            android:name="com.geoloqi.android.sdk.service.LQService"
            android:exported="false" />

        <receiver
            android:name=".GeoReceiver"
            android:enabled="false"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.geoloqi.android.sdk.action.LOCATION_CHANGED" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.geoloqi.android.sdk.receiver.LQDeviceMessagingReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="com.pop.geoloqi" />
            </intent-filter>
        </receiver>

    </application>
</manifest>
4

1 回答 1

0

Geoloqi Android SDK 的早期版本中存在错误。如果您更新到最新版本,应该可以解决此问题。

于 2012-06-04T17:16:56.100 回答