2 * Copyright (C) 2012 OUYA, Inc.
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 de.cweiske.ouya.gamelauncher;
20 import java.io.FileOutputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.OutputStream;
25 import android.app.Activity;
26 import android.content.ComponentName;
27 import android.content.Intent;
28 import android.content.res.AssetManager;
29 import android.net.Uri;
30 import android.os.Bundle;
31 import android.os.Environment;
33 public class LaunchGameActivity extends Activity
35 String assetFilename = "FIXME_ASSETFILENAME";
38 * Called when the activity is first created.
41 public void onCreate(Bundle savedInstanceState)
43 super.onCreate(savedInstanceState);
45 File extractedFile = extractFile(this.assetFilename);
46 if (extractedFile == null) {
47 System.err.println("Failed to extract file " + this.assetFilename);
52 Intent intent = new Intent();
53 intent.setComponent(new ComponentName("com.explusalpha.Snes9xPlus", "com.imagine.BaseActivity"));
54 intent.setAction("android.intent.action.VIEW");
55 intent.setData(Uri.fromFile(extractedFile));
57 startActivity(intent);
62 protected File extractFile(String assetFilename)
64 //File cacheDir = this.getExternalCacheDir();
65 //File cacheDir = getExternalFilesDir(null);
66 File cacheDir = Environment.getExternalStorageDirectory();
67 if (cacheDir == null) {
79 File targetFile = new File(dir.toString() + File.separator + assetFilename);
80 if (targetFile.exists()) {
84 AssetManager assetManager = this.getAssets();
86 InputStream in = assetManager.open("game/" + assetFilename);
87 copyFile(in, new FileOutputStream(targetFile));
89 } catch (IOException e) {
95 protected void copyFile(InputStream in, OutputStream out) throws IOException
97 byte[] buffer = new byte[1024];
99 while((read = in.read(buffer)) != -1){
100 out.write(buffer, 0, read);