function getLauncherClassName: JString; var str : JString; localPackageManager : JPackageManager; Intent: JIntent; localIterator : JIterator; localResolveInfo : JResolveInfo; begin localPackageManager := SharedActivity.getPackageManager; Intent := TJIntent.JavaClass.init(StringToJString(‘android.intent.action.MAIN‘)); Intent.addCategory(StringToJString(‘android.intent.category.LAUNCHER‘)); try localIterator := localPackageManager.queryIntentActivities(Intent,0).iterator; while localIterator.hasNext do begin localResolveInfo := TJResolveInfo.Wrap((localIterator.next as ILocalObject).GetObjectID); if (not localResolveInfo.activityInfo.applicationInfo.packageName.equalsIgnoreCase(SharedActivity.getPackageName)) then Continue; Result := localResolveInfo.activityInfo.name; Break; end; except end; end; procedure setHuaweiBadge(num: Integer); var str : JString; localBundle : JBundle; begin str := getLauncherClassName; if JStringToString(str) <> ‘‘ then begin localBundle := TJBundle.JavaClass.init; localBundle.putString(StringToJString(‘package‘), SharedActivityContext.getPackageName()); localBundle.putString(StringToJString(‘class‘), str); localBundle.putInt(StringToJString(‘badgenumber‘), 3); SharedActivityContext.getContentResolver.call(StrToJURI(‘content://com.huawei.android.launcher.settings/badge/‘),StringToJString(‘change_badge‘),StringToJString(‘null‘),localBundle); end; end;现在手头上只有华为的手机,其他没有经过测试的代码就不贴出来了,自己找java代码转换。 判断手机类型:TJBuild.JavaClass.MANUFACTURER.EqualsIgnoreCase(StringToJString(‘huawei‘))
时间: 2024-10-12 14:17:53