I'm trying to figure out how to write apps for Android using Adobe Air. I've choosen Axel Framework (simple game engine based on Stage3D) and FlashDevelop as my tools. I wrote my first app which should display an image and some text on screen. When I run this app in desktop mode, it works. Unfortunately when I install it on Android emulator it displays only blank screen (with color specified in [SWF] tag). I really don't know what's wrong.
Addtional compile arguments: -swf-version=13
Target framework: AIR mobile 3.3
application.xml
<?xml version="1.0" encoding="utf-8"?>
<application xmlns="http://ns.adobe.com/air/application/3.0">
<id>air.TestAndroidAxl</id>
<versionNumber>0.1</versionNumber>
<supportedProfiles>mobileDevice</supportedProfiles>
<filename>TestAndroidAxl</filename>
<name>TestAndroid_Axl</name>
<android>
<manifestAdditions><![CDATA[<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:required="true"android:name="android.hardware.touchscreen.multitouch" />
</manifest>]]></manifestAdditions>
</android>
<initialWindow>
<title>TestAndroid_Axl</title>
<content>TestAndroidAxl.swf</content>
<visible>true</visible>
<fullScreen>false</fullScreen>
<!--<autoOrients>false</autoOrients>-->
<!--<aspectRatio>landscape</aspectRatio>-->
<renderMode>direct</renderMode>
<systemChrome>standard</systemChrome>
<aspectRatio>landscape</aspectRatio>
</initialWindow>
<icon>
<image48x48>icons/icon_48.png</image48x48>
<image57x57>icons/icon_57.png</image57x57>
<image72x72>icons/icon_72.png</image72x72>
<image114x114>icons/icon_114.png</image114x114>
<image512x512>icons/icon_512.png</image512x512>
</icon>
</application>
Main.as
import flash.desktop.NativeApplication;
import flash.events.Event;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
public class Main extends Sprite {
public function Main() : void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.DEACTIVATE, deactivate);
// touch or gesture?
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
// entry point
var game : AxlGame = new AxlGame();
addChild(game);
}
private function deactivate(e:Event) : void {
NativeApplication.nativeApplication.exit();
}
}
AxllGame.as
import org.axgl.Ax;
public class AxlGame extends Ax {
public function AxlGame() {
super(PlayState);
}
}
You might want to try it on emulator with GPU emulation. Here's how to set it up:
Add Android 4.0.3 (or later) image.
Edit the image. Next to “Hardware:”, Select “New…”
Add “GPU emulation”.
Set its value to “Yes”.
Related
This is the start of a simple app to initially display some TextViews and Buttons.
I want to avoid using layout managers by getting the dimensions of the main window/layout and using that to hard-code the components any way I want.
But my main Activity can't get non-zero data about the main window/layout.
I don't know if it's supposed to be this way or if I'm doing something dumb, and would appreciate some help.
This is a command line project using Ant under win10 and outputting to a USB'd phone.
I've updated the SDK Manager to Android 6.0 (API 23) with Android Tools 24.4.1 and installed v23.2 of the Android Support Lib, although Ant seems to think differently as you can see in my previous message which has the Ant output:
-build-setup:
[getbuildtools] Using latest Build Tools: 21.1.2.
I don't know if that makes a difference, but not in this case I think.
The next two files are complete as far as they go.
I would have included more but the way the website mangles my code doesn't encourage uploading to it.
It might have helped if I could have comprehended the 'How to Format' but (A) I didn't even see it before my first post and (B) I don't understand it now.
There are far too many instructions and too much jargon; e.g. what is a backtick?
Can't there be a simple format that will take everything you throw at it?
main.xml
========
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
package="com.Chatterton.Peter.ChessClock"
android:id="#+id/main_window"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="#+id/time_text_view_left"
android:text="top_left"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<Button
android:layout_alignParentBottom="true"
...
There are a total of 4 components, one per corner, with the same layout_width and height.
ChessClockActivity.java
=======================
package com.Chatterton.Peter.ChessClock;
import android.app.Activity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;
import android.graphics.Color;
import android.widget.TextView;
import android.util.Log;
public class ChessClockActivity extends Activity
{
public int winOriginX=10, winOriginY=20, winWidth=44, winHeight=66;
#Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout mainLayout = (RelativeLayout)findViewById( R.id.main_window );
int mainWidth = mainLayout.getWidth();
int mainHeight = mainLayout.getHeight();
Log.d( "clox", "mainLayout=" + mainLayout );
Log.d( "clox", "main W/H=" + mainWidth + "/" + mainWidth );
...
Screen Results:
It shows the last component displayed -- full-size -- with its text.
logcat results:
===============
D:\Android\ChessClock>adb shell
shell#android:/ $ logcat clox:D *:S
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
D/clox (27214): mainLayout=android.widget.RelativeLayout#41755b80
D/clox (27214): main W/H=0/0
**
They have no size at this point of the initialization process.
Click here to an answer that will let you access the sizes of your components after they have been displayed.
Or perhaps you can get the window size and figure the placement of your components by that value......
Answer here
i wanted to incororate a Leaflet Map into an ios and android air mobile application using the StageWebView class.
Unfortunately the quality of the map images is so jagged, that it is hard to make out the streetnames. There seems to be some minor scaling going on.
For test purposes i used the Leaflet tutorial mal at http://leafletjs.com/examples/quick-start-example.html
When viewed in the Android browser ( chrome ) the images look fine.
Here is some simple code to show the issue:
package {
import flash.display.MovieClip;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.desktop.NativeApplication;
import flash.utils.setTimeout;
public class Main extends MovieClip{
private var _stageWebView:StageWebView
public function Main()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
setTimeout( init, 100 );
}
private function init():void {
_stageWebView = new StageWebView();
_stageWebView.stage = this.stage;
_stageWebView.viewPort = new Rectangle( 0, 0, stage.stageHeight, stage.stageWidth );
_stageWebView.loadURL( "http://leafletjs.com/examples/quick-start-example.html" );
}
}
}
Any ideas? Does it have to do with a resolution problem maybe?
Thanks
The problem that you got is a rendering problem which you can avoid by enabling hardware acceleration (force GPU rendering) when it's supported of course.
Beginning in Android 3.0 (API level 11), the Android 2D rendering pipeline supports hardware acceleration, meaning that all drawing operations that are performed on a View's canvas use the GPU.
So to force GPU rendering, you can :
1 - Enable hardware acceleration in your application's manifest file, where you should set the android:hardwareAccelerated attribute of the application element to true :
<android>
<manifestAdditions>
<![CDATA[
<manifest>
<application android:hardwareAccelerated="true"/>
</manifest>
]]>
</manifestAdditions>
</android>
And this is an example of a full manifest file (my test browser-app.xml) :
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<application xmlns="http://ns.adobe.com/air/application/19.0">
<id>browser</id>
<versionNumber>1.0.0</versionNumber>
<versionLabel/>
<filename>browser</filename>
<description/>
<name>browser</name>
<copyright/>
<initialWindow>
<content>browser.swf</content>
<systemChrome>standard</systemChrome>
<transparent>false</transparent>
<visible>true</visible>
<fullScreen>false</fullScreen>
<renderMode>auto</renderMode>
<autoOrients>true</autoOrients>
</initialWindow>
<icon/>
<customUpdateUI>false</customUpdateUI>
<allowBrowserInvocation>false</allowBrowserInvocation>
<android>
<manifestAdditions>
<![CDATA[
<manifest>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:hardwareAccelerated="true"/>
</manifest>
]]>
</manifestAdditions>
</android>
</application>
then you have just to publish your AIR app, you will get something like this :
and you can see the result when I comment <application android:hardwareAccelerated="true"/> :
2 - You can also force GPU rendering from the Developer Options of your Android device :
and you can get the same result even when <application android:hardwareAccelerated="true"/> is commented :
That's all !
Hope that can help.
If you change it to use nativeMode new StageWebView(true) it solves the problem for me but the mouse/touch events don't work :/
I am integrating Fusion chart in my Flex 4.6 web application, it is working fine but when i try to use the same set of code in AIR it throws run time error as like below
VerifyError: Error #1014: Class mx.controls::Image could not be found.
at FusionChartSample/init()[D:\WorkspaceLocal\TabletSamples\FusionChartAppln\FusionChartSample.mxml:15]
at FusionChartSample/___FusionChartSample_Application1_creationComplete()[D:\WorkspaceLocal\TabletSamples\FusionChartAppln\FusionChartSample.mxml:4]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
at mx.core::UIComponent/set initialized()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:1818]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:842]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]
Here is my sample code working fine in Web application but not in AIR,
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:components="com.fusioncharts.components.*" xmlns="*" creationComplete="init()" >
<fx:Script>
<![CDATA[
import com.fusioncharts.components.*;
import spark.components.Button;
private var _fusionChart: FusionCharts;
private var sampleXml:XML;
private function init():void {
_fusionChart = new FusionCharts();
_fusionChart.FCChartType = "StackedColumn2D";
_fusionChart.FCDataXML = sampleXml;
_fusionChart.FCFolder = "../fusioncharts/";
_fusionChart.FCRender();
this.addElement(_fusionChart);
}
]]>
</fx:Script>
</s:Application>
If anyone comes across this problem, kindly provide me some idea. Thanks in advance.
The above code snippets has few problems. First ensure that you are not using Spark Only Component set. Set MX + Spark Component.
I am not sure why the above code snippet is showing "s:Application". If this is an AIR app it should be "s:WindowedApplication".
The attribute FCDataXML is pointing towards a string which is probably the name of the XML file. You need to specify the actual XML there.
I'm fairly new in the android developing scene, however I have done a few dead simple applications to get an understanding of what the workflow would be like in the environment.
I'm having a difficulty running the example program called SimpleXYPlotExample and here's the code, manifest, main.xml and activity.java, respectively. I know this is a user error of some sort, but it would be great if someone could give me some helpful pointers as to what I'm doing wrong.
At first, all the code was broken, but I realized i forgot to import the library in. Now that I have done so, I try to run the program on my nexus s and it just crashes as it enters it.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="6"
android:targetSdkVersion="16"/>
<application android:label="SimpleXYPlotExample"
android:icon="#drawable/icon"
android:debuggable="true"
android:hardwareAccelerated="false">
<activity android:name=".MyActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.androidplot.xy.XYPlot
android:id="#+id/mySimpleXYPlot"
android:layout_width="fill_parent"
android:layout_height="150px"
android:layout_marginTop="10px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
andsroidplot.title="A Simple XYPlot Example"
androidplot.ticksPerRangeLabel="4"
androidplot.ticksPerDomainLabel="2"
androidplot.gridPadding="4dp|4dp|4dp|4dp"
/>
</LinearLayout>
package com.example;
import java.util.Arrays;
import android.app.Activity;
import android.os.Bundle;
import com.androidplot.series.XYSeries;
import com.androidplot.ui.AnchorPosition;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XLayoutStyle;
import com.androidplot.xy.XYPlot;
import com.androidplot.xy.YLayoutStyle;
public class MyActivity extends Activity
{
private XYPlot plot;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// initialize our XYPlot reference:
plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
// add a new series
XYSeries mySeries = new SimpleXYSeries(
Arrays.asList(0, 25, 55, 2, 80, 30, 99, 0, 44, 6),
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "series1");
plot.addSeries(mySeries, new LineAndPointFormatter(
getApplicationContext(), R.xml.f1));
// reposition the domain label to look a little cleaner:
plot.position(plot.getDomainLabelWidget(), // the widget to position
45, // x position value, in this case 45 pixels
XLayoutStyle.ABSOLUTE_FROM_LEFT, // how the x position value is applied, in this case from the left
0, // y position value
YLayoutStyle.ABSOLUTE_FROM_BOTTOM, // how the y position is applied, in this case from the bottom
AnchorPosition.LEFT_BOTTOM); // point to use as the origin of the widget being positioned
plot.centerOnRangeOrigin(60);
plot.centerOnDomainOrigin(5);
}
}
This may be contributed by the fact that the plot doesn't even show up on the graphical layout. This is what it looks like with this code:
http://imgur.com/qYl96Zi
As you can see, I have imported the androidplot library. Please advise.
The screenshot appears to be from the eclipse gui editor, which as the exception mentions does not support the setShadowLayer method and thus will not render. That's just a limitation with Eclipse and not a bug in your code or the library.
Normally to be able to answer questions regarding why Androidplot is crashing you'd need to supply the corresponding stack trace. I did however notice this typo in your xml:
andsroidplot.title="A Simple XYPlot Example"
As far as getting a working WYSIWYG editor my personal suggestion would be to give either IntelliJ IDEA or Android Studio (built on the current EAP version IntelliJ IDEA) a try. Both are free and both are in (IMHO) far superior IDE's.
I'm new at this. Go easy.
My code so far looks like this.
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.hardware.Camera;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String fmode = "Not Supported";
Camera cam = Camera.open();
Camera.Parameters p = cam.getParameters();
if (p.getFlashMode() != null)
{fmode = p.getFlashMode();}
TextView tv = new TextView(this);
tv.setText(fmode);
setContentView(tv);
}
}
When I run the program, I get the message stating that The application has stopped unexpectedly. Please try again. If I comment out these four lines...
//Camera cam = Camera.open();
//Camera.Parameters p = cam.getParameters();
//if (p.getFlashMode() != null)
//{fmode = p.getFlashMode();}
then the code runs fine and I get the "Not Supported" message. Then if I uncomment the first line where I declare the Camera object, it crashes again.
Feel free to be verbose, I'm in learning mode and would like all the information I can get. Thanks in advance.
Any chance you missed adding the camera permission in your AndroidManifest?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<application ...>
.
.
.
</application>
</manifest>
If that's not the case:
Why does the android emulator camera stop unexpectedly?
I'm not very familiar using a camera in apps but I found you a great tutorial that can help you on your way towards your solution.
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html
I hope this is helpful for you and may you find what you need :) if not, I'll make a test app myself and help you further
And like someone else stated above, some permissions must be added to use the camera, you can find those here:
http://developer.android.com/reference/android/hardware/Camera.html
Permissions are needed to allow access to certain features in android. Did you put <uses-permission android:name="android.permission.CAMERA" /> in your android manifest to have access to the camera.