|
17 | 17 |
|
18 | 18 | import android.content.Context;
|
19 | 19 | import android.content.Intent;
|
| 20 | +import android.content.pm.ApplicationInfo; |
| 21 | +import android.content.pm.PackageManager; |
20 | 22 | import android.net.Uri;
|
21 | 23 |
|
22 | 24 | public class IntentHelper {
|
23 | 25 |
|
24 | 26 | private static final String GALLERY_PACKAGE_NAME = "com.android.gallery3d";
|
| 27 | + private static final String SNAPDRAGON_GALLERY_PACKAGE_NAME = "org.codeaurora.gallery"; |
25 | 28 | private static final String GALLERY_ACTIVITY_CLASS =
|
26 |
| - "com.android.gallery3d.app.GalleryActivity"; |
| 29 | + "com.android.gallery3d.app.GalleryActivity"; |
27 | 30 |
|
28 | 31 | public static Intent getGalleryIntent(Context context) {
|
| 32 | + String packageName = packageExist(context, SNAPDRAGON_GALLERY_PACKAGE_NAME) ? |
| 33 | + SNAPDRAGON_GALLERY_PACKAGE_NAME : GALLERY_PACKAGE_NAME; |
29 | 34 | return new Intent(Intent.ACTION_MAIN)
|
30 |
| - .setClassName(GALLERY_PACKAGE_NAME, GALLERY_ACTIVITY_CLASS); |
| 35 | + .setClassName(packageName, GALLERY_ACTIVITY_CLASS); |
31 | 36 | }
|
32 | 37 |
|
33 | 38 | public static Intent getVideoPlayerIntent(Context context, Uri uri) {
|
34 | 39 | return new Intent(Intent.ACTION_VIEW)
|
35 |
| - .setDataAndType(uri, "video/*"); |
| 40 | + .setDataAndType(uri, "video/*"); |
| 41 | + } |
| 42 | + |
| 43 | + private static boolean packageExist(Context context, String packageName) { |
| 44 | + if (packageName == null || "".equals(packageName)) { |
| 45 | + return false; |
| 46 | + } |
| 47 | + try { |
| 48 | + context.getPackageManager().getApplicationInfo(packageName, 0); |
| 49 | + return true; |
| 50 | + } catch (PackageManager.NameNotFoundException e) { |
| 51 | + return false; |
| 52 | + } |
36 | 53 | }
|
37 | 54 | }
|
0 commit comments