1

私のAndroidアプリでは、最新のGeoloqi APIを使用してジオフェンスの概念を実装しています.ユーザーが通知した地域に入ったとき、その目的のためにプッシュ通知を使用しています.GeoReceiverクラスでは3つのコールバックメソッドが呼び出されていますが、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

以前のバージョンのGeoloqiAndroidSDKにはバグがありました。最新バージョンに更新すると、この問題は解決するはずです。

于 2012-06-04T17:16:56.100 に答える