android – 听Chrome定制选项卡进度事件

我有一个使用Chrome自定义标签打开一些链接的应用程序,我需要在用户停留在Chrome上的每一秒都有事件,或者知道他在Chrome上呆了多少时间。对我而言,唯一的方法是使用服务。有可能不同吗?
创建YourBroadCastReceiver类,如下所示

public class YourBroadCastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("Called every 60 seconds","called");
    }

}

启动自定义选项卡后,成功创建将每60秒触发YourBroadCastReceiver的Alarm PendingIntent。

    // Retrieve a PendingIntent that will perform a broadcast

    Intent repeatingIntent = new Intent(context,
            YourBroadCastReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(
           context, _pendingIntentId, alarmIntent, 0);

    AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    // Set the alarm to start at 10:00 AM
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());

    manager.setRepeating(AlarmManager.RTC_WAKEUP,
            calendar.getTimeInMillis(), 60 * 1000, // repeat for every 60 seconds
            pendingIntent);

关闭您的自定义标签后,永远不会忘记取消您的PendingIntent

PendingIntent.getBroadcast(
       context, _pendingIntentId, alarmIntent, 0).cancel();
http://stackoverflow.com/questions/37548100/listen-chrome-custom-tab-progress-event

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:android – 听Chrome定制选项卡进度事件