I am writing a native Android extension for a mobile AIR application. I am trying to get the device id, but the result always comes back as null. I can't figure out what I am doing wrong. Here is the native extension code (java):
import android.app.Activity;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.content.Context;
import android.content.SharedPreferences;
import android.telephony.TelephonyManager;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
import com.adobe.fre.FREWrongThreadException;
public class DeviceIdGetter extends Activity implements FREFunction {
@Override
public FREObject call(FREContext context, FREObject[] passedArgs) {
FREObject result = null;
TelephonyManager tManager = (TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
try
{
result = FREObject.newObject(tManager.getDeviceId());
}
catch (FREWrongThreadException fwte)
{
try
{
result = FREObject.newObject("error");
}
catch (FREWrongThreadException fwte2)
{
}
fwte.printStackTrace();
}
return result;
}
}
yimogod
Are you using sdk4.6?
The FREObject.newObject
returns an error no implementation found for native freobject
, this cause context get null
.
I think you have copied the FlashRuntimeExtensions.jar
file from sdks folder to your java project.
Try to add Adobe Flash Builder 4.x\sdks\4.xx\lib\android\FlashRuntimeExtensions.jar
into your jar path.
来源:https://stackoverflow.com/questions/9232859/air-native-android-extension-always-returning-null-device-id