1

我正在构建一个空中扩展,调用扩展的第一个方法是检查是否

GCMRegistrar.checkDevice($context.getActivity());
GCMRegistrar.checkManifest($context.getActivity());

支持和设置,所以写道:CheckGcm.java

package com.doitflash.air.extensions.gcm;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREInvalidObjectException;
import com.adobe.fre.FREObject;
import com.adobe.fre.FRETypeMismatchException;
import com.adobe.fre.FREWrongThreadException;

import com.google.android.gcm.GCMConstants;
import com.google.android.gcm.GCMRegistrar;

public class CheckGcm implements FREFunction 
{
    private String _result;

    public FREObject call(FREContext $context, FREObject[] $params) 
    {
            //$context.dispatchStatusEventAsync("variable", "value");

            try 
            {
            GCMRegistrar.checkDevice($context.getActivity());
            GCMRegistrar.checkManifest($context.getActivity());

            _result = "true";
        }
        catch(Exception err)
        {
            _result = "false";
        }

        return as3ConvertValue(_result);
    }

    private FREObject as3ConvertValue(String $value)
    {
        try 
        {
            return FREObject.newObject($value);
        } 
        catch (FREWrongThreadException e) 
        {
            return null;
        }
    }

}

我像这样设置android清单:

<manifestAdditions><![CDATA[<manifest android:installLocation="auto">

<permission android:name="air.air.com.doitflash.SampleApp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="air.air.com.doitflash.SampleApp.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application>

    <activity>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver 
        android:enabled="true" 
        android:exported="true"
        android:name="com.google.android.gcm.GCMBroadcastReceiver" 
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="air.air.com.doitflash.SampleApp" />
        </intent-filter>
    </receiver>

    <service 
        android:enabled="true" 
        android:exported="true" 
        android:name="com.doitflash.air.extensions.gcm.GCMIntentService" />

</application>
</manifest>]]></manifestAdditions>

我还设置了 GCMIntentService:

package com.doitflash.air.extensions.gcm;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gcm.GCMBaseIntentService;

public class GCMIntentService extends GCMBaseIntentService 
{
    private static final String TAG = "===GCMIntentService===";

    public GCMIntentService()
    {
        super("000000"); // senderID
    }

    @Override
    protected void onRegistered(Context arg0, String registrationId) 
    {

    }

    @Override
    protected void onUnregistered(Context arg0, String arg1)
    {

    }

    @Override
    protected void onMessage(Context arg0, Intent arg1) 
    {
        //Log.i(TAG, "notification title = " +  arg1.getStringExtra("title"));
        //Log.i(TAG, "notification message = " +  arg1.getStringExtra("msg"));
        //Log.i(TAG, "notification type = " +  arg1.getStringExtra("type"));
        //Log.i(TAG, "notification id= " +  arg1.getStringExtra("id"));

    }

    @Override
    protected void onError(Context arg0, String errorId) 
    {

    }

    @Override
    protected boolean onRecoverableError(Context context, String errorId)
    {
        return super.onRecoverableError(context, errorId);
    }
}

在我看来一切都很好,但是当我尝试在我的 air 项目中跟踪 check 方法时,它返回 null!所以我知道一定有问题:

GCMRegistrar.checkDevice($context.getActivity());
GCMRegistrar.checkManifest($context.getActivity());

因为当我删除这两行时,空气中的痕迹返回真。就在开始构建 air 扩展之前,我在 java 中构建了一个示例 GCM,一切正常,但我似乎不明白为什么 air 版本不起作用。有任何想法吗?

更新:我使用 eclipse logcat 查看手机上发生了什么,这可能是一些提示:

Could not find method com.google.android.gcm.GCMRegistrar.checkDevice, referenced from method com.doitflash.air.extensions.gcm.CheckGcm.call
unable to resolve static method 284: Lcom/google/android/gcm/GCMRegistrar;.checkDevice (Landroid/content/Context;)V
4

0 回答 0