gpt4 book ai didi

android - 待定 Intent 未启动

转载 作者:太空狗 更新时间:2023-10-29 14:30:40 27 4
gpt4 key购买 nike

我有一个创建通知的 Activity 。当我使用 AVD 模拟器(针对 Android 2.1 update 1)时,通知将启动 PendingIntent 就好了,但在实际设备(运行 Android 2.2.1)上根本不会启动。有什么基本的东西是我遗漏的吗?

最佳答案

您还没有发布任何代码。所以我正在分享对我有用的代码:

public static void notifyIcon(Context context){

NotificationManager notifier = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.your_app_notification, "", System.currentTimeMillis());

/**
*Setting these flags will stop clearing your icon
*from the status bar if the user does clear all
*notifications.
*/
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.custom_notification_layout);
notification.contentView = contentView;

//If you want to open any activity on the click of the icon.

Intent notificationIntent = new Intent(context, YourActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;

notification.setLatestEventInfo(context, "title", null, contentIntent);
notifier.notify(1, notification);

//To cancel the icon ...
notifier.cancel(1);

}

这里是 custom_notification_layout.xml

<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dp" >

</LinearLayout>

注意:如果您设置了上述标志,请不要忘记在适当的时候清除您的应用程序图标。

关于android - 待定 Intent 未启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7320603/

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