2016-07-29 8 views
2

カスタムプラグインに書かれています。これは、スティッキー通知プラグインイベントの処理にのみ使用できます。プッシュプラグインをインストールしたときのカスタムCordovaプラグインのスティッキー通知

ワーキングシナリオと問題は私が取得しています: -

  1. をデモcorodvaアプリケーションと機能にインストールすると、それは正常に動作し、カスタムプラグインによって作成されたアプリスティッキー通知を閉じた後のように正常に動作locak画面に表示され、通知バー。
  2. しかし、カスタムプラグインがすでにインストールされているデモアプリケーションにphonegap pushプラグインをインストールしようとすると、その後、スティッキー通知は通知バーからクリア/削除/消滅します。ユーザーがアプリケーションを閉じたとき。

私がPhonegap Push Pluginのソースコードを見ると、プラグインにNotifcationManger.cancelAll()が書かれています。

これはなぜ起こりませんか?

以下の私のスティッキー通知プラグインのコードを追加: -

public class StickyNotificationPlugin extends CordovaPlugin { 
private static final String START_NOTIFICATION = "START"; 
private static final String STOP_NOTIFICATION = "STOP"; 
private Notification myNotication; 
int intNotificationId = 11111; 
private NotificationManager manager; 
private SharedPreferences objSharedPreferences; 

@Override 
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 
    objSharedPreferences = this.cordova.getActivity().getSharedPreferences("My_Plugin_Prefs", Context.MODE_PRIVATE); 

    System.out.println("Final in Plugin Action==>" + action); 
    manager = (NotificationManager) this.cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE); 

    if (START_NOTIFICATION.equals(action)) { 
     SharedPreferences.Editor objEditor = objSharedPreferences.edit(); 
     objEditor.putString("plugin_url", args.getString(0)); 
     objEditor.putString("plugin_token", args.getString(1)); 
     objEditor.putString("plugin_user_id", args.getString(2)); 
     objEditor.putBoolean("plugin_status", true); 
     objEditor.commit(); 
     Notify(); 
    } else if (STOP_NOTIFICATION.equals(action)) { 
     SharedPreferences.Editor objEditor = objSharedPreferences.edit(); 
     objEditor.putString("plugin_url", ""); 
     objEditor.putString("plugin_token", ""); 
     objEditor.putString("plugin_user_id", ""); 
     objEditor.putBoolean("plugin_status", false); 
     objEditor.putLong("time", 0); 
     objEditor.commit(); 
     manager.cancel(intNotificationId); 
    } 
    return true; 
} 

private void Notify() { 
    Context objContext = this.cordova.getActivity(); 
    Intent objIntent = new Intent(objContext, ApiCallServeice.class); 
    PendingIntent pi = PendingIntent.getService(objContext, intNotificationId, objIntent, PendingIntent.FLAG_CANCEL_CURRENT); 
    RemoteViews objRemoteViews = new RemoteViews(objContext.getApplicationContext().getPackageName(), R.layout.sticky_notification); 
    objRemoteViews.setOnClickPendingIntent(R.id.btn_notification, pi); 

    Notification.Builder builder = new Notification.Builder(objContext); 
    builder.setAutoCancel(false); 
    builder.setSmallIcon(objContext.getApplicationInfo().icon); 
    objRemoteViews.setImageViewResource(R.id.img_icon, objContext.getApplicationInfo().icon); 
    builder.setOngoing(true); 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     builder.setVisibility(Notification.VISIBILITY_PUBLIC); 
    } 
    builder.setContent(objRemoteViews); 
    builder.build(); 

    myNotication = builder.getNotification(); 
    manager.notify(intNotificationId, myNotication); 
}} 
+0

「取得する」とは何ですか? – weston

+0

スティッキー通知が通知バーから消去/消滅/消え去る –

+0

一部のコードが表示されることがあります。 – weston

答えて

1

あなたの問題は、ホームボタンが押されたら、通知をキャンセルする2行を削除することによって解決される -

この2行が検出されましたonPause()メソッドのPushPlugin.javaファイルです。

final NotificationManager notificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE); 
notificationManager.cancelAll(); 
関連する問題