从Android App Widget和深层链接打开Unity App

时间:2018-04-22 02:41:59

标签: java android unity3d

我仍然在Android工作室和java工作,所以我还没有完全理解它是如何工作的(尝试学习时)。

我有一个从Unity 3D构建并导入Android Studios的应用程序。然后我添加了一个应用程序小部件。应用程序小部件运行正常,我已经能够更新它并且每天更新它而没有问题到目前为止。

我需要的下一件事是能够点击它并让它到应用程序中的某个位置。我知道这可以用深层链接类型的东西完成,我注意到UnityPlayerActivity有方法

@Override protected void onNewIntent(Intent intent)
{
    // To support deep linking, we need to make sure that the client can get access to
    // the last sent intent. The clients access this through a JNI api that allows them
    // to get the intent set on launch. To update that after launch we have to manually
    // replace the intent with the one caught here.
    setIntent(intent);
}

我不确定我是否或如何使用它。 (或者即使这是我需要使用的)。我也考虑过设置一个PlayerPref(我认为它们是我可以从我读过的内容中访问的SharedPrefs),或者甚至只是在应用程序打开时在其中一个Java文件中设置一个变量来读入。但我认为深层次的联系是最好的。

我知道我还想检测应用程序是否已经打开,我看到提到UnitySendMessage,我相信这是打电话给游戏对象。

我遇到的问题是我无法弄清楚如何挂钩我需要的所有东西来点击小部件。我能够使用以下代码打开应用程序

RemoteViews views = new RemoteViews(context.getPackageName(),
        R.layout.verse_of_the_day);

Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");

intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.setComponent(new ComponentName("com.company.app",
        UnityPlayerActivity.class.getName()));
PendingIntent pendingIntent = PendingIntent.getActivity(
        context, 0, intent, 0);

views.setOnClickPendingIntent(R.id.button2, pendingIntent);

这很有用,我可以点击小部件,应用程序确实打开了,但现在我需要它在点击小部件时打开某个部分,或者只是在点击图标时正常打开。

我很欣赏任何有关我需要改变的信息。

0 个答案:

没有答案