0

MySql 서버가있는 Android에서 애플리케이션을 만들고 있습니다. 파일에 데이터가있는 경우 알림이 필요합니다 (사용자는 확인 후이를 모두 제거해야합니다). 따라서 1 시간 후에 활성화되고, 데이터가 있는지 확인하고, 알림을 보내고, 닫고, 한 시간 후에 다시 활성화하는 훌륭한 백그라운드 작업자가 필요합니다. 1 시간 시간을 변경할 수 있습니다. 나는 (Unavoidable) 다운로드를 위해 AsyncTask를 사용한다. 나는 알림을 보내고 AsyncTask를 사용하는 것이 좋다.app에 대한 알림을 서버에서 확인하고 표시 할 경우 표시합니다.

나는 게으르다. 실험을 완료하기 전에 실험을하지 않았다.

서비스 클래스를 사용할 수 있다고 생각합니다. 자세한 정보를 입력하십시오. Github Library을 사용하려고 할 때 전체 튜토리얼을 제공하십시오. Github을 처음 사용하는 이유입니다.

, 감사합니다

너의 정중하게, 나는 해결책을 나 자신을 발견하고 그래서 다른 새로운 프로그래머를 도와하기로 결정

답변

0

인도의 젊은 안드로이드 응용 프로그램 개발자

. 여기가

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()); 
} 
} 

의 AndroidManifest.xml

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

    <service android:name=".MyReciever" /> 
을이 추가 - 이것도

수신자 활성화

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.