Java Code Examples for android.app.Activity#openFileOutput()

The following examples show how to use android.app.Activity#openFileOutput() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerFragment.java    From AudioVideoPlayerSample with Apache License 2.0 6 votes vote down vote up
private final void prepareSampleMovie(File path) throws IOException {
	final Activity activity = getActivity();
	if (!path.exists()) {
		if (DEBUG) Log.i(TAG, "copy sample movie file from res/raw to app private storage");
		final BufferedInputStream in = new BufferedInputStream(activity.getResources().openRawResource(R.raw.easter_egg_nexus9_small));
		final BufferedOutputStream out = new BufferedOutputStream(activity.openFileOutput(path.getName(), Context.MODE_PRIVATE));
		byte[] buf = new byte[8192];
		int size = in.read(buf);
		while (size > 0) {
			out.write(buf, 0, size);
			size = in.read(buf);
		}
		in.close();
		out.flush();
		out.close();
	}
}
 
Example 2
Source File: FileIO.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Write the data to the file indicate by fileName. The file is created if
 * it doesn't exists.
 */
public static void write(Activity activity, String data, String fileName) throws IOException {
    FileOutputStream fo = activity.openFileOutput(fileName, 0);
    BufferedWriter bf = new BufferedWriter(new FileWriter(fo.getFD()));
    bf.write(data);
    bf.flush();
    bf.close();
}
 
Example 3
Source File: SystemUtils.java    From CoolWeather with Apache License 2.0 5 votes vote down vote up
/**
 * @author htq_
 * @param mActivity
 * bolg:www.csdn.net/htq__
 */
public static void shareApp(Activity mActivity)
{
     String shareAppContent="各位亲爱的小伙伴们,我发现了一款简约好用且颜值爆表的天气APP酷我天气,分享给大家,记得关注作者的博客http://blog.csdn.net/htq__,福利多多哦!";
   
     new File(mActivity.getFilesDir(), "share.png").deleteOnExit();
	FileOutputStream fileOutputStream=null;
	try {
		fileOutputStream = mActivity.openFileOutput(
				"share.png", 1);
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    
	  Bitmap pic=BitmapFactory.decodeResource(mActivity.getResources(),com.htq.coolweather.R.drawable.cool_weather_icon);
	  pic.compress(CompressFormat.JPEG, 100,fileOutputStream);
	  
     
       Intent intent = new Intent("android.intent.action.SEND");
	intent.setType("image/*");
	intent.putExtra("sms_body", shareAppContent);
	intent.putExtra("android.intent.extra.TEXT",shareAppContent);
	intent.putExtra("android.intent.extra.STREAM",
			Uri.fromFile(new File(mActivity.getFilesDir(), "share.png")));
	intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	mActivity.startActivity(Intent.createChooser(intent,"好东西要与小伙伴们一起分享"));
}