0

MySqlサーバーを持つAndroidでアプリケーションを作成しています。ファイルにデータが存在する場合は通知が必要です(ユーザーは確認後にすべてを削除する作業をしています)。だから、私は1時間後に起動し、データがあるかどうかをチェックし、通知を送信し、それを閉じてから1時間後に再度アクティブにする、良いバックグラウンドワーカーが必要です。 1時間時間を変更することができます。私はダウンロードのためにAsyncTaskを使用します(避けられない)。私は、通知を送信し、AsyncTaskを使用するのが得意です。アプリケーションの通知をサーバーでチェックし、存在する場合は表示します。

私は少し怠惰なので、私の仕事を完了することを確認する前に実験をしていません。

サービスクラスを使用すると思われます。詳細な情報を提供してください。 Github Library私はGithubを初めて使用しているため、チュートリアル全体を教えてください。

は、ありがとうございました

ユアーズ謹んで、私は解決策を自分で見つけたので、他の新しいプログラマーを助けることにしました

答えて

0

インドの最年少のAndroidアプリケーション開発者

。ここでは、あなたの のAndroidManifest.xml

<receiver android:name=".AlarmReceiverLifeLog" > 
    </receiver> 

    <service android:name=".MyReciever" /> 
でこれを追加

AlarmReceiverLifeLog.java

public class AlarmReceiverLifeLog extends BroadcastReceiver { 

    private static final String TAG = "LL24"; 
    static Context context; 

    @Override 
    public void onReceive(Context context, Intent intent) { 

     Log.v(TAG, "Alarm for LifeLog..."); 

     Intent serviceIntent = new Intent(context,MyReciever.class); 
     context.startService(serviceIntent); 
    } 
} 

MyReciever.java

public class MyReciever extends Service { 

int mStartMode; 
IBinder mBinder; 
boolean mAllowRebind; 

@Override 
public void onCreate() { 

} 

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
    //Your Method to get Data from Server 
} 

@Override 
public IBinder onBind(Intent intent) { 
    return mBinder; 
} 

@Override 
public boolean onUnbind(Intent intent) { 
    return mAllowRebind; 
} 

@Override 
public void onRebind(Intent intent) { 

} 

@Override 
public void onDestroy() { 

} 
//method to show notification to be called when you finally decide that you have to notify the user 
public void showNotification(String title,String message){ 
    Log.d("Service","Going to show notification"); 
    NotificationCompat.Builder builder = 
      new NotificationCompat.Builder(this) 
        .setSmallIcon(R.drawable.app_icon) 
        .setContentTitle(title) 
        .setContentText(message); 



    Intent notificationIntent = new Intent(this, NavigationActivity.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 
      PendingIntent.FLAG_UPDATE_CURRENT); 
    builder.setContentIntent(contentIntent); 
    // Add as notification 
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    manager.notify(0, builder.build()); 
} 
} 

をIS-

レシーバの有効化

Intent ll24 = new Intent(this, AlarmReceiverLifeLog.class); 
    PendingIntent recurringLl24 = PendingIntent.getBroadcast(this, 0, ll24,  PendingIntent.FLAG_CANCEL_CURRENT); 
    AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
    alarms.setRepeating(AlarmManager.RTC_WAKEUP, 0, AlarmManager.INTERVAL_HALF_DAY, recurringLl24);//For waking it after each 12hrs. 
関連する問題