Emre
Samsun
19/06/2017 tarihinden beri üye
10
GY Puanı
105K
GY Sırası
Kişisel Sayfaları
İlgi Alanları
1
Rozet
0
Sertifika
1
Soru Sordu
0
Cevap Verdi
0
Blog Yazısı
0
Etiket Takibi
İş Tecrubesi
Kullanıcıya ait İş tecrübesi bilgisi bulunmamaktadır.
Eğitim Geçmişi
Kullanıcıya ait Eğitim geçmişi bilgisi bulunmamaktadır.
Sertifikalar & Başarılar
GY Sertifikaları
(0)
Kullanıcının GY sertifikası bulunmamaktadır.
Diğer Sertifikaları
(0)
Kullanıcıya ait sertifika bulunmamaktadır.
Test Sonuçları
(0)
Kullanıcıya ait test sonucu bulunmamaktadır.
Dil Becerileri
Son Forum Aktiviteleri
1OneSignal ile Push Notification problemi
One signal ile bildirim gönderdiğimde bildirim çubuğuna bildirimim düşüyor. Ama uygulama tamamen kapalıyken tıkladığımda hiç bir şey açılmıyor. Uygulama arkaplanda açıkken veya önde açıkken gönderdiğim bildirime tıklayınca açılıyor. Openhandler ve receivedhandler kullandım webviewde acabilmek için.
Sanırım servis eklemem gerekiyor arkaplanda hazır bekletebilmek için ama nereye eklemem gerektiğini bulamadım.
MainActivity kodlarım da burada
package d****.k****en;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.onesignal.OSNotification;
import com.onesignal.OSNotificationAction;
import com.onesignal.OSNotificationOpenResult;
import com.onesignal.OneSignal;
import android.app.Application;
import com.onesignal.OneSignal.NotificationOpenedHandler;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends Activity {
private WebView webView;
private String Uri;
@Override
protected void onCreate(Bundle savedInstanceState) { // Bu metod uygulama açıldığında çalıştırılan metod.
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String Uri = getIntent().getStringExtra("openURL");
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
.setNotificationReceivedHandler(new ExampleNotificationReceivedHandler())
.init();
// webView'i tasarımdakiyle bağlıyoruz.
webView = (WebView) findViewById(R.id.webViewl);
// webView'i JavaScript kodlarını çalıştıracak şekilde set ediyoruz.
webView.getSettings().setJavaScriptEnabled(true);
// Sayfanın yüklendiğinin anlaşılması için ProgressDialog açıyoruz.
webView.setWebViewClient(new WebViewClient() {
// Sayfa Yüklenirken bir hata oluşursa kullanıcıyı uyarıyoruz.
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Sayfa Yüklenemedi!",
Toast.LENGTH_SHORT).show();
}
// Sayfanın yüklenme işlemi bittiğinde progressDialog'u kapatıyoruz.
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
findViewById(R.id.spscreen).setVisibility(View.GONE);
//show webview
findViewById(R.id.webViewl).setVisibility(View.VISIBLE);
}
});
//Web sayfamızın url'ini webView'e yüklüyoruz.
if (Uri == null) {
webView.loadUrl("https://www.******.com");
} else {
webView.loadUrl(Uri);
}
//
}
private class ExampleNotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
@Override
public void notificationReceived(OSNotification notification) {
JSONObject data = notification.payload.additionalData;
String notificationID = notification.payload.notificationID;
String title = notification.payload.title;
String body = notification.payload.body;
String smallIcon = notification.payload.smallIcon;
String largeIcon = notification.payload.largeIcon;
String bigPicture = notification.payload.bigPicture;
String smallIconAccentColor = notification.payload.smallIconAccentColor;
String sound = notification.payload.sound;
String ledColor = notification.payload.ledColor;
int lockScreenVisibility = notification.payload.lockScreenVisibility;
String groupKey = notification.payload.groupKey;
String groupMessage = notification.payload.groupMessage;
String fromProjectNumber = notification.payload.fromProjectNumber;
//BackgroundImageLayout backgroundImageLayout = notification.payload.backgroundImageLayout;
String rawPayload = notification.payload.rawPayload;
String customKey;
Log.i("OneSignalExample", "NotificationID received: " + notificationID);
if (data != null) {
customKey = data.optString("customkey", null);
if (customKey != null)
Log.i("OneSignalExample", "customkey set with value: " + customKey);
}
}
}
private 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 Uri = result.notification.payload.launchURL; // update docs launchUrl
String customKey;
String openURL = Uri;
Object activityToLaunch = MainActivity.class;
if (data != null) {
customKey = data.optString("customkey", null);
openURL = data.optString("openURL", null);
if (customKey != null)
Log.i("OneSignalExample", "customkey set with value: " + customKey);
if (openURL != null)
Log.i("OneSignalExample", "openURL to webview with URL value: " + openURL);
}
// 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 intent = new Intent(getApplicationContext(), (Class<?>) activityToLaunch );
// İlk Hali intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
// Direk kapanan hali intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("openURL", Uri);
Log.i("OneSignalExample", "openURL = " + openURL);
// startActivity(intent);
startActivity(intent);
// Add the following to your AndroidManifest.xml to prevent the launching of your main Activity
// if you are calling startActivity above.
/*
<application ...>
<meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
</application>
*/
}
}
public void onBackPressed() //Android Back Buttonunu Handle ettik. Back butonu bir önceki sayfaya geri dönecek
{
if (webView.canGoBack()) {//eğer varsa bir önceki sayfaya gidecek
webView.goBack();
} else {//Sayfa yoksa uygulamadan çıkacak
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder.setTitle("Çıkmak istediğinizden emin misiniz?");
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("Evet",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainActivity.super.onBackPressed();
}
})
.setNegativeButton("Hayır", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
}
7 yıl 3 ay önce yanıtladın