1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.camera.util;
17 
18 import android.content.Context;
19 import android.content.Intent;
20 import android.content.pm.PackageManager;
21 import android.content.pm.ResolveInfo;
22 import android.graphics.drawable.Drawable;
23 import android.net.Uri;
24 
25 import com.android.camera.debug.Log;
26 
27 import java.util.List;
28 
29 public class IntentHelper {
30     private static final Log.Tag TAG = new Log.Tag("IntentHelper");
31 
getGalleryIntent(Context context)32     public static Intent getGalleryIntent(Context context) {
33         Intent intent = new Intent(Intent.ACTION_MAIN);
34         GalleryHelper.setGalleryIntentClassName(intent);
35 
36         // check if intent can launch gallery
37         PackageManager pm = context.getPackageManager();
38         List<ResolveInfo> resolveInfos =
39             pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
40         if (resolveInfos.size() == 0) {
41             return null;
42         } else {
43             return intent;
44         }
45     }
46 
getGalleryIcon(Context context, Intent galleryIntent)47     public static Drawable getGalleryIcon(Context context, Intent galleryIntent) {
48         return GalleryHelper.getGalleryIcon(context, galleryIntent);
49     }
50 
getGalleryAppName(Context context, Intent galleryIntent)51     public static CharSequence getGalleryAppName(Context context, Intent galleryIntent) {
52         return GalleryHelper.getGalleryAppName(context, galleryIntent);
53     }
54 
getVideoPlayerIntent(Uri uri)55     public static Intent getVideoPlayerIntent(Uri uri) {
56         return new Intent(Intent.ACTION_VIEW)
57             .setDataAndType(uri, "video/*");
58     }
59 }
60