GPS の使用状況を追跡するアプリを開発しています (GPS のオン/オフだけでなく、位置要求も)。
調査の結果、マニフェストで次のコードを使用してこれをアーカイブできることがわかりました。
<receiver android:name=".triggers.TriggerGPS">
<intent-filter>
<action android:name="android.location.GPS_ENABLED_CHANGE" />
</intent-filter>
</receiver>
アプリが GPS を要求するたびに、TriggerGPS クラスが呼び出されます。
public class TriggerGPS extends BroadcastReceiver {
Calendar c = Calendar.getInstance();
@Override
public void onReceive(Context context, Intent intent) {
String currentDatetime = c.get(Calendar.DAY_OF_MONTH) + "/" + c.get(Calendar.MONTH) + "/" +
c.get(Calendar.YEAR) + " " + c.get(Calendar.HOUR_OF_DAY) + ":" +
c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND);
Log.d("---------log--------", "Intent ( " + intent.getAction() + " ) GPS Status onReceive : " + currentDatetime);
}
}
しかし、私のアプリは、各アプリが GPS を使用しており、アプリが GPS を使用して 1 日あたりの座標を取得した回数を示すレポートを作成する必要があります。
ここでの問題は、イベントをブロードキャストしたアプリ名を取得する方法がわからないことです。
それを行う方法はありますか?
皆さん、ありがとうございました。