Example usage for android.content Intent addCategory

List of usage examples for android.content Intent addCategory

Introduction

In this page you can find the example usage for android.content Intent addCategory.

Prototype

public @NonNull Intent addCategory(String category) 

Source Link

Document

Add a new category to the intent.

Usage

From source file:com.netcompss.ffmpeg4android_client.BaseWizard.java

protected void startService() {
    if (started) {
        //   Toast.makeText(this, "Service already started", Toast.LENGTH_SHORT).show();
    } else {//from   w  ww .  j a  v  a2s  . c  o m

        Intent i = new Intent("com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge");
        if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            i.setPackage("com.netcompss.ffmpeg4android");
        }
        PackageManager packageManager = getPackageManager();
        List<ResolveInfo> services = packageManager.queryIntentServices(i, 0);
        Log.i(Prefs.TAG, "!!!!!!!!!!!!!!!!!!services.size(): " + services.size());

        if (services.size() > 0) {
            ResolveInfo service = services.get(0);
            i.setClassName(service.serviceInfo.packageName, service.serviceInfo.name);
            i.setAction("com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge");
            if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                i.setPackage("com.netcompss.ffmpeg4android");
            }
            if (!invokeFileInfoServiceFlag) {
                i.addCategory("Base");
                Log.i(Prefs.TAG, "putting Base categoty");
            } else {
                i.addCategory("Info");
                Log.i(Prefs.TAG, "putting Info categoty");
            }

            ComponentName cn = startService(i);
            Log.d(Prefs.TAG, "started: " + cn.getClassName());
        }

        started = true;
        Log.d(Prefs.TAG, "Client startService()");
    }

}

From source file:com.stikyhive.stikyhive.ChattingActivity.java

private void showFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("File/*");

    /*try {/*  w  w  w.  j  a  v a 2  s  . c o m*/
    startActivityForResult(intent, FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
    // Potentially direct the user to the Market with a Dialog
    Toast.makeText(this, "Please install a File Manager.",
            Toast.LENGTH_SHORT).show();
    }*/
    // special intent for Samsung file manager
    Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
    // if you want any file type, you can skip next line
    // sIntent.putExtra("CONTENT_TYPE", "*/*");
    sIntent.addCategory(Intent.CATEGORY_DEFAULT);

    Intent chooserIntent;
    if (getPackageManager().resolveActivity(sIntent, 0) != null) {
        // it is device with samsung file manager
        chooserIntent = Intent.createChooser(sIntent, "Open file");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent });
    } else {
        chooserIntent = Intent.createChooser(intent, "Open file");
    }

    try {
        startActivityForResult(chooserIntent, FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(getApplicationContext(), "No suitable File Manager was found.", Toast.LENGTH_SHORT)
                .show();
    }
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Allows to install a new icon for the application.
 *
 * This method need two additional permissions in the application:
 *
 * <code>//from  w  ww.ja  v  a 2s.  com
 *  <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 * </code>
 *
 * @param context       The application context.
 * @param appMain       The application main class
 * @param appName       The application name
 * @param appIcon       The bitmap of the application icon. Can be null. If null, the
 *                      appIconResId must be provided.
 * @param appIconResId  Specify this only if no bitmap is set in the call to this method.
 */
public static void application_shortcutAdd(Context context, Class appMain, String appName, Bitmap appIcon,
        int appIconResId, boolean removeCurrent) {

    // Intent launcher of the application
    Intent shortcutIntent = new Intent("android.intent.action.MAIN");
    shortcutIntent.addCategory("android.intent.category.LAUNCHER");
    shortcutIntent.setClass(context, appMain);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    //Intent to add the new application icon.
    //
    // Decorate the shortcut
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);

    if (appIcon != null) {
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, appIcon);
    } else if (appIconResId != 0) {
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(context.getApplicationContext(), appIconResId));
    }

    // Inform launcher to create shortcut
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
}

From source file:com.android.leanlauncher.LauncherModel.java

/**
 * Make an ShortcutInfo object for a shortcut that is an application.
 *//*w w  w . j  a  v a  2  s .c  o m*/
public ShortcutInfo getShortcutInfo(Intent intent, UserHandleCompat user, int titleIndex,
        Map<Object, CharSequence> labelCache, boolean allowMissingTarget) {
    if (user == null) {
        Log.d(TAG, "Null user found in getShortcutInfo");
        return null;
    }

    ComponentName componentName = intent.getComponent();
    if (componentName == null) {
        Log.d(TAG, "Missing component found in getShortcutInfo");
        return null;
    }

    Intent newIntent = new Intent(intent.getAction(), null);
    newIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    newIntent.setComponent(componentName);
    LauncherActivityInfoCompat lai = mLauncherApps.resolveActivity(newIntent, user);
    if ((lai == null) && !allowMissingTarget) {
        Log.d(TAG, "Missing activity found in getShortcutInfo: " + componentName);
        return null;
    }

    final ShortcutInfo info = new ShortcutInfo();

    // From the cache.
    if (labelCache != null) {
        info.title = labelCache.get(componentName);
    }

    // from the resource
    if (info.title == null && lai != null) {
        info.title = lai.getLabel();
        if (labelCache != null) {
            labelCache.put(componentName, info.title);
        }
    }
    // from the db
    if (info.title == null) {
        if (mApp.getContext() != null) {
            info.title = mApp.getContext().getString(titleIndex);
        }
    }
    // fall back to the class name of the activity
    if (info.title == null) {
        info.title = componentName.getClassName();
    }
    info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
    info.user = user;
    info.contentDescription = mUserManager.getBadgedLabelForUser(info.title.toString(), info.user);
    return info;
}

