Tôi đang thử điều đó. Tôi gửi một số AdditionalData từ push và chuyển hướng người dùng đến hoạt động spesific nhưng không chuyển hướng.OneSignal - không thể mở hoạt động sau khi nhấn được bấm
Ví dụ: tôi gửi một tệp tin có chứa AdditionalData như imageID và chuyển hướng hoạt động ImageDetail của người dùng bằng cách truyền tham số imageID đến hoạt động khác.
Khi tôi nhấp vào đẩy, Hoạt động chính mở ra và không có gì xảy ra
Tôi đã thử nhưng không thể thành công.
Làm thế nào tôi có thể sửa chữa nó
public class MainActivity extends Activity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
// nav drawer title
private CharSequence mDrawerTitle;
// used to store app title
private CharSequence mTitle;
// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
private static MainActivity mInstance;
private AccessToken facebookAccessToken;
private SessionManager session;
private String pushAdURL;
private boolean isAdActive = false;
private boolean isQRActive = false;
private boolean isMaintenanceMode = false;
SharedPreferences sp ;
SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp = PreferenceManager.getDefaultSharedPreferences(this);
Log.e("MAIN", "Main activity has been called");
session = new SessionManager(getApplicationContext());
OneSignal.startInit(this)
.setNotificationOpenedHandler(new NotificationHandler())
.init();
public static synchronized MainActivity getInstance() {
return mInstance;
}
private class NotificationHandler implements OneSignal.NotificationOpenedHandler {
/**
* Callback to implement in your app to handle when a notification is opened from the Android status bar or
* a new one comes in while the app is running.
* This method is located in this Application class as an example, you may have any class you wish implement NotificationOpenedHandler and define this method.
*
* @param message The message string the user seen/should see in the Android status bar.
* @param additionalData The additionalData key value pair section you entered in on onesignal.com.
* @param isActive Was the app in the foreground when the notification was received.
*/
@Override
public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
Toast.makeText(getApplicationContext(), "Notification opened:" + message
+ "Addional: "+additionalData, Toast.LENGTH_SHORT).show();
Log.d("MESAJ:","message: " +message + "AditionData: " +String.valueOf(additionalData));
try{
if (additionalData != null) {
Log.d("MESAJ:","Additionaldata is not null");
if (additionalData.has("action")) {
Log.d("MESAJ:", "Title " + additionalData.getString("title"));
Log.d("MESAJ:", "Additionaldata has action");
Log.d("MESAJ:", "Action is " + additionalData.getString("action"));
Log.d("MESAJ:", "Action id is " + additionalData.getString("id"));
if (additionalData.getString("action") == "openimage") {
Log.d("MESAJ:","Additionaldata action is openimage");
String pusedImageId = additionalData.getString("id");
Log.d("MESAJ:", "Additionaldata action is " + pusedImageId);
Intent intent = new Intent(getApplicationContext(), ImageDetail.class);
intent.putExtra("imageid", pusedImageId);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else if (additionalData.getString("action") == "openboard") {
Log.d("MESAJ:","Additionaldata action is openboard");
String pusedBoardId = additionalData.getString("id");
Log.d("MESAJ:","Additionaldata action is " +pusedBoardId);
Intent intent = new Intent(getApplicationContext(), BoardDetail.class);
intent.putExtra("boardid", pusedBoardId);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
/*try {
if (additionalData != null) {
if (additionalData.has("actionSelected"))
additionalMessage += "Pressed ButtonID: " + additionalData.getString("actionSelected");
additionalMessage = message + "\nFull additionalData:\n" + additionalData.toString();
}
Log.d("OneSignalExample", "message:\n" + message + "\nadditionalMessage:\n" + additionalMessage);
} catch (Throwable t) {
t.printStackTrace();
}
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(MainActivity.this);
builder.setTitle("Bilgilendirme");
builder.setMessage(message + String.valueOf(additionalData));
builder.setPositiveButton("Tamam", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
android.app.AlertDialog alert = builder.create();
alert.show();*/
}
}
}
Dưới đây là kết quả các logcat
1-31 08:17:47.410 20682-20682/com.harmankaya.otokatalog D/MESAJ:: message: klAditionData: {"action":"openboard","id":"23123","title":"dsga"}
01-31 08:17:47.410 20682-20682/com.harmankaya.otokatalog D/MESAJ:: Additionaldata is not null
01-31 08:17:47.415 20682-20682/com.harmankaya.otokatalog D/MESAJ:: Title dsga
01-31 08:17:47.415 20682-20682/com.harmankaya.otokatalog D/MESAJ:: Additionaldata has action
01-31 08:17:47.415 20682-20682/com.harmankaya.otokatalog D/MESAJ:: Action is openboard
01-31 08:17:47.415 20682-20682/com.harmankaya.otokatalog D/MESAJ:: Action id is 23123
01-31 08:17:47.445 20682-20682/com.harmankaya.otokatalog D/OneSignal: curActivity is NOW: null
01-31 08:17:47.600 20682-20682/com.harmankaya.otokatalog V/BitmapFactory: DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi-v4/sym_def_app_icon.png
01-31 08:17:47.610 20682-20682/com.harmankaya.otokatalog D/AbsListView: Get MotionRecognitionManager
01-31 08:17:47.615 20682-20682/com.harmankaya.otokatalog E/MAIN: Main activity has been called
EDIT: Hımm tôi gần kết thúc :) Tôi đã thêm những dòng này vào OnCreate phương pháp và tôi muốn di chuyển mu đẩy chuyển hướng logic để OnCreate phương pháp MainActivity. Nhưng bây giờ tôi không thể phân tích Bundle extras Ý định :)
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
Toast.makeText(getApplicationContext(), "Sonuç: " +bundle, Toast.LENGTH_SHORT).show();
Log.d("mesaj", "Result: " + bundle);
if (bundle != null) {
try {
//TODO Push redirect logic
Log.d("mesaj","String bundle : "+bundle.getString("onesignal_data"));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("PUSH",String.valueOf(e));
}
}
logcat quả
Sonuç: Bundle[{onesignal_data=[{"custom":"{\"a\":{\"action\":\"openboard\",\"id\":\"2345\"},\"i\":\"159c4c5d-37d2-45ec-ae90-6f103a4b8e83\"}","from":"111189706423","alert":"demopushbody","title":"demotitle","android.support.content.wakelockid":1,"collapse_key":"do_not_collapse"}]}]
Bạn có nhận được bất kỳ lỗi? Hãy thử đặt một bản ghi trước khi 'try' chặn trong' notificationOpened' để xem ngay cả khi nó đang được gọi. – Rohit5k2
không phải lỗi. Vấn đề là phương thức onCreate được kích hoạt sau khi thông báoOpen() :( –
Hmmmm i am gần để kết thúc :) Tôi đã thêm các dòng này vào phương thức OnCreate và tôi muốn di chuyển logic chuyển hướng mu tới phương thức OnCreate của MainActivity. Nhưng bây giờ tôi không thể phân tích cú pháp tính năng bổ sung của gói bổ sung :) –