If you want to write something:
File myFile = mCon.getDir("myFile", Activity.MODE_WORLD_WRITEABLE);
String path = myFile.getAbsolutePath();
File file = new File(path + "/config.txt");
String strContent = "my file save";
try
{
FileOutputStream fos = new FileOutputStream(file, false);
fos.write(strContent.getBytes());
fos.close();
}
catch(Exception e)
{
Log.e("klx", e.toString());
}
And how to read from file:
File myFile = mCon.getDir("myFile", Activity.MODE_WORLD_WRITEABLE);
String path = myFile.getAbsolutePath();
File file = new File(path + "/config.txt");
if (file.exists() == false)
{
// do something
}
try
{
FileInputStream fis = new FileInputStream(path + "/config.txt");
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(fis));
String str = bufferReader.readLine();
Log.d("klx", "klx " + str); // Now you have what you want.
fis.close();
}
catch(IOException e)
{
Log.e("klx", "e.toString());
}
Oct 22, 2013
Oct 17, 2013
[android] StringTokenizer
Same as in Java.
StringTokenizer stk = new StringTokenizer(strTest, "/");
while(stk.hasMoreElements())
{
System.out.println(stk.nextToken()); // or stk.nextElement().toString();
}
Oct 10, 2013
[android] How to bring app in background to foreground
First, you should get the list of active apps like this.
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasklist =am.getRunningTasks(10); // Number of tasks you want to get
List<RunningTaskInfo> tasklist =am.getRunningTasks(10); // Number of tasks you want to get
Then, you will have the active app list in tasklist.
moveTaskToFront () function will bring the app to foreground.
if(!tasks.isEmpty())
{
int nSize = tasklist.size();
for(int i = 0; i >= nSize; i++)
int nSize = tasklist.size();
for(int i = 0; i >= nSize; i++)
{
RunningTaskInfo taskinfo = tasklist.get(i);
if(taskinfo.topActivity.getPackageName().equals("name of the package"))
RunningTaskInfo taskinfo = tasklist.get(i);
if(taskinfo.topActivity.getPackageName().equals("name of the package"))
{
am.moveTaskToFront(taskinfo.id, 0);
}
}
}
Finally, add permissions to the manifest.
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
am.moveTaskToFront(taskinfo.id, 0);
}
}
}
Finally, add permissions to the manifest.
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
Oct 8, 2013
[android] How to hide action bar
If you create a project, action bar will be shown by default.
Anyway, you can hide or show action bar in the run time.
hide: getActionBar().hide();
show: getActionBar().show();
This might be better:
final ActionBar actionBar = getActionBar();
actionBar.hide();
Anyway, you can hide or show action bar in the run time.
hide: getActionBar().hide();
show: getActionBar().show();
This might be better:
final ActionBar actionBar = getActionBar();
actionBar.hide();
[Unity3d] How to access variables from other scripts
This is based on Unity 4.1. It might be different depending on Unity versions.
Suppose that you want to access aaa.js from bbb.js.
aaa.js
var nSource : int; // It doesn`t have to be static, but private is not allowed here.
bbb.js
var src : aaa;
function Start ()
{
{
src = FindObjectOfType(aaa);
}
Usage:
function customFunction()
{
var a = aaa.nSource;
}
[Unity3d] How to convert 3d coords to 2d GUI position
You can use WorldToScreenPoint function.
var screenPos : Vector3 = GameObject.FindWithTag("MainCamera").camera.WorldToScreenPoint( transform.position);
var screenPos : Vector3 = GameObject.FindWithTag("MainCamera").camera.WorldToScreenPoint( transform.position);
[Unity3d] C++ dll for iPhone and XBox 360
#if UNITY_IPHONE || UNITY_XBOX360
// On iOS and Xbox 360 plugins are statically linked into
// the executable, so we have to use __Internal as the
// library name.
[DllImport ("__Internal")]
#else
// Other platforms load plugins dynamically, so pass the name
// of the plugin's dynamic library.
[DllImport ("PluginName")]
#endif
iOS and X-Box use dll as a static library. So, you should use "__internal" when importing.
Subscribe to:
Posts (Atom)