From source file:com.gigathinking.simpleapplock.ResetUnlockMethod.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_reset);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    mDialog = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
    mDialog.setIndeterminate(true);// w  ww  .ja  v a2s.c  om
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    mResetReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            prefs.edit().putString(AppLockApplication.LOCKTYPE, AppLockApplication.LOCKTYPE_PIN).commit();
            prefs.edit()
                    .putString(AppLockApplication.PASSWORD, intent.getStringExtra(AppLockApplication.PASSWORD))
                    .commit();
            Toast.makeText(context, getString(R.string.pin_reset), Toast.LENGTH_LONG).show();
            startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
            //startActivity(new Intent(ResetUnlockMethod.this,UnlockWithPIN.class).putExtra("test","test"));
            finish();
        }
    };
    LocalBroadcastManager.getInstance(this).registerReceiver(mResetReceiver,
            new IntentFilter(AppLockApplication.RESET_UNLOCK));

    if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.register_complete),
            false)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getString(R.string.reset_register_device));
        builder.setTitle(getString(R.string.info));
        builder.setPositiveButton(getString(R.string.register), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                new Register().execute();
                if (mDialog != null) {
                    mDialog.setMessage(getString(R.string.register_ongoing));
                    mDialog.show();
                }
                dialog.dismiss();
            }
        });
        builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                finish();
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_HOME);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        });
        builder.create().show();
    } else {
        if (mDialog != null) {
            mDialog.setMessage(getString(R.string.connect_to_server));
            mDialog.show();
        }
        new DoRequestReset().execute();
    }
}

From source file:com.hichinaschool.flashcards.anki.DeckPicker.java

/**
 * Creates an intent to load a deck given the full pathname of it. The constructed intent is equivalent (modulo the
 * extras) to the open used by the launcher shortcut, which means it will not open a new study options window but
 * bring the existing one to the front./*from  w w w.ja va  2 s.c  o  m*/
 */
public static Intent getLoadDeckIntent(Context context, long deckId) {
    Intent loadDeckIntent = new Intent(context, DeckPicker.class);
    loadDeckIntent.setAction(Intent.ACTION_MAIN);
    loadDeckIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    loadDeckIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    loadDeckIntent.putExtra(EXTRA_DECK_ID, deckId);
    return loadDeckIntent;
}

From source file:com.dish.browser.activity.BrowserActivity.java

@Override
/**/* www. j a  v a 2  s.c o m*/
 * opens a file chooser
 * param ValueCallback is the message from the WebView indicating a file chooser
 * should be opened
 */
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
    mUploadMessage = uploadMsg;
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("*/*");
    startActivityForResult(Intent.createChooser(i, getString(R.string.title_file_chooser)), 1);
}

From source file:dentex.youtube.downloader.DashboardActivity.java

private void reDownload(DashboardListItem currentItem, String category) {
    String ytLink = "http://www.youtube.com/watch?v=" + currentItem.getYtId();
    Intent rdIntent = new Intent(this, ShareActivity.class);
    rdIntent.setData(Uri.parse(ytLink));
    rdIntent.addCategory(category);
    rdIntent.putExtra("id", currentItem.getId());
    rdIntent.putExtra("position", currentItem.getPos());
    rdIntent.putExtra("filename", currentItem.getFilename());
    rdIntent.setAction(Intent.ACTION_VIEW);
    //rdIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(rdIntent);//from  ww  w . j a v  a2 s  .  c  om
}

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

public void OpenFile(View view) {

    if (Device.hasKitKatApi() && PreferenceHelper.getUseStorageAccessFramework(this)) {
        // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
        // browser.
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

        // Filter to only show results that can be "opened", such as a
        // file (as opposed to a list of contacts or timezones)
        intent.addCategory(Intent.CATEGORY_OPENABLE);

        // Filter to show only images, using the image MIME data type.
        // If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
        // To search for all documents available via installed storage providers,
        // it would be "*/*".
        intent.setType("*/*");/*from   ww w. jav a  2s .c  o  m*/

        startActivityForResult(intent, READ_REQUEST_CODE);
    } else {
        Intent subActivity = new Intent(MainActivity.this, SelectFileActivity.class);
        subActivity.putExtra("action", SelectFileActivity.Actions.SelectFile);
        AnimationUtils.startActivityWithScale(this, subActivity, true, SELECT_FILE_CODE, view);
    }
}

From source file:com.dish.browser.activity.BrowserActivity.java

@Override
public void showFileChooser(ValueCallback<Uri[]> filePathCallback) {
    if (mFilePathCallback != null) {
        mFilePathCallback.onReceiveValue(null);
    }//from  w  w w. j  a  v a  2  s . c o m
    mFilePathCallback = filePathCallback;

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = Utils.createImageFile();
            takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
        } catch (IOException ex) {
            // Error occurred while creating the File
            Log.e(Constants.TAG, "Unable to create Image File", ex);
        }

        // Continue only if the File was successfully created
        if (photoFile != null) {
            mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
        } else {
            takePictureIntent = null;
        }
    }

    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.setType("image/*");

    Intent[] intentArray;
    if (takePictureIntent != null) {
        intentArray = new Intent[] { takePictureIntent };
    } else {
        intentArray = new Intent[0];
    }

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

    mActivity.startActivityForResult(chooserIntent, 1);
}