0

我有一个 Flash 游戏,我已经使用 AIR3.2 for Android 将它移植到了 Android,我已经创建了 .apk 并安装到了我的平板电脑上,并且可以正常运行。

现在我使用 Eclipse 创建了另一个 Android 应用程序;爪哇;我想从我的这个应用程序中打开我上面的游戏..

我经历了一些例子,但它对我不起作用。移植到AIR for Android后生成的xml文件如下:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<application xmlns="http://ns.adobe.com/air/application/3.2">
  <id>com.animals.AnimalGame</id>
  <versionNumber>1.0.0</versionNumber>
  <versionLabel>Animal Game</versionLabel>
  <filename>Animal Game</filename>
  <description/>
  <!-- To localize the description, use the following format for the description element.<description><text xml:lang="en">English App description goes here</text><text xml:lang="fr">French App description goes here</text><text xml:lang="ja">Japanese App description goes here</text></description>-->
  <name>Animal Game</name>
  <!-- To localize the name, use the following format for the name element.<name><text xml:lang="en">English App name goes here</text><text xml:lang="fr">French App name goes here</text><text xml:lang="ja">Japanese App name goes here</text></name>-->
  <copyright/>
  <initialWindow>
    <content>AndroidGameLoader.swf</content>
    <systemChrome>standard</systemChrome>
    <transparent>false</transparent>
    <visible>true</visible>
    <fullScreen>true</fullScreen>
    <aspectRatio>landscape</aspectRatio>
    <renderMode>gpu</renderMode>
    <autoOrients>false</autoOrients></initialWindow>
  <icon>
    <image36x36>36X36.png</image36x36>
    <image48x48>48X48.png</image48x48>
    <image72x72>72X72.png</image72x72>
  </icon>
  <customUpdateUI>false</customUpdateUI>
  <allowBrowserInvocation>false</allowBrowserInvocation>
  <android>
    <manifestAdditions>
      <![CDATA[<manifest>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>]]>
    </manifestAdditions>
  </android>
  <supportedLanguages>en</supportedLanguages>
</application>

我尝试在我的 Android 应用程序中按如下方式启动游戏:
HomeActivity.Java

package com.sush.myApp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class HomeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        Button btn1 =(Button)findViewById(R.id.button1);
        btn1.setOnClickListener(new OnClickListener()
        {
            public void onClick(View v)
              {
                try
                {
                    Intent i = new Intent(Intent.ACTION_MAIN);
                    PackageManager manager = getPackageManager();
                    i = manager.getLaunchIntentForPackage("com.animals.AnimalGame");
                    i.addCategory(Intent.CATEGORY_LAUNCHER);
                    startActivity(i);
                }catch(Exception e)
                {
                    e.printStackTrace();
                    Toast.makeText(v.getContext(), "Game Not Found", Toast.LENGTH_LONG).show();
                }

              }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }

}

但它没有用它总是去捕获声明。任何人都可以帮我解决如何从 Android 应用程序打开 Air for Android 应用程序...我还需要在游戏的 xml 文件中包含其他内容吗?

错误:

11-07 10:15:38.581: W/System.err(2140): java.lang.NullPointerException
11-07 10:15:38.732: W/System.err(2140):     at com.sush.myApp.HomeActivity$1.onClick(HomeActivity.java:47)
11-07 10:15:38.732: W/System.err(2140):     at android.view.View.performClick(View.java:4240)
11-07 10:15:38.742: W/System.err(2140):     at android.view.View$PerformClick.run(View.java:17721)
11-07 10:15:38.742: W/System.err(2140):     at android.os.Handler.handleCallback(Handler.java:730)
11-07 10:15:38.762: W/System.err(2140):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-07 10:15:38.792: W/System.err(2140):     at android.os.Looper.loop(Looper.java:137)
11-07 10:15:38.832: W/System.err(2140):     at android.app.ActivityThread.main(ActivityThread.java:5103)
11-07 10:15:38.863: W/System.err(2140):     at java.lang.reflect.Method.invokeNative(Native Method)
11-07 10:15:38.871: W/System.err(2140):     at java.lang.reflect.Method.invoke(Method.java:525)
11-07 10:15:38.881: W/System.err(2140):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-07 10:15:38.912: W/System.err(2140):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-07 10:15:38.912: W/System.err(2140):     at dalvik.system.NativeStart.main(Native Method)
11-07 10:15:39.051: D/dalvikvm(2140): GC_FOR_ALLOC freed 116K, 8% free 2881K/3104K, paused 74ms, total 103ms
4

1 回答 1

0

我已经解决了我的问题,现在我可以从我的 Android 应用程序打开 AIR for Android 应用程序。我刚变

i = manager.getLaunchIntentForPackage("com.animals.AnimalGame");

i = manager.getLaunchIntentForPackage("air.com.animals.AnimalGame");

现在它工作正常..

于 2013-11-13T06:59:34.973 回答