【发布时间】:2016-07-07 20:16:57
【问题描述】:
我正在开发一个跟踪 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 获取坐标的次数。
这里的问题是我不知道如何获取广播事件的应用名称。
有什么办法吗?
谢谢大家。
【问题讨论】:
标签: android android-intent android-broadcast android-gps