Android的:如何检查自己是否达到/接近我的目标? [英] Android: How to check that whether i reach/near my Destination?

查看:172
本文介绍了Android的:如何检查自己是否达到/接近我的目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发展,当你到达/目的地附近,接到通知像闹钟唤醒了你的应用程序。

这是任何方式,我是否连续检查用户的当前位置,当用户接近/到达目的地?

如果有可能比请给我品尝/教程,这样我可以很容易地实现它。

到现在为止,我实现低于code,表示通知。

 公共类ProximityReceiver扩展广播接收器{私有静态最终诠释ALARM_DURATION = 6000;
公共静态最后弦乐INTENT_NAME =com.xxx.xxx.intent.PROXIMITY;
私有静态最后长VIBRATION_PATTERN [];静态的 {
    长人[] =新长[6];
    [1] = 1000L;
    [2] = 500L;
    [3] = 1000L;
    [4] = 500L;
    [5] = 1000L;
    VIBRATION_PATTERN =人;
}@覆盖
公共无效的onReceive(上下文的背景下,意图意图){    MyMainApplication wakeappapplication =(MyMainApplication)上下文
            .getApplicationContext();    如果(wakeappapplication.getStatus()。等于(WakeAppStatus.STARTED)){
        wakeappapplication.setStatus(WakeAppStatus.APPROACHING);
        长L = 6000L + System.currentTimeMillis的();
        ((AlarmManager)context.getSystemService(报警))。setRepeating(0,
                升,6000L,wakeappapplication.getProximityPendingIntent());
    }    NotificationManager notificationmanager =(NotificationManager)上下文
            .getSystemService(通知);    notificationmanager.cancel(ProximityReceiver,0);    通知通知=新的通知(
            R.drawable.ic_stat_notify_wakeapp,
            context.getString(R.string.text_wake_title)
            System.currentTimeMillis的());    的PendingIntent的PendingIntent = PendingIntent.getActivity(上下文,0,
            新意图(上下文,MainWakeMeUpActivity.class),0);    notification.setLatestEventInfo(背景下,
            context.getString(R.string.text_wake_title)
            context.getString(R.string.text_wake_descr)的PendingIntent);    android.net.Uri URI = wakeappapplication.getChosenRingtone();    如果(URI!= NULL)
        notification.sound = URI;    notification.vibrate = VIBRATION_PATTERN;    如果(wakeappapplication.isRaiseVolume())
        ((AudioManager)context.getSystemService(音频))。adjustVolume(1,
                0);    notificationmanager.notify(ProximityReceiver,0,通知);
}}


解决方案

您应该创建一个地理围栏,并把它添加到谷歌定位服务,当用户在一个特定的地理围栏进入或退出它,它会通知您(回调)。

遵循此:
http://developer.android.com/training/location/geofencing.html

I am developing an application that wakeup to you when you reach/near your destination and send you notification like Alarm.

Is it any way whether i check continuously user's current location and when user is near/reach destination?

If it is possible than please give me sample/tutorial so that i can implement it easily.

Till now,i implement below code that indicates "Notification".

public class ProximityReceiver extends BroadcastReceiver {

private static final int ALARM_DURATION = 6000;
public static final String INTENT_NAME = "com.xxx.xxx.intent.PROXIMITY";
private static final long VIBRATION_PATTERN[];

static {
    long al[] = new long[6];
    al[1] = 1000L;
    al[2] = 500L;
    al[3] = 1000L;
    al[4] = 500L;
    al[5] = 1000L;
    VIBRATION_PATTERN = al;
}

@Override
public void onReceive(Context context, Intent intent) {



    MyMainApplication wakeappapplication = (MyMainApplication) context
            .getApplicationContext();

    if (wakeappapplication.getStatus().equals(WakeAppStatus.STARTED)) {
        wakeappapplication.setStatus(WakeAppStatus.APPROACHING);
        long l = 6000L + System.currentTimeMillis();
        ((AlarmManager) context.getSystemService("alarm")).setRepeating(0,
                l, 6000L, wakeappapplication.getProximityPendingIntent());
    }

    NotificationManager notificationmanager = (NotificationManager) context
            .getSystemService("notification");

    notificationmanager.cancel("ProximityReceiver", 0);

    Notification notification = new Notification(
            R.drawable.ic_stat_notify_wakeapp,
            context.getString(R.string.text_wake_title),
            System.currentTimeMillis());

    PendingIntent pendingintent = PendingIntent.getActivity(context, 0,
            new Intent(context, MainWakeMeUpActivity.class), 0);

    notification.setLatestEventInfo(context,
            context.getString(R.string.text_wake_title),
            context.getString(R.string.text_wake_descr), pendingintent);

    android.net.Uri uri = wakeappapplication.getChosenRingtone();

    if (uri != null)
        notification.sound = uri;

    notification.vibrate = VIBRATION_PATTERN;

    if (wakeappapplication.isRaiseVolume())
        ((AudioManager) context.getSystemService("audio")).adjustVolume(1,
                0);

    notificationmanager.notify("ProximityReceiver", 0, notification);


}}

解决方案

You should create a geofence and add it to google location services it will notify you (callback) when a user enters in a particular geofence or exits it.

Follow this: http://developer.android.com/training/location/geofencing.html

这篇关于Android的:如何检查自己是否达到/接近我的目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