2017-09-14 81 views
-2

有沒有辦法組織自動通知推送沒有服務器部分的android?沒有服務器部分的自動推送通知

我在電腦上(不是在電話上)的服務,定期添加數據到谷歌文檔或谷歌光盤。 因此,我想推送通知的每個新信息。

對我來說這似乎是不可能的,但可能不是?

+0

使用FCM ........... –

+0

想象一下,我在計算機上的文件,我新的字符串添加到該文件,並希望自動推送通知與字符串訂閱手機。 FCM可能無法在您的服務(PC)中檢測到像這樣的 – Vadim

+1

這樣的新字符串,您需要調用FCM的Web API將推送通知發送到特定設備ID –

回答

0

你可以做的是在你的服務類中創建一個本地通知。所以一旦你更新了數據,你可以建立一個像這樣的新通知。

private void sendUpdateNotification() { 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 

    builder.setContentIntent(resultPendingItent) 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher)) 
      .setTicker(msg) 
      .setWhen(System.currentTimeMillis()) 
      .setAutoCancel(true) 
      .setContentTitle("My App") 
        .setContentText(msg); 
    notificationManager.notify(notifyID, builder.build()); 
} 
+0

所有數據操作都不會顯示在手機設備上。 – Vadim

+0

啊,好的。我會看看FCM。看看這裏https://firebase.google.com/docs/cloud-messaging/ –

+0

它適用於firebase和另一項服務(一個信號),但只能手動推送通知。 – Vadim