Android-在应用程序中重写getPackageName()并获取组件回调。 [英] Android - Override getPackageName() in application and get component callback.
本文介绍了Android-在应用程序中重写getPackageName()并获取组件回调。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用Webview组件的Android应用中,我扩展了Application类,并且重写了getPackageName()方法。在我的应用程序的生命周期中,各种组件多次调用此方法。我想知道是不是它的webview组件。
这是我的代码:
in my Android app that uses a webview component, I have extended the Application class and I override the getPackageName() method. This method is called multiple times in the life of my application by various component. I want to know if it's the webview component that call it. Here is my code:
package com.xxx.xxx;
import android.app.Application;
public class Global extends Application {
private static Global instance;
public Global() {
instance = this;
}
private final String PACKAGE="com.webnews.appdirector";
@Override
public void onCreate() {
super.onCreate();
}
@Override
public String getPackageName() {
return PACKAGE; //this work fine, but how to know if is webkit callback ??? "instance" have mcomponentcallbacks set to webkit, but how to read it ???
}
}
您能帮我吗?
推荐答案
回答迟了一点,但这应该可以。
A little late to answer, but this should work.
@Override
public String getPackageName()
{
try
{
throw new Exception();
}
catch (Exception e)
{
StackTraceElement[] elements = e.getStackTrace();
for (StackTraceElement element: elements)
{
if(element.getClassName().startsWith("android.webkit."))
{
return null;
}
}
}
return super.getPackageName();
}
这篇关于Android-在应用程序中重写getPackageName()并获取组件回调。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文