【问题标题】:How to get package name of the library in Android?如何在Android中获取库的包名?
【发布时间】:2020-03-19 23:34:34
【问题描述】:

我有一个 android 应用程序,我在内部依赖几个库。现在我正在尝试记录发生在单个组件级别(这意味着单个库级别)的崩溃,以便帮助我分析导致崩溃的组件。

public class MyApplication extends Application implements Thread.UncaughtExceptionHandler {

    public static final String TAG = "myapplication";

    public static MyApplication applicationInstance;

    public MyApplication() {
        Thread.setDefaultUncaughtExceptionHandler(this);
    }

    @Override
    public Context getApplicationContext() {
        return super.getApplicationContext();
    }

    public static MyApplication getInstance() {
        return applicationInstance;
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
    }


    @Override
    public void uncaughtException(Thread t, Throwable e) {
        Log.i(TAG, "Inside uncaught exception..." + Thread.currentThread().getId());
        //getPackageName() here returns the name of the application instead of the dependent library's one. 
    }
}

有什么方法可以获取添加到他们的 android 清单中的库的包名吗?

【问题讨论】:

    标签: android exception android-library android-package-managers android-threading


    【解决方案1】:

    不是真的。库没有应用程序 ID。清单中的package 属性仅用于代码生成,仅此而已。

    如果你碰巧有一个库中的对象,你可以获取与该类关联的 Java 包,并可能从那里推断出你所指的是哪个库。

    【讨论】:

    • 是的,我想到了完全相同的方法,然后我遇到了另一个问题,即同一个库中有 n 个 java 包 - 我很难将它们分组在同一个包下 - 没有维护我消费的软件包的白名单。
    猜你喜欢
    • 1970-01-01
    • 2012-01-28
    • 2013-03-14
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 2012-10-09
    相关资源
    最近更新 更多