2 * Copyright (C) 2010 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.android.wifi;
19 import java.util.Timer;
20 import java.util.TimerTask;
22 import com.google.zxing.client.android.R;
24 import android.app.Activity;
25 import android.app.AlertDialog;
26 import android.content.ActivityNotFoundException;
27 import android.content.Intent;
28 import android.net.Uri;
29 import android.os.Handler;
32 * Close the parent after a delay.
33 * @author Vikram Aggarwal
35 final class Killer implements Runnable {
38 private static final long DELAY_MS = 3 * 1000L;
40 private final Activity parent;
42 Killer(Activity parent) {
45 void launchIntent(Intent intent) {
47 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
49 parent.startActivity(intent);
50 } catch (ActivityNotFoundException e) {
51 AlertDialog.Builder builder = new AlertDialog.Builder(parent);
52 builder.setTitle(R.string.app_name);
53 builder.setMessage(R.string.msg_intent_failed);
54 builder.setPositiveButton(R.string.button_ok, null);
61 final Handler handler = new Handler();
62 Timer t = new Timer();
63 t.schedule(new TimerTask() {
66 handler.post(new Runnable() {
68 // This will kill the parent, a bad idea.
70 // This will start the browser, a better idea
71 launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/")));