Comment faire pour que mon application WebView ouvre les notifications push d'UR
Ilyass2020
Messages postés
9
Statut
Membre
-
BunoCS Messages postés 16550 Date d'inscription Statut Modérateur Dernière intervention -
BunoCS Messages postés 16550 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour
j ai instaler le plugins Onesignal sur mon site web wordpress et j ai configurer mon projet android studio avec onesignal et firebase, tous va bien . mais lorsque j'envoie une notification push avec mon site wordpress à ouvrir dans l'application webview, elle s'ouvre à la place dans le navigateur.
Est-il possible d'ouvrir les notifications push d'URL dans l'application et non dans le navigateur?
voila mon code MainActivity.java
j ai instaler le plugins Onesignal sur mon site web wordpress et j ai configurer mon projet android studio avec onesignal et firebase, tous va bien . mais lorsque j'envoie une notification push avec mon site wordpress à ouvrir dans l'application webview, elle s'ouvre à la place dans le navigateur.
Est-il possible d'ouvrir les notifications push d'URL dans l'application et non dans le navigateur?
voila mon code MainActivity.java
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 Initialization
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.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 connexion
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);
}
}
@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);
}
}
}
}
A voir également:
- Comment faire pour que mon application WebView ouvre les notifications push d'UR
- Comment ouvrir un fichier epub ? - Guide
- Nommez une application d'appel vidéo ou de visioconférence - Guide
- Application pour voir qui regarde mon profil facebook gratuit - Guide
- Desinstaller application windows - Guide
- Comment supprimer une application préinstallée sur android - Guide
2 réponses
Hello,
Tu devrais trouver ton bonheur ici : https://developer.android.com/training/notify-user/navigation
Tu devrais trouver ton bonheur ici : https://developer.android.com/training/notify-user/navigation
Tu peux m aider plus s il vous plaît ? Je suis pzs très doué en java et je suis un peu perdu dans cette page, normalement cr spnt des notifications pour articles, si j envoi la notification depuit onesignal directement, il s ouvre dans mon appli webview, mais les notif wordpress mènent a crome. Merci pour vôtre aide BunoCS