android - 共享前必须调用 Urban Airship 起飞(仅限 kit kat)

标签 android urbanairship.com

我正在尝试学习如何使用 Urban Airship 发送推送通知,为此,我创建了一个使用它的非常简单的虚拟应用。

该应用有一个自定义自动驾驶仪和一个自定义通知工厂,以便测试某些功能。在 api 版本 >19 的 android 上一切正常。

但是,对于版本 19(我需要支持的最低版本)的设备,自动驾驶仪从未初始化,因此,每当我尝试访问 UAutopilot.shared()... 时,应用程序就会崩溃错误

takeoff must be called before shared

即使调用 Autopilot.autoTakeoff(application) 也无法解决问题。

主要 Activity :

public class MainActivity extends AppCompatActivity{

    TextView mTextView;
    Button mButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTextView = (TextView) findViewById(R.id.text);
        mButton = (Button)findViewById(R.id.button2);
        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTextView.setText(UAirship.shared().getPushManager().getChannelId());
            }
        });
    }
}

自定义自动驾驶仪:

class CustomAutopilot extends Autopilot {

@Override
public void onAirshipReady(UAirship airship) {
    Logger.info("onAirshipReady");
    airship.getPushManager().setUserNotificationsEnabled(true);
    airship.getPushManager().setNotificationFactory(new CustomNotificationFactory(UAirship.getApplicationContext()));
}

@Nullable
@Override
public AirshipConfigOptions createAirshipConfigOptions(@NonNull Context context) {
    Logger.info("setting airship config options");
    AirshipConfigOptions options = new AirshipConfigOptions.Builder()
            .setDevelopmentAppKey("xxxxxxxxxxx")
            .setDevelopmentAppSecret("xxxxxxxxxxx")
            .setDevelopmentLogLevel(Log.DEBUG)

            .setInProduction(false)

            .setGcmSender("232973289571")

            .setNotificationIcon(R.drawable.icon)
            .setNotificationAccentColor(Color.rgb(0, 72, 51))
            .build();
        return options;
    }
}

自定义通知工厂:

public class CustomNotificationFactory extends NotificationFactory {
    public CustomNotificationFactory(@NonNull Context context) {
        super(context);
    }

    @Nullable
    @Override
    public Notification createNotification(@NonNull PushMessage message, int notificationId) {
        NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(getContext())
                .setContentTitle("altered " + message.getTitle())
                .setContentText(message.getAlert())
                .setSmallIcon(message.getIcon(getContext(), R.drawable.icon))
                .setColor(Color.rgb(212, 45, 198))
                .setVibrate(new long[]{100, 50, 100, 200, 100, 50, 100})
                .setPriority(Notification.PRIORITY_MAX);

        return builder.build();

    }
}

最佳答案

您是否在 list 中注册自动驾驶仪?

在应用入口中:

    <!-- Autopilot calls takeOff without the need to override the Application -->
    <meta-data
        android:name="com.urbanairship.autopilot"
        android:value="your.package.here.CustomAutopilot"/>

关于android - 共享前必须调用 Urban Airship 起飞(仅限 kit kat),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44906715/

相关文章:

android - 如何保证我的操作栏选项卡在所有屏幕尺寸下始终可见?

ios - 为我的自定义 UIApplicationDelegate 绕过 UABaseAppDelegateSurrogate

ios - 交互式通知 UIMutableUserNotificationActionauthenticationRequired 在一台 iphone ios 8.4 上不起作用

java - Urban Airship jar 问题

android - 应用程序未针对 Google Play 上的 Alpha 测试人员进行更新

java - 错误 : Activity class {com. example.thejourney/com.example.thejourney.WelcomeActivity} 不存在

android - 间歇性对等未验证异常 : No peer certificate with Android client

ios - 如何使用 Urban AirShip (Swift) 获取 appDelegate

ios - Urban Airship 未在应用程序中显示警报

android - 我的应用程序可以在 android 2.2 和 android 2.3.3 模拟器上运行,但不能在我的手机 galaxy s android 2.3.5 上运行/阅读 facebook、twitter 联系人?