please note that problem might be related to Android 10
Im trying to start a new Activity from myInAppMessagingService, but i got null pointer exception un startActivitys context parameter every time.
So here is my Service code :
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.firebase.inappmessaging.FirebaseInAppMessagingClickListener;
import com.google.firebase.inappmessaging.model.Action;
import com.google.firebase.inappmessaging.model.CampaignMetadata;
import com.google.firebase.inappmessaging.model.InAppMessage;
import viaapp_v2.systems.webview_activity.webview_base;
public class MyFirebaseInAppMessaging extends Service implements FirebaseInAppMessagingClickListener {
String TAG = "MyFirebaseInAppMessaging";
@Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void messageClicked(@NonNull InAppMessage inAppMessage, @NonNull Action action) {
// Determine which URL the user clicked
String url = action.getActionUrl();
Log.d(TAG, "Popup URL :"+url);
// Get general information about the campaign
CampaignMetadata metadata = inAppMessage.getCampaignMetadata();
Log.d(TAG, "metadata :"+metadata);
try{
startActivity(
new Intent(MyFirebaseInAppMessaging.this, webview_base.class)
.putExtra("web_url", url)
);
}catch(Exception e){
e.printStackTrace();
}
}
}
I got error in "startActivity(..)" line because of 1st parameter, context. I tried everything - getApplicationContext(), MyFirebaseInAppMessaging.this or just simply "this" but nothing works.
I read a restrictions provided by Android Developers, but i couldnt figure out anything new.
Otherwise the app works perfectly - webview_base class works as it should, so does everything else, including myInAppMesaging Services listener. Its just that one context in startActivity() which stops me.
Thanks for any help.
--Update on Sep 7
After playing around with permissions, flags ect. i noticed that nothing works. Newer Android OS opens an web overly over the app, but older Android OS just crashes without any specific crash report. Thats weird.
Try below code , it will work..
you have to add FLAG-
FLAG_ACTIVITY_NEW_TASK