2017-09-03 100 views
0

我有座標列表(30+對經度,緯度),我的任務是:發送GPS通知,到處

我應該創建其發送通知(在狀態欄),以一個Android應用程序用戶如果他/她在我的列表中包含的30個位置之一。通知部分已準備就緒,我可以在一個活動中做到這一點(遍歷列表,如果座標相同,然後發送通知,但我怎麼能做到這一點所有活動,以及應用程序在緩存中的時間,但不開?謝謝

  Intent intent = new Intent(AGPS.this, SecondClass.class); 

      TaskStackBuilder stackBuilder = TaskStackBuilder.create(AnotherGPS.this); 
      stackBuilder.addParentStack(SecondClass.class); 
      stackBuilder.addNextIntent(intent); 
      PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent 
        .FLAG_UPDATE_CURRENT); 

      NotificationCompat.Builder mBuilder = 
        (NotificationCompat.Builder) new NotificationCompat.Builder(AnotherGPS.this) 
          .setSmallIcon(R.drawable.cam_icon) 
          .setContentTitle("My notification") 
          .setContentText("content of notification") 
          .setContentIntent(pendingIntent); 
      NotificationManager NM = (NotificationManager) getSystemService(Context 
        .NOTIFICATION_SERVICE); 
      NM.notify(0, mBuilder.build()); 

回答

0

如果您正在構建下面api26您可以使用後臺服務來監聽位置的變化,提供你的應用程序的權限和移動的位置上

開始API 26服務不會以這種方式工作,你很可能會得到一些例外,做後臺任務你必須通過這個https://developer.android.com/about/versions/oreo/android-8.0-changes.html#abll

+0

感謝您的快速答覆。我會檢查出來的! –