[1]安装java jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
[2]sdk安装详见:http://www.cnblogs.com/yjmyzz/p/4219829.html
[3]安装android studio IDE
[1]添加unity的class.jar文件,详见:http://www.narkii.com/club/thread-320335-1.html
[2]unity-classes Add To Library
[3]Android Studio 打Jar包见:http://blog.csdn.net/ta893115871/article/details/46955791/
[4]Jar包生成目录:
./mylibrary/build/intermediates/bundles/debug/classes.jar
[5]保存图片至android相册
java代码:
// 保存照片至相册
public static void savePng(final String fileName)
{
context = mainActivity.getApplicationContext();
mainActivity.runOnUiThread(new Runnable() {
public void run() {
Bitmap bitmap = BitmapFactory.decodeFile(Environment
.getExternalStorageDirectory()
+ "/Android/data/com.ztgame.snake/files/"
+ fileName
+ ".png");
File file = new File(Environment.getExternalStorageDirectory()
+ "/DCIM/Camera", fileName + ".jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
Log.w("cat", e.toString());
}
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
try {
fos.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.w("cat", e.toString());
}
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.w("cat", e.toString());
}
bitmap.recycle();//扫描保存的图片
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" +Environment.getExternalStorageDirectory()
+ "/DCIM/Camera/"+fileName + ".jpg")));
Toast.makeText(context, "照片已保存到相册", Toast.LENGTH_SHORT).show();
}
});
}
c#部分:
//先保存至本地目录
string name = "name";
string writePath = Application.persistentDataPath + "/" + name + ".png";
File.WriteAllBytes(writePath, b);
//调用原生代码复制到相册
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic("currentActivity");
jo.CallStatic("savePng", name);
[6]将文本复制到剪贴板
java部分:
// 向剪贴板中添加文本
public static void copyTextToClipboard(final String str) throws Exception {
context = mainActivity.getApplicationContext();
if (Looper.myLooper() == null){
Looper.prepare();
}
clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
ClipData textCd = ClipData.newPlainText("data", str);
clipboard.setPrimaryClip(textCd);
mainActivity.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(context, "链接已复制到剪贴板", Toast.LENGTH_SHORT).show();
}
});
}
c#部分:
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic("currentActivity");
jo.CallStatic("copyTextToClipboard", input);
[7]安装AndroidPlayer扩展即可导出
[1]Android工程包名要和unity设置中保持一致
[2]如果横竖屏不能在unity设置中满足需求,可以在代码中强制调整
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);