如何从我的Android应用程序打开AIR3.2 For Android(.apk)应用程序

时间:2013-11-12 07:37:48

标签: java android eclipse air

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

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

我做了一些例子,但它对我不起作用。 移植到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

1 个答案:

答案 0 :(得分:0)

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

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

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

现在工作正常..