Notification wordpress => Android Studio ( ça marche, Mais !! )
Ilyass2020
Messages postés
8
Date d'inscription
Statut
Membre
Dernière intervention
-
BunoCS Messages postés 15952 Date d'inscription Statut Modérateur Dernière intervention -
BunoCS Messages postés 15952 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour
j arriver a configurer mon projet webview avec onesignale et mes notification wordpress s'ouvrent avec Succès sur mon appli , mais le problème quand je publie une article sur mon site, la notification reçu s'ouvre sur la page accueil de mon application, pas sur l'article elle meme.
voila mon code MainActivity
le "onesignal-mobile-support.php" dans mon " wp-content/mu-plugins"
j arriver a configurer mon projet webview avec onesignale et mes notification wordpress s'ouvrent avec Succès sur mon appli , mais le problème quand je publie une article sur mon site, la notification reçu s'ouvre sur la page accueil de mon application, pas sur l'article elle meme.
voila mon code MainActivity
public class MainActivity extends AppCompatActivity { WebView webView; ProgressBar progressBar; RelativeLayout relativeLayout; Button btnNoInternetConnection; @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // remove title requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); OneSignal.startInit(this) .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification) .unsubscribeWhenNotificationsAreDisabled(true) .setNotificationReceivedHandler(new ExampleNotificationReceivedHandler()) .init(); webView = (WebView) findViewById(R.id.webView); progressBar = (ProgressBar) findViewById(R.id.progressBar ); // loadUrl webView.setWebChromeClient( new MyChrome() ); progressBar.setVisibility(View.VISIBLE); //apel telephone hort app webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith("tel:")) { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); startActivity(intent); return true; } return false; } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); progressBar.setVisibility(View.GONE); } }); //no conection btnNoInternetConnection = (Button) findViewById(R.id.btnNoConnection); relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout); checkConnection(); // websettings WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); // webSettings.setDomStorageEnabled(true); // webSettings.setUseWideViewPort(true); webSettings.setAllowContentAccess(true); webSettings.setAllowFileAccess(true); webSettings.setAppCacheEnabled(true); // pivote ecran phone et video if (savedInstanceState!=null){ webView.post( new Runnable() { @Override public void run() { checkConnection(); } }); } //button no internet btnNoInternetConnection.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { checkConnection(); } }); } // plein écran video private class MyChrome extends WebChromeClient { private View mCustomView; private CustomViewCallback mCustomViewCallback; protected FrameLayout mFullscreenContainer; private int mOriginalOrientation; private int mOriginalSystemUiVisibility; MyChrome() {} public Bitmap getDefaultVideoPoster() { if (mCustomView == null) { return null; } return BitmapFactory.decodeResource(getApplicationContext().getResources(), 2130837573); } public void onHideCustomView() { ((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomView); this.mCustomView = null; getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility); setRequestedOrientation(this.mOriginalOrientation); this.mCustomViewCallback.onCustomViewHidden(); this.mCustomViewCallback = null; } public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback) { if (this.mCustomView != null) { onHideCustomView(); return; } this.mCustomView = paramView; this.mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility(); this.mOriginalOrientation = getRequestedOrientation(); this.mCustomViewCallback = paramCustomViewCallback; ((FrameLayout)getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1)); getWindow().getDecorView().setSystemUiVisibility(3846); } } class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler { // This fires when a notification is opened by tapping on it. @Override public void notificationOpened(OSNotificationOpenResult result) { OSNotificationAction.ActionType actionType = result.action.type; JSONObject data = result.notification.payload.additionalData; String customKey; Log.i("OSNotificationPayload", "result.notification.payload.toJSONObject().toString(): " + result.notification.payload.toJSONObject().toString()); if (data != null) { customKey = data.optString("customkey", null); if (customKey != null) Log.i("OneSignalExample", "customkey set with value: " + customKey); } if (actionType == OSNotificationAction.ActionType.ActionTaken) Log.i("OneSignalExample", "Button pressed with id: " + result.action.actionID); // The following can be used to open an Activity of your choice. // Replace - getApplicationContext() - with any Android Context. // Intent intent = new Intent(getApplicationContext(), YourActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); // startActivity(intent); // Add the following to your AndroidManifest.xml to prevent the launching of your main Activity // if you are calling startActivity above. } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()){ webView.goBack(); return true; } return super.onKeyDown(keyCode, event); } // pivote ecran phone et video @Override public void onConfigurationChanged(Configuration newConfig){ super.onConfigurationChanged( newConfig ); } @Override protected void onSaveInstanceState(Bundle outState ){ super.onSaveInstanceState( outState ); webView.saveState( outState ); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState){ super.onRestoreInstanceState( savedInstanceState ); webView.restoreState( savedInstanceState ); } // no conection message public void checkConnection(){ ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); assert connectivityManager != null; NetworkInfo wifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobileNetwork = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); assert wifi != null; if (wifi.isConnected()){ webView.loadUrl("https://www.groupe-alakssa.ma/"); webView.setVisibility(View.VISIBLE); relativeLayout.setVisibility(View.GONE); } else { assert mobileNetwork != null; if (mobileNetwork.isConnected()){ webView.loadUrl("https://www.groupe-alakssa.ma/"); webView.setVisibility(View.VISIBLE); relativeLayout.setVisibility(View.GONE); } else { webView.setVisibility(View.GONE); relativeLayout.setVisibility(View.VISIBLE); } } } }
le "onesignal-mobile-support.php" dans mon " wp-content/mu-plugins"
<?php add_filter('onesignal_send_notification', 'onesignal_send_notification_filter', 10, 4); function onesignal_send_notification_filter($fields, $new_status, $old_status, $post) { /* Goal: We don't want to modify the original $fields array, because we want the original web push notification to go out unmodified. However, we want to send an additional notification to Android and iOS devices with an additionalData property. * */ $fields_dup = $fields; $fields_dup['isAndroid'] = true; $fields_dup['isIos'] = true; $fields_dup['isAnyWeb'] = true; $fields_dup['isWP'] = false; $fields_dup['isAdm'] = false; $fields_dup['isChrome'] = false; // $fields_dup['android_channel_id'] = "<CHANNEL ID UUID HERE>"; $fields_dup['data'] = array("myappurl" => $fields['url']); /* Important to set web_url to support opening through both mobile and browser*/ $fields_dup['web_url'] = $fields_dup['url']; /* Important to unset the URL to prevent opening the browser when the notification is clicked for mobile app users */ unset($fields_dup['url']); $onesignal_post_url = "https://onesignal.com/api/v1/notifications"; /* Hopefully OneSignal::get_onesignal_settings(); can be called outside of the plugin */ $onesignal_wp_settings = OneSignal::get_onesignal_settings(); $onesignal_auth_key = $onesignal_wp_settings['app_rest_api_key']; $request = array("headers" => array("content-type" => "application/json;charset=utf-8", "Authorization" => "Basic " . $onesignal_auth_key), "body" => json_encode($fields_dup), "timeout" => 60); $response = wp_remote_post($onesignal_post_url, $request); if (is_wp_error($response) || !is_array($response) || !isset($response['body'])) { $status = $response->get_error_code(); $error_message = $response->get_error_message(); error_log("There was a " . $status . " error returned from OneSignal when sending to mobile users: " . $error_message); return; } return $fields; }
A voir également:
- Notification wordpress => Android Studio ( ça marche, Mais !! )
- Android recovery - Guide
- Historique notification android - Guide
- Notification visite profil facebook - Guide
- Son notification par application android - Guide
- Telecharger fl studio 20 pour pc gratuit complet - Télécharger - Édition & Montage