Utils.getPackageUri() for creating Uris from packageNames

Since this is done a lot, might as well have a reusable method.
This commit is contained in:
Hans-Christoph Steiner 2016-05-25 13:00:00 +02:00
parent ae3ea85355
commit 677db72bb3
3 changed files with 11 additions and 4 deletions

View File

@ -158,7 +158,7 @@ public class TestUtils {
context.setPackageManager(pm);
pm.install(appId, versionCode, versionName);
Intent installIntent = new Intent(Intent.ACTION_PACKAGE_ADDED);
installIntent.setData(Uri.parse("package:" + appId));
installIntent.setData(Utils.getPackageUri(appId));
new PackageAddedReceiver().onReceive(context, installIntent);
}
@ -176,7 +176,7 @@ public class TestUtils {
context.setPackageManager(pm);
pm.install(appId, versionCode, versionName);
Intent installIntent = new Intent(Intent.ACTION_PACKAGE_CHANGED);
installIntent.setData(Uri.parse("package:" + appId));
installIntent.setData(Utils.getPackageUri(appId));
new PackageUpgradedReceiver().onReceive(context, installIntent);
}
@ -189,7 +189,7 @@ public class TestUtils {
context.setPackageManager(pm);
pm.remove(appId);
Intent installIntent = new Intent(Intent.ACTION_PACKAGE_REMOVED);
installIntent.setData(Uri.parse("package:" + appId));
installIntent.setData(Utils.getPackageUri(appId));
new PackageRemovedReceiver().onReceive(context, installIntent);
}

View File

@ -267,6 +267,13 @@ public final class Utils {
return b.build();
}
/**
* Create a standard {@link PackageManager} {@link Uri} for pointing to an app.
*/
public static Uri getPackageUri(String packageName) {
return Uri.parse("package:" + packageName);
}
/**
* This location is only for caching, do not install directly from this location
* because if the file is on the External Storage, any other app could swap out

View File

@ -58,7 +58,7 @@ public class CacheSwapAppsService extends IntentService {
if (!indexJarFile.exists()
|| FileUtils.isFileNewer(new File(applicationInfo.sourceDir), indexJarFile)) {
Intent intent = new Intent();
intent.setData(Uri.parse("package:" + applicationInfo.packageName));
intent.setData(Utils.getPackageUri(applicationInfo.packageName));
parseApp(context, intent);
}
}