We want to create a Unity application include App Widgets. But we can not find that sample.
App Widgets https://developer.android.com/guide/topics/appwidgets/index.html
We know how to make App Widgets in native apps. But We do not know how to include App Widgets in Unity application.
We have two questions.
First, I want to know how to retrieve the contents saved in Unity's PlayerPrefs from the Android side.
Second, how to include AppWidgets in the Unity application.
We tried the sample to show Toast. But I did not know how to include AppWidgets.
First, I want to know how to retrieve the contents saved in Unity's PlayerPrefs from the Android side.
"On Android data is stored (persisted) on the device. The data is saved in SharedPreferences. C#/JavaScript, Android Java and Native code can all access the PlayerPrefs data. The PlayerPrefs data is physically stored in /data/data/pkg-name/shared_prefs/pkg-name.xml." So guess you fetch it from there?
Source: https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
Second, how to include AppWidgets in the Unity application.
I believe the solution in the link below might help you do that. Not entirely sure but I'd assess it will.
https://forum.unity.com/threads/using-unity-android-in-a-sub-view.98315/
※ Unity Version : 2018.2.17f1
Export Project
& Development Build
checked.gradle .idea build gradle...
import project (Gradle, Eclipse ADT, etc.)
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
}
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.