Context.MODE_WORLD_READABLE : Context « Core Class « Android






Context.MODE_WORLD_READABLE

     
/*
 * Copyright (C) 2009 Virgil Dobjanschi, Jeff Sharkey
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package ch.racic.android.linuxtag2009.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

class AppUtil {
    /**
     * Show a level
     * 
     * @param context The context
     * @param level The level
     */
    public static void showLevel( Context context, int level)
    {
        String filename= "gelaendeplan.png";
        File f = new File( context.getFilesDir() + "/" + filename);
        try {
            if( f.exists() == false) {
                InputStream is = context.getAssets().open( filename);
                FileOutputStream fos = context.openFileOutput( filename, Context.MODE_WORLD_READABLE);
                byte[] buffer = new byte[is.available()];
                is.read(buffer);
                // write the stream to file
                fos.write(buffer, 0, buffer.length);
                fos.close();
                is.close();
            }

            // Prepare the intent
            Intent intent = new Intent( Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(f), "image/png");
            context.startActivity(intent);
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
    }
}

   
    
    
    
    
  








Related examples in the same category

1.Returns whether the context is running on the android emulator.
2.check Internet for Context
3.add Link
4.performing common form field validation tasks
5.Reads all text from asset with specified path.
6.Context Delete File
7.Context Open file
8.Context.openFileOutput