gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:46:45 28 4
gpt4 key购买 nike

我正在尝试学习如何使用 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com