繁体   English   中英

推送通知不起作用-Android

[英]Push notification not working - Android

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

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清单代码:

<?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);

插入

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

采用

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM