Error on load Chrome Custom Tab in Android 11 - android-studio

Chrome custom tab work in every other device. Only error in Android 11.
Here is my code how I put I code in my app.
ImageView adCustomBannerImage= findViewById(R.id.adCustomBannerImage);
adCustomBannerImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String urlCustomBannerAd= getResources().getString(R.string.urlCustomBannerAdQureka);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent=builder.build();
customTabsIntent.launchUrl(getApplicationContext(),Uri.parse(urlCustomBannerAd));
}
});
When I click on ImageView then this error come in Android 11
2022-03-11 10:22:21.344 3059-3059/com.udai.aadharloan.kredit.finance.pmscheme E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.udai.aadharloan.kredit.finance.pmscheme, PID: 3059
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:1018)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:425)
at androidx.core.content.ContextCompat$Api16Impl.startActivity(ContextCompat.java:830)
at androidx.core.content.ContextCompat.startActivity(ContextCompat.java:279)
at androidx.browser.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:376)
at com.udai.aadharloan.kredit.finance.pmscheme.MainActivity$1.onClick(MainActivity.java:76)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
After too much research on this topic I found 3 helpful page. But I am not much pro developer, So I cann't understand these documentations terms.
Using Custom Tabs with Android 11
Package visibility in Android 11
Fulfilling common use cases while having limited package visibility
So any developer can tell me pls, what is need to change in my code.
Thanks in advance:)

Remove getApplicationContext() and pass your_activityname.this
customTabsIntent.launchUrl(your_activityname.this,Uri.parse(urlCustomBannerAd));

Related

App crashes after selecting option in menu on phone but not in emulator android studio

If i test my app on the android emulator it works great, but if i test it on my phone, i get the menu i need, but when i push a button to get the data from a mysql server it crashes.
This is my log with errors say after the crash in Android Studio.:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 32610
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:121)
at org.json.JSONTokener.nextValue(JSONTokener.java:98)
at org.json.JSONArray.(JSONArray.java:94)
at org.json.JSONArray.(JSONArray.java:110)
at com.example.myapplication.ProductkeuzeActivity.loadIntoListView(ProductkeuzeActivity.java:85)
at com.example.myapplication.ProductkeuzeActivity.-$$Nest$mloadIntoListView(Unknown Source:0)
at com.example.myapplication.ProductkeuzeActivity$1DownloadJSON.onPostExecute(ProductkeuzeActivity.java:55)
at com.example.myapplication.ProductkeuzeActivity$1DownloadJSON.onPostExecute(ProductkeuzeActivity.java:41)
at android.os.AsyncTask.finish(AsyncTask.java:771)
at android.os.AsyncTask.access$900(AsyncTask.java:199)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8645)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Can anybody help me to solve this?
Almost 3 weeks i'm trying to get it work, so if i mist something here to place just call.

Secured Android SharedPreferences Error: 'Caused by: java.lang.RuntimeException: Field keySize_ for...'

In an Android Kotlin project, I implemented EncryptedSharedPreference feature based on this link using the androidx.security library and it worked well in debug mode. But in release mode, I keep getting this error
java.lang.ExceptionInInitializerError
at com.package_name.i.a.f(:46)
at com.package_name.i.a.j(:52)
at com.package_name.i.a.e(:82)
at com.package_name.MyApplication.onCreate(:37)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
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)
Caused by: java.lang.RuntimeException: Field keySize_ for k.a.d.a.h0.u not found. Known fields are [private int k.a.d.a.h0.u.i, private static final k.a.d.a.h0.u k.a.d.a.h0.u.j, private static volatile k.a.d.a.i0.a.a1 k.a.d.a.h0.u.k]
at k.a.d.a.i0.a.v0.n0(:608)
Please kindly share your ideas on how to solve this error.
This bug is related to Minify Enabled, which most likely causes some values to be removed.
A bug is reported already, you can track it here:
https://issuetracker.google.com/issues/157983099
-keep class com.google.crypto.** { *; }
Something is wrong with the rc2 version of android crypto of may 20. So it is better to use 1.0.0-alpha02 in your gradle file.
Remember, takes care with dependencies which are not in rc. You can also fix the issue with a proguard rules (see comment of Sebas LG).
dependencies {
implementation "androidx.security:security-crypto:1.0.0-alpha02"
}
Official documentation : https://developer.android.com/jetpack/androidx/releases/security
Linked commits : https://android.googlesource.com/platform/frameworks/support/+log/f66cdf1658639bd74ae850dfe3c1f5bb72eaebe6..6be101c2241593fee3ef9ab4e1fb337b485f2f9a/security/crypto
I solved using
dependencies {
..
implementation "androidx.security:security-crypto:1.0.0-rc03"
This is due to the fact that AndroidX security library uses the Google Tink library(This is already fixed in Tink 1.4.0), where there is a flaw in working with Proguard.
Add this code to proguard-rules.pro and this should help:
-keepclassmembers class * extends com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite {
<fields>;
}
Links:
https://github.com/google/tink/issues/361
https://github.com/google/tink/blob/master/java_src/src/main/resources/META-INF/proguard/protobuf.pro

Speech-To-Text App Error

I cannot make a simple Speech-To-Text app work (I'm new to Java). I have been working on this code for several days and refuses to launch due to these errors:
08-13 12:35:08.784 26041-26041/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.blindnavi.navirecog2, PID: 26041
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.blindnavi.navirecog2/com.blindnavi.navirecog2.NaviVoice}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:117)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:54)
at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:31)
at android.support.v7.app.AppCompatDelegateImplN.<init>(AppCompatDelegateImplN.java:31)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:198)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at com.blindnavi.navirecog2.NaviVoice.<init>(NaviVoice.java:17)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
I do not know what most of these errors mean so i cannot fix the program myself. Please leave your suggestions below!
Your help is appreciated!
As discussed in another stackoverflow question Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
An Activity is not fully initialized and ready to look up views until after setContentView(...) is called in onCreate().
So only declare the fields uninitialized and then assign the values in onCreate:

Android Studio - how to debug this situation?

Preface
I'm maintaining an app that I inherited from another team
Scenario
I understand ClassCastException but for the life of me I cannot find where this error is occurring in the code.
01-27 14:47:15.839 13272-13272/com.xx.android E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xx.android, PID: 13272
java.lang.ClassCastException: com.xx.viewmodels.components.AutoValue_SpecialViewModel cannot be cast to com.xx.viewmodels.components.NormalViewModel
at com.xx.android.viewholders.NormalViewHolder.bind(NormalViewHolder.java:27)
at com.xx.android.BaseAdapter.onBindViewHolder(BaseAdapter.java:39)
at com.xx.android.componentfeed.ComponentFeedAdapter.onBindViewHolder(ComponentFeedAdapter.java:123)
at com.xx.android.componentfeed.ComponentFeedAdapter.onBindViewHolder(ComponentFeedAdapter.java:79)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6541)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5484)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5750)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5589)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5585)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2231)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1558)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1518)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:610)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3719)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3436)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3988)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:611)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1731)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1496)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:132)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1361)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:874)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:17938)
at android.view.ViewGroup.layout(ViewGroup.java:5814)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1171)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:856)
at android.support.design.widget.ViewOffsetBehavior.layoutChild(ViewOffsetBehavior.java:63)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:136)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1361)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:874)
at andro
(I'm not sure why the output cutoff at that point)
NormalViewHolder.java
line 27
public class NormalViewHolder extends ComponentViewHolder<NormalViewModel> {
lines 55-64
public NormalViewHolder(final View itemView, final RecyclerView.RecycledViewPool relatedItemsViewPool) {
super(itemView);
Dagger.getInstance(itemView.getContext()).inject(this);
ButterKnife.bind(this, itemView);
adapter = new NormalRelatedItemsAdapter();
recyclerView.setRecycledViewPool(relatedItemsViewPool);
recyclerView.setAdapter(adapter);
recyclerView.setNestedScrollingEnabled(false);
}
Question
The app stops abruptly even with the settings found in my screenshot below. I've set breakpoints all around bind and onBindViewHolder and followed them as far as they go with no avail. How can I go about tracking down this issue? I was thinking I could move around in a breakpoint to put things together but I'm not having any luck.. Suggestions?
Extra
In researching the issue I've adjusted my breakpoint settings to the following with no success:
This was an impossible situation to debug.
This app was written to leverage dagger modules. In the app there was a line that referenced an incompatible class but in a file that was never even mentioned in the stack trace - making my methods of debugging rather useless.
Ultimately I had to go through line by line, manually inspecting every situation. Good old fashioned elbow grease.

java.lang.VerifyError: me.xxx.menu.MenuListFragment only on Android 2.x.x

after almost 2 week trying to solve this strange problem, I give up!
Basically a get the java.lang.VerifyError every time I try to run my app
only in devices with Android 2.x.x. From 3.x.x all are going well.
In the project I'm using this two external library:
Action Bar Sherlock - http://actionbarsherlock.com/ - updated at the v4.4.0
Sliding Menu - https://github.com/jfeinstein10/SlidingMenu
This is what the LogCat return every time:
FATAL EXCEPTION: main
java.lang.VerifyError: me.xxx.menu.MenuListFragment
at me.xxx.menu.BaseSlidingMenuActivity.onCreate(BaseSlidingMenuActivity.java:46)
at me.xxx.menu.SlidingMenuCustomAnimation.onCreate(SlidingMenuCustomAnimation.java:28)
at me.xxx.XXXActivity.onCreate(XXXActivity.java:130)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
and this is how the BaseSlidingMenuActivity.java looks like around the line 46:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mTitleRes);
// set the Behind View
setBehindContentView(R.layout.frame_content);
if (savedInstanceState == null) {
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new MenuListFragment(); <--- ERROR HERE!
t.replace(R.id.frame_content, mFrag);
t.commit();
} else {
mFrag =(SherlockListFragment)this.getSupportFragmentManager()
.findFragmentById(R.id.frame_content);
}
...
...
}
Where MenuListFragment() is a SlidingFragmentActivity that extend a SherlockFragmentActivity
and implements SlidingActivityBase.
Of course I googled the problem, and seems that a lot of people are getting this
issue with the last version of the Android SDK tool, i.e. v22.x.x , in fact a have
the v22.6.3.
Some people resolved the VerifyError just putting the Check on the "Private Libraries"
box, inside "BuildPath->Configure BuildPath->Order and Export" menù, as explained
in other conversation about the VerifyError, but for me doesn't work, even because the "Private Libraries" was already checked. So the libraries/imports situation seems to be ok!
Hoping that someone already fund a solution for that! I'm getting crazy! :D
Thank you!
I finally found the solution!
Recap! Basically the are two main reason in which you can get this error:
(In my case) I was getting the VerifyError all the time that I tried to run my app on devices with API Level under 10 , because I was trying to catch an SQLiteDatabaseLockedException that are supported from the Android API Level 11. So to solve it check that every Exception or possible method (i.e. String.isEmpty() is supported from API Level 9) is supported form your minimum API Level.
While I was searching for a solution I found a lot of people that got the VerifyError because there was some problem with Libraries Imports, as explained in this post: http://commonsware.com/blog/2013/05/23/do-not-manually-modify-eclipse-build-path-except-now-r22.html
Hope that will help someone beyond me! :D
Bye Bye! Caterpillar.

Resources