※ Unity Version : 2018.2.17f1
Pre-Task
- export Android build, with
Export Project & Development Build checked
- then you will get a folder contains
.gradle .idea build gradle...
( I gotta call this folder as Project Folder )
- open Android Studio and select
import project (Gradle, Eclipse ADT, etc.)
- in file explorer, you should pick up the Project Folder
1. How to retrieve Unity PlayerPrefs from Android side
you can find Project Folder/java/UnityPlayerActivity.java in project explorer on Android Studio. this class performs Unity application on Android side, thus you should write code for retrieving PlayerPrefs in here. example code is below:
public class UnityPlayerActivity extends Activity
{
protected SharedPreferences mPlayerPrefs = null;
@Override protected void onCreate(Bundle savedInstanceState)
{
// generated code
this.mPlayerPrefs = this.getSharedPreferences(this.getPackageName() + ".v2.playerprefs", Context.MODE_PRIVATE);
}
// generated code
}
rest of job is all about using SharedPreferences, not the PlayerPrefs. Yeap.
for example...
int a = this.mPlayerPrefs.getInt("key", -1);
if(a == -1)
{
Log.d("MyLog", "getInt(key) failed !");
}
else
{
// some code
}
2. How to include AppWidget in Unity Application
it is very simple. just in the state with your Project Folder open on Android Studio, select File -> New -> Widget -> App Widget and you will see Widget wizard. after the wizard, your Unity Application can be located in home screen as widget. rest of job is all about widget programming... ;D