问题
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