Android get dialer package name

限于喜欢 提交于 2021-02-10 15:51:52

问题


I need to get package name of an app which post notification about a missed call. As far as I understand it makes dialer app of a device. Can I get package name of dialer app on the device, I need it from API 19?


回答1:


You can filter all dialer applications using Intent.ACTION_DIAL action and PackageManager.queryIntentActivities(...). Where it will return list of applications which can dial phone. Read more at Android: How to show a list of dialer app installed on my device instead of directly calling default dialer


You can use below code, as it is

public List<String> getPackagesOfDialerApps(Context context){

    List<String> packageNames = new ArrayList<>();

    // Declare action which target application listen to initiate phone call
    final Intent intent = new Intent();
    intent.setAction(Intent.ACTION_DIAL);
    // Query for all those applications
    List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(intent, 0);
    // Read package name of all those applications
    for(ResolveInfo resolveInfo : resolveInfos){
        ActivityInfo activityInfo = resolveInfo.activityInfo;
        packageNames.add(activityInfo.applicationInfo.packageName);
    }

    return packageNames;
}



回答2:


To get an app's package (and activity name) you can use adb command.

Launch the app and then:

adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'

From the output:

mFocusedApp=AppWindowToken{
  e224f9d token=Token{
    d8b2e74 ActivityRecord{
      1d97647 u0 com.android.dialer/.app.DialtactsActivity t1078
    }
  }
}

You can say the app's package is com.android.dialer and activity name is .app.DialtactsActivity



来源:https://stackoverflow.com/questions/48225919/android-get-dialer-package-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!