매니페스트 파일에 동기화 프로세스의 프로세스 이름을 확인하십시오 (내 경우는 "동기화")
<service
android:name=".sync.SyncService"
android:exported="true"
android:process=":sync">
<intent-filter>
<action android:name="android.content.SyncAdapter"/>
</intent-filter>
<meta-data android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
</service>
당신은 현재의 프로세스 이름을
public String getCurrentProcessName(Context context) {
// Log.d(TAG, "getCurrentProcessName");
int pid = android.os.Process.myPid();
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses())
{
// Log.d(TAG, processInfo.processName);
if (processInfo.pid == pid)
return processInfo.processName;
}
return "";
}
전화를 얻을 수있는 방법이 필요합니다 Application.onCreate의 위 코드는 현재 프로세스가 동기화되었는지 여부를 감지합니다.
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
String processName = Helper.getCurrentProcessName(this);
if (processName.endsWith(":sync")) {
Log.d(TAG, ":sync detected");
return;
}
}
}