0

Basically I'm creating a small app which should record video when receiving a ping from another computer.

I have extended the Google Glass stopwatch example in order to create a basic live card. I removed ChronometerView.java and changed CountDownView.java so it does not count down but opens a ServerSocket and displays text once it receives a ping from another computer.

This all goes well, but now I want to start Glass' built-in camera activity from CountDownView.java once the signal is received. Simply inserting the below code does not work as (for as far as I understand) CountDownView.java does not extend activity.

Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent, TAKE_VIDEO_REQUEST);

So how do I start the camera activity at this point?

Sicco
  • 6,167
  • 5
  • 45
  • 61

1 Answers1

2

You need to start the activity from a context. Follow the steps below to test it first:

In StopwatchService.java, add:

private static StopwatchService mAppService;     

public static StopwatchService appService() {
    return mAppService;
}   

@Override
public void onCreate() {
    super.onCreate();
    mAppService = this;
}

In CountDownView.java, at the end of public CountDownView(Context context, AttributeSet attrs, int style) {...}, add:

mHandler.postDelayed(mLaunchVideoRunnable, 1000);

Also in CountDownView.java, add:

private final Handler mHandler = new Handler();  
private final Runnable mLaunchVideoRunnable = new Runnable() {
    @Override
    public void run() {
        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        StopwatchService.appService().startActivity(intent);
    }
}; 

Note that you need to add FLAG_ACTIVITY_NEW_TASK or your app would crash. After you test run this, you can copy the code to where you receive the socket data.

Jeff Tang
  • 1,804
  • 15
  • 16