1

在我的Android應用程序中,我使用最新的Geoloqi API來實現Geofence concept.when用戶進入他通知的某個區域,爲此目的我使用Push Notifications.in GeoReceiver類三個回調方法正在調用,但不是onPushMessageReceived()。請幫我怎麼做? 我正在創建與當前位置的觸發器是否需要手動輸入到區域或由於我已經在它的位置沒有調用? 注:我已經給定的資產/ geoloqi.properties file.when應用在logcat中推出所需的憑據「已成功註冊了C2DM服務」味精也displayed.my代碼:爲什麼在Android的Geoloqi API中不會調用onPushMessageReceived()?

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> 
+0

如果你使用wifi,確保它沒有防火牆。簡單的檢查方法是看看gtalk是否能夠登錄你。並且請確保您使用安裝了市場應用的Android 2.2及更高版本的設備,並且正確配置了一個Gmail身份證。 – drulabs

+0

@KKD我查了wifi不firewalled.Device是Android 3.1市場應用程序與一個gmail id安裝。 –

+0

你能登錄到gtalk嗎?聯繫c2dm服務器後,服務器是否收到STATUS_OK消息? – drulabs

回答

相關問題