Just about have native Android extension working.
Hey,
I've been following GoToAndLearn's Android Native Extension tutorial. After a couple hours of mucking with batch scripts I finally converted over his build script to windows and got my .ane and .apk.
However, when I load up my apk on my device, there's no indication that the extension is actually loaded.
Here's some of my code:
extension.xml
<extension xmlns="http://ns.adobe.com/air/extension/2.5">
<id>com.revstudios.dota2stream</id>
<versionNumber>1</versionNumber>
<platforms>
<platform name="Android-ARM">
<applicationDeployment>
<nativeLibrary>dota2stream.jar</nativeLibrary>
<initializer>com.revstudios.dota2stream.Dota2StreamExtension</initializer>
<finalizer>com.revstudios.dota2stream.Dota2StreamExtension</finalizer>
</applicationDeployment>
</platform>
</platforms>
</extension>
my Actionscript interface library:
package
{
import flash.external.ExtensionContext;
public class Dota2StreamInterface
{
private var context:ExtensionContext;
public function Dota2StreamInterface()
{
if(!context)
context = ExtensionContext.createExtensionContext("com.revstudios.dota2stream", null);
}
public function nofity(message:String):void{
context.call("notify", message);
}
}
}
Here's my view:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
<fx:Script>
<![CDATA[
protected function showIt(event:MouseEvent):void
{
var ni:Dota2StreamInterface = new Dota2StreamInterface();
ni.nofity(ti.text);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:TextInput id="ti" left="20" right="20" top="10"/>
<s:Button y="162" left="20" right="20" label="Button" click="showIt(event)"/>
</s:View>
Here's my app descriptor extension element:
<extensions>
<extensionID>com.revstudios.dota2stream</extensionID>
</extensions>
Here's my android Java (imports excluded for space):
package com.revstudios.dota2stream;
public class Dota2StreamContext extends FREContext {
@Override
public void dispose() {
}
@Override
public Map<String, FREFunction> getFunctions() {
Map<String, FREFunction> map = new HashMap<String, FREFunction>();
map.put("notify", new Dota2StreamFunction());
return map;
}
}
package com.revstudios.dota2stream;
public class Dota2StreamExtension implements FREExtension {
@Override
public FREContext createContext(String arg0) {
return new Dota2StreamContext();
}
@Override
public void dispose() {
}
@Override
public void initialize() {
}
}
package com.revstudios.dota2stream;
public class Dota2StreamFunction implements FREFunction {
@Override
public FREObject call(FREContext context, FREObject[] args) {
String message = "";
try {
message = args[0].getAsString();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FRETypeMismatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FREInvalidObjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FREWrongThreadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.w("WHEEEEE", "WHEEEEE");
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getActivity().getSystemService(ns);
long when = System.currentTimeMillis();
Notification notification = new Notification(context.getResourceId("drawable.notify"), message, when);
notification.defaults |= Notification.DEFAULT_SOUND;
CharSequence contentTitle = "Notification from Flash";
CharSequence contentText = message;
Intent notificationIntent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(context.getActivity(), 0, notificationIntent, 0);
notification.setLatestEventInfo(context.getActivity(), contentTitle, contentText, contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
return null;
}
}
I think that's all of the relevant code. I figured that the .ane and .apk wouldn't build if something is wrong... but the extension doesn't do anything.
I wasn't sure if it was something in my code or not, but that's why I put the Log.w. But that's not displayed either.
Any help would be appreciated.
