I have an Android app that is crashing due to an unhandled exeption, but only on one particular device (running Nougat). I believe they are the only one of my testers that is running Nougat. This is the exception:
Java.Lang.RuntimeException: Bad notification posted from package [my
package name]: Couldn't cache contentViews: package=[my package name]
Here is the stack trace:
android.app.RemoteServiceException: Bad notification posted from package com.elephanigma.starmygrooves: Couldn't cache contentViews: package=com.elephanigma.starmygrooves
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1675)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Xamarin caused by: Java.Lang.RuntimeException: Bad notification posted from package com.elephanigma.starmygrooves: Couldn't cache contentViews: package=com.elephanigma.starmygrooves
--- End of managed Java.Lang.RuntimeException stack trace ---
android.app.RemoteServiceException: Bad notification posted from package com.elephanigma.starmygrooves: Couldn't cache contentViews: package=com.elephanigma.starmygrooves
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1675)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
The stack trace does not show any of my own code. My app does not create any notifications itself, but it does use an open source package (Xamarin Media Manager) that does. The stack trace does not show any of that package's code either.
So, I'm not sure where to look. I have tried searching for this exception, and although I get a couple of hits for "Bad notification posted", none of them seem to address my issue. I do not get ANY hits for "Couldn't cache contentViews".
If it helps, here is the code (as best I can tell) from the package that creates the notification: (note this is c# code, because it's using Xamarin/Mono)
/// <summary>
/// When we start on the foreground we will present a notification to the user
/// When they press the notification it will take them to the main page so they can control the music
/// </summary>
public void StartNotification(IMediaFile mediaFile, bool mediaIsPlaying, bool canBeRemoved)
{
var icon = (_appliactionContext.Resources?.GetIdentifier("xam_mediamanager_notify_ic", "drawable", _appliactionContext?.PackageName)).GetValueOrDefault(0);
_notificationStyle.SetMediaSession(_sessionToken);
_notificationStyle.SetCancelButtonIntent(_pendingCancelIntent);
_builder = new NotificationCompat.Builder(_appliactionContext)
{
MStyle = _notificationStyle
};
_builder.SetSmallIcon(icon != 0 ? icon : _appliactionContext.ApplicationInfo.Icon);
_builder.SetContentIntent(_pendingIntent);
_builder.SetOngoing(mediaIsPlaying);
_builder.SetVisibility(1);
SetMetadata(mediaFile);
AddActionButtons(mediaIsPlaying);
if (_builder.MActions.Count >= 3)
((NotificationCompat.MediaStyle)(_builder.MStyle)).SetShowActionsInCompactView(0, 1, 2);
NotificationManagerCompat.From(_appliactionContext)
.Notify(MediaServiceBase.NotificationId, _builder.Build());
}
Related
I create a screenshot application and that work good in all of the android devices.
But I have a problem with take screenshot in android 12 (Xiaomi 11t) I'm using static intent and result code and then clone intent and pass it to this function mediaProjectionManager.getMediaProjection(resultCode,clonedIntent) I have no problem with take screen shot for first time but I can't take screen shot for second time and I get this error.
if you need more info please tell me.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.koala.classor, PID: 10824
java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.Set.add(java.lang.Object)' on a null object reference
at android.os.Parcel.createExceptionOrNull(Parcel.java:2431)
at android.os.Parcel.createException(Parcel.java:2409)
at android.os.Parcel.readException(Parcel.java:2392)
at android.os.Parcel.readException(Parcel.java:2334)
at android.media.projection.IMediaProjection$Stub$Proxy.start(IMediaProjection.java:235)
at android.media.projection.MediaProjection.<init>(MediaProjection.java:59)
at android.media.projection.MediaProjectionManager.getMediaProjection(MediaProjectionManager.java:119)
at com.koala.classor.G.getMediaProjection(G.java:86)
at com.koala.classor.OverScreenWindowService$2$1.run(OverScreenWindowService.java:194)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8105)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.media.projection.MediaProjectionManagerService$MediaProjection.start(MediaProjectionManagerService.java:553)
at android.media.projection.IMediaProjection$Stub.onTransact(IMediaProjection.java:137)
at android.os.Binder.execTransactInternal(Binder.java:1182)
at android.os.Binder.execTransact(Binder.java:1146)
MIUI13+Android12
The RemoteException error is reported on line 553 of MediaProjectionManagerService. After checking the source code, the error message is that the package for applying for mediaprojection cannot be found.
It is guessed that MIUI maintains a separate list for this, only the package that has applied for permission will be in it, and it will be removed after obtaining and closing mediaprojection. No such mechanism has been seen in other systems.
In other words, intent data cannot be reused. The solution is also very simple, just don’t close the mediaprojection after using it.
It appears from my crash reports that some people pirate my app and add advertisements to monetise it.
The stack trace from the crash report seems to show a bunch of calls to a library to show interstitials?
Is it possible for me to add code to detect the presence of the com.test.ylh or com.qq.e library?
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy#da2c866 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:1126)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:439)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
at android.app.Dialog.show(Dialog.java:473)
at com.qq.e.comm.plugin.intersitial2.e.a(A:315)
at com.qq.e.comm.plugin.intersitial2.e.show(A:113)
at com.qq.e.comm.plugin.intersitial2.e.show(A:107)
at com.qq.e.comm.plugin.intersitial2.d.show(A:35)
at com.qq.e.ads.interstitial2.UnifiedInterstitialAD.show(Unknown Source:4)
at com.test.ylh.InterAd$2.run(InterAd.java:53)
at android.app.Activity.runOnUiThread(Activity.java:6972)
at com.test.ylh.InterAd.showAd(InterAd.java:50)
at com.test.ylh.InterAd.onADReceive(InterAd.java:108)
at com.qq.e.comm.plugin.intersitial2.a$1.run(A:169)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7860)
at java.lang.reflect.Method.invoke(Method.java:-2)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
You can check if a class exists with a method as described over here: How to check if class exists somewhere in package?
However, they could also remove that check when recompiling the app. So it won't be airtight. You can make it more difficult for the "pirates" by adding proper code obfuscation: https://developer.android.com/studio/build/shrink-code#obfuscate
I use Flurry through MoPub. I use the MoPub provided adapters for Flurry, so essentially I have zero code of my own for Flurry.
I keep getting these crashes from them on Crashlytics, basically, they are all CalledFromWrongThreadException.
I've never reproduced the issue myself. Flurry claims it must be my code but like I said, I have zero Flurry specific code and I don't get that crash with any other ad network. The stack trace shows it is all within Flurry's code. It isn't clear from the stacktrace whether this is a interstitial crash or a native ad crash.
Is anyone else seeing crashes like this?
Fatal Exception: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7901)
at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1322)
at android.view.View.requestLayout(View.java:21049)
at android.view.View.requestLayout(View.java:21049)
at android.view.View.requestLayout(View.java:21049)
at android.view.View.requestLayout(View.java:21049)
at android.view.View.requestLayout(View.java:21049)
at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:360)
at android.view.View.requestLayout(View.java:21049)
at android.widget.TextView.checkForRelayout(TextView.java:8621)
at android.widget.TextView.setText(TextView.java:5131)
at android.widget.TextView.setText(TextView.java:4956)
at android.widget.TextView.setText(TextView.java:4931)
at com.flurry.sdk.hq$2.run(SourceFile:123)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
I have a piece of code that tries to query the YouTube Data API to get the MetaData of a youtube video, using as a parameter the videoID. To be able to access the YouTube Data API server, the program executes the imposed transactions and permissions.
To be able to access the YouTube Data API, the code invokes a Dialog window with the message: "This app needs your Google account (via Contacts)":
public class LMMoviesMainActivity extends AppCompatActivity
implements EasyPermissions.PermissionCallbacks {...
// Relevant part of the method of the Interface: EasyPermissions:
EasyPermissions.requestPermissions(
this,
"This app needs to access your Google account (via Contacts).",
REQUEST_PERMISSION_GET_ACCOUNTS,
Manifest.permission.GET_ACCOUNTS);
The window has Ok and Cancel buttons. After pressing Ok, the App crashes. The LogCat is:
11-18 10:27:08.460 4566-4566/com.languagematerial.lmmovies E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.languagematerial.lmmovies, PID: 4566
java.lang.ClassCastException: com.languagematerial.lmmovies.LMMoviesMainActivity cannot be cast to android.support.v4.app.FragmentActivity
at pub.devrel.easypermissions.RationaleDialogClickListener.onClick(RationaleDialogClickListener.java:57)
at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:162)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-18 10:27:08.461 1642-2985/system_process W/ActivityManager: Force finishing activity com.languagematerial.lmmovies/.LMMoviesMainActivity
11-18 10:27:08.463 1259-1720/? D/PermissionCache: checking android.permission.READ_FRAME_BUFFER for uid=1000 => granted (109 us)
11-18 10:27:08.463 1259-1720/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 520192
[ 11-18 10:27:08.466 1642: 2985 D/ ]
HostConnection::get() New Host Connection established 0x9cb5b9c0, tid 2985
11-18 10:27:08.484 1259-1720/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
11-18 10:27:08.484 1642-4704/system_process D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
The line: RationaleDialogClickListener.java refers to a file which is part of a Library called: pub.devrel:easypermissions-0.3.0
The code in that Library file in the Line number 57 is:
ActivityCompat.requestPermissions((FragmentActivity) mHost, mConfig.permissions, mConfig.requestCode);
This RationaleDialogClickListener.java file cannot be modified because it is ONLY READABLE. And even if I could modify it, I have no idea what to put instead!
Also, my own App never uses fragments: The calling code is located in the MainActivity (In case that fact could be relevant).
There are similar cases of this Cast error, but none has a satisfactory answer. Any ideas or suggestions on how to proceed? Thanks
I've followed AWS Mobile Hub push integration guide, and integrated AWS SNS push services in my app. When I open the app I get this error log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.intap.appme, PID: 23576
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.intap.name/com.intap.name.MainActivity}: com.amazonaws.AmazonServiceException: 1 validation error detected: Value null at 'token' failed to satisfy constraint: Member must not be null (Service: AmazonSNS; Status Code: 400; Error Code: ValidationError; Request ID: 21d6a3b2-0459-513a-bf7a-f3c1d99d41ac)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: com.amazonaws.AmazonServiceException: 1 validation error detected: Value null at 'token' failed to satisfy constraint: Member must not be null (Service: AmazonSNS; Status Code: 400; Error Code: ValidationError; Request ID: 21d6a3b2-0459-513a-bf7a-f3c1d99d41ac)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:712)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:388)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:199)
at com.amazonaws.services.sns.AmazonSNSClient.invoke(AmazonSNSClient.java:2262)
at com.amazonaws.services.sns.AmazonSNSClient.createPlatformEndpoint(AmazonSNSClient.java:447)
at com.amazonaws.mobile.push.PushManager.subscribeToTopic(PushManager.java:264)
at com.intap.name.MainActivity.onCreate(MainActivity.java:50)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
The code lines mentioned in the app are those lines:
PushManager.java:264 (The whole method)
public void subscribeToTopic(final SnsTopic topic) {
final CreatePlatformEndpointRequest endpointRequest = new CreatePlatformEndpointRequest();
endpointRequest.setPlatformApplicationArn(platformApplicationArn);
try {
endpointRequest.setToken(InstanceID.getInstance(context).getToken(sharedPreferences.getString("deviceToken", ""), GoogleCloudMessaging.INSTANCE_ID_SCOPE));
} catch (IOException e) {
Log.e("Error", e.getMessage());
}
/* This is line 264 -> */ final CreatePlatformEndpointResult endpointResult = sns.createPlatformEndpoint(endpointRequest);
final SubscribeRequest request = new SubscribeRequest();
request.setEndpoint(endpointResult.getEndpointArn());
request.setTopicArn(topic.getTopicArn());
request.setProtocol(SNS_PROTOCOL_APPLICATION);
final SubscribeResult result = sns.subscribe(request);
// update topic and save subscription in shared preferences
final String subscriptionArn = result.getSubscriptionArn();
topic.setSubscriptionArn(subscriptionArn);
sharedPreferences.edit().putString(topic.getTopicArn(), subscriptionArn).apply();
}
MainActivity.java:50
pushManager.subscribeToTopic(pushManager.getDefaultTopic());
When I'm trying to send a push message through the online Firebase console, The device gets the push messages, and when I click on the message to open the app it keeps crashing.
When I'm trying to send a push message through the online SNS console, I don't get any push notfiications, which means the error is in the registration to SNS.
How can I solve it? I have no idea about it...
The token is coming back as null from Google's SDK. The reason is due to this line:
endpointRequest.setToken(InstanceID.getInstance(context)
.getToken(sharedPreferences.getString("deviceToken", ""),
GoogleCloudMessaging.INSTANCE_ID_SCOPE));
The first parameter to getToken() should be the GCM Sender ID rather than the device token that is being passed as pulled from sharedPreferences. Changing your code to pass the sender ID as follows, should fix the issue:
endpointRequest.setToken(InstanceID.getInstance(context)
.getToken(gcmSenderID, GoogleCloudMessaging.INSTANCE_ID_SCOPE));
Also, it appears that the code you pasted was modified from a Mobile Hub project that was generated in the fairly distant past. There have been improvements in the PushManager since then. The latest versions generated by the Mobile Hub would use the GCMTokenHelper class, which is not present in the code you pasted. Please try generating the sample app or SDK using the Mobile Hub again and updating your app to use the more recently generated code and report back if you are still experiencing issues.