Google 피트니스의 모든 데이터 포인트에는 연결된 데이터 소스가 있습니다. 데이터 소스 앱을 수집하거나 수집하는 앱 또는 기기를 식별하는 데이터를 변환하게 됩니다. 앱의 패키지 이름을 데이터 소스에 사용할 수 있음 인코더-디코더 모델을 생성합니다.
Google 피트니스를 사용하면 다음 작업을 할 수 있습니다.
- 인텐트를 호출하여 특정 앱과 연결된 데이터를 봅니다.
- 앱을 사용하여 데이터를 표시하는 인텐트를 수신합니다.
- 어떤 앱이 세션을 삽입했는지 확인합니다. 자세한 내용은 자세한 내용은 세션 작업을 참조하세요.
데이터 포인트를 삽입한 앱 확인
데이터 포인트를 삽입한 애플리케이션의 패키지 이름을 가져오려면 먼저
DataPoint.getOriginalDataSource
호출
데이터 소스를 가져온 다음
DataSource.getAppPackageName
메서드를 사용하여 축소하도록 요청합니다.
val dataPoint : DataPoint = ...
val dataSource = dataPoint.originalDataSource
val appPkgName = dataSource.appPackageName
DataPoint dataPoint = ...
DataSource dataSource = dataPoint.getOriginalDataSource();
String appPkgName = dataSource.getAppPackageName();
다른 앱에서 인텐트 수신
다른 건강 및 웰빙 앱의 인텐트를 수신하도록 앱을 등록하려면 다음 단계를 따르세요. 매니페스트에서 다음과 유사한 인텐트 필터를 선언합니다.
<intent-filter>
<action android:name="vnd.google.fitness.VIEW" />
<data android:mimeType="vnd.google.fitness.data_type/com.google.step_count.cumulative" />
<data android:mimeType="vnd.google.fitness.data_type/com.google.step_count.delta" />
</intent-filter>
앱이 Google 피트니스에서 수신하는 각 인텐트에는 한 가지 유형만 있으므로 단일 인텐트 필터에서 여러 MIME 유형을 필터링할 수 있습니다. 앱의 인텐트 필터는 앱이 지원하는 모든 데이터 유형을 포함해야 합니다. 커스텀 데이터 유형 등이 있습니다
피트니스 인텐트에는 다음과 같은 추가 항목이 포함됩니다.
vnd.google.gms.fitness.start_time
vnd.google.gms.fitness.end_time
vnd.google.gms.fitness.data_source
다음과 같이 이러한 추가 항목에서 데이터를 가져올 수 있습니다.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
val supportedType = DataType.getMimeType(DataType.TYPE_STEP_COUNT_DELTA)
if (Intent.ACTION_VIEW == intent.action && supportedType == intent.type) {
// Get the intent extras
val startTime = Fitness.getStartTime(intent, TimeUnit.MILLISECONDS);
val endTime = Fitness.getEndTime(intent, TimeUnit.MILLISECONDS)
val dataSource = DataSource.extract(intent)
}
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
String supportedType = DataType.getMimeType(DataType.TYPE_STEP_COUNT_DELTA);
if (Intent.ACTION_VIEW.equals(getIntent().getAction()) && supportedType.equals(getIntent().getType())
{
// Get the intent extras
long startTime = Fitness.getStartTime(getIntent(), TimeUnit.MILLISECONDS);
long endTime = Fitness.getEndTime(getIntent(), TimeUnit.MILLISECONDS);
DataSource dataSource = DataSource.extract(getIntent());
}
}
맞춤 데이터 유형의 MIME 유형을 가져오려면
MIME_TYPE_PREFIX
드림
상수:
val supportedType = DataType.MIME_TYPE_PREFIX + "com.company.customdatatype"
String supportedType = DataType.MIME_TYPE_PREFIX + "com.company.customdatatype";
데이터를 보기 위한 인텐트 호출
다른 앱에서 데이터를 보기 위한 인텐트를 호출하려면
HistoryApi.ViewIntentBuilder
드림
클래스:
// Inside your activity
val startTime = ...
val endTime = ...
val dataSource = ...
val dataType = ...
val fitIntent = HistoryApi.ViewIntentBuilder(this, dataType)
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.setDataSource(dataSource) // Optional if a specific data source is desired
.setPreferredApplication("com.example.app") // Optional if you'd like a
// specific app to handle the intent if that app is installed on the device
.build()
// Inside your activity
long startTime = ...
long endTime = ...
DataSource dataSource = ...
DataType dataType = ...
Intent fitIntent = new HistoryApi.ViewIntentBuilder(this, dataType)
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.setDataSource(dataSource) // Optional if a specific data source is desired
.setPreferredApplication("com.example.app") // Optional if you'd like a
// specific app to handle the intent if that app is installed on the device
.build();
인텐트 및 인텐트 사용 방법 자세히 알아보기 필터를 참조하세요.