IntentHelper

1827 ワード

public class IntentHelper {

    /**
     *  ( )
     * 
     * @param context
     *            : 
     * @param targetPakageName
     *            : com.android.deskclock
     * @param targetClassFullName
     *            : com.android.deskclock.AlarmClock
     */
    public static void startActivityByComponentName(Context context, String targetPakageName, String targetClassFullName) {
        Intent intent = new Intent();
        ComponentName componentName = new ComponentName(targetPakageName, targetClassFullName);
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction("android.intent.action.VIEW");
        context.startActivity(intent);
    }

    /**
     *  action , action 
     */
    public static void sendActionToBroadcast(Context context, String action) {
        Intent intent = new Intent(action);
        context.sendBroadcast(intent);
    }

    /**
     *  , 
     * 
     * @param context
     * @param packageName
     *             
     * @param classFullName
     *             service 
     */
    @SuppressLint("InlinedApi")
    public static void startLiveWallpaperPrevivew(Context context, String packageName, String classFullName) {
        ComponentName componentName = new ComponentName(packageName, classFullName);
        Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
        intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, componentName);
        context.startActivity(intent);
    }
}