gpt4 book ai didi

java - 推送通知不起作用 - Android

转载 作者:行者123 更新时间:2023-11-30 01:42:09 24 4
gpt4 key购买 nike

我正尝试在按钮单击事件上发送推送通知。但是不知道为什么,就是不行。它没有显示任何错误。任何人都可以在代码中找到任何错误吗?

public class Verify extends AppCompatActivity {

public static String TAG=Verify.class.getSimpleName();
NotificationCompat.Builder notification;
private static final int uniqueID=12345;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_verify);
notification=new NotificationCompat.Builder(this);
notification.setAutoCancel(true);
}

public void onVerify(View v)
{
this.defineNotification();
//other code follows
}

public void defineNotification()
{
notification.setContentTitle("Successfully Signed Up");
notification.setContentText("Hi, you just Signed Up as a Vendor");
notification.setWhen(System.currentTimeMillis());

Intent intent=new Intent(this,OtherActivity.class);
PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);

NotificationManager nm=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(uniqueID,notification.build());
//Log.i(TAG, "coming here in notification");
}

这是 Android list 代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sachinparashar.xyz">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SignUp"
android:label="SignUp"
android:theme="@style/AppTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Verify"
android:label="@string/title_activity_verify"
android:theme="@style/AppTheme"/>
<activity
android:name=".VendorDetails"
android:label="Vendor Details"
android:theme="@style/AppTheme"/>
<activity
android:name=".OrderTypes"
android:label="Orders"
android:theme="@style/AppTheme" />

</application>

最佳答案

改变这个:

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

用这个:

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

关于java - 推送通知不起作用 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34353604/

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