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.fvd.nimbus.MainActivity.java

public void onButtonClick(View v) {
    switch (v.getId()) {
    case R.id.bTakePhoto:
        showProgress(true);//w w w  .j  av  a2 s. c  o m
        getPhoto();
        break;
    case R.id.bFromGallery:
        try {
            showProgress(true);
            Intent fileChooserIntent = new Intent();
            fileChooserIntent.addCategory(Intent.CATEGORY_OPENABLE);
            fileChooserIntent.setType("image/*");
            fileChooserIntent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(fileChooserIntent, "Select Picture"), TAKE_PICTURE);
        } catch (Exception e) {
            appSettings.appendLog("main:onClick  " + e.getMessage());
            showProgress(false);
        }
        break;
    case R.id.bWebClipper:
        Intent iBrowse = new Intent();
        iBrowse.setClassName("com.fvd.nimbus", "com.fvd.nimbus.BrowseActivity");
        startActivity(iBrowse);
        //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
        overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
        break;
    case R.id.bPdfAnnotate:
        Intent ip = new Intent();
        ip.setClassName("com.fvd.nimbus", "com.fvd.nimbus.ChoosePDFActivity");
        startActivity(ip);
        //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
        overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
        break;
    case R.id.ibSettings:
        Intent inten = new Intent(getApplicationContext(), SettingsActivity.class);
        startActivityForResult(inten, SHOW_SETTINGS);
        //overridePendingTransition(R.anim.carbon_slide_in,R.anim.carbon_slide_out);
        overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
        break;
    /*case R.id.bssSettings:
       Intent i = new Intent(getApplicationContext(), PrefsActivity.class);
        startActivity(i);
        overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
       break;
    case R.id.bssRegister:
       Intent intent = new Intent(getApplicationContext(), RegisterDlg.class);
       intent.putExtra("userMail", userMail==null?"":userMail);
       startActivityForResult(intent, 5);
       overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
       break;   
    case R.id.bssHelp:
       Uri uri = Uri.parse("http://help.everhelper.me/customer/portal/articles/1376820-nimbus-clipper-for-android---quick-guide");
       Intent it = new Intent(Intent.ACTION_VIEW, uri);
       startActivity(it);
       overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
       break;
    case R.id.bssLogin:
       if(serverHelper.getInstance().getSession().length() == 0) showLogin();
       else {
     String sessionId="";
     serverHelper.getInstance().setSessionId(sessionId);
     appSettings.storeUserData(this, userMail, "", "");
     Editor e = prefs.edit();
     e.putString("userMail", userMail);
       e.putString("userPass", "");
       e.putString("sessionId", sessionId);
       e.commit();
     showLogin();
     }
       break;
    case R.id.bssRateUs:
       try{
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getApplicationInfo().packageName)));
    }
    catch(Exception e){
    }
       break;*/
    }
}

From source file:ca.rmen.android.scrumchatter.main.MainActivity.java

private void startFileChooser() {
    final Intent importIntent;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
        importIntent = new Intent(Intent.ACTION_GET_CONTENT);
    else/*from   ww  w . j  a v  a2s  .co  m*/
        importIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    importIntent.setType("*/*");
    importIntent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(Intent.createChooser(importIntent, getResources().getText(R.string.action_import)),
            ACTIVITY_REQUEST_CODE_IMPORT);
}

From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java

@SuppressWarnings("deprecation")
private void generateMenu() {
    if (isStartButton) {
        addPreferencesFromResource(R.xml.pref_context_menu_open_settings);
        findPreference("open_taskbar_settings").setOnPreferenceClickListener(this);
        findPreference("start_menu_apps").setOnPreferenceClickListener(this);

        if (U.launcherIsDefault(this) && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
            addPreferencesFromResource(R.xml.pref_context_menu_change_wallpaper);
            findPreference("change_wallpaper").setOnPreferenceClickListener(this);
        }/*www  . j  a va 2s.c om*/

        if (!getIntent().getBooleanExtra("dont_show_quit", false)) {
            addPreferencesFromResource(R.xml.pref_context_menu_quit);
            findPreference("quit_taskbar").setOnPreferenceClickListener(this);
        }
    } else if (isOverflowMenu) {
        if (getResources().getConfiguration().screenWidthDp >= 600
                && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M)
            setTitle(R.string.tools);
        else {
            addPreferencesFromResource(R.xml.pref_context_menu_header);
            findPreference("header").setTitle(R.string.tools);
        }

        addPreferencesFromResource(R.xml.pref_context_menu_overflow);
        findPreference("volume").setOnPreferenceClickListener(this);
        findPreference("system_settings").setOnPreferenceClickListener(this);
        findPreference("lock_device").setOnPreferenceClickListener(this);
        findPreference("power_menu").setOnPreferenceClickListener(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            findPreference("file_manager").setOnPreferenceClickListener(this);
        else
            getPreferenceScreen().removePreference(findPreference("file_manager"));
    } else {
        appName = getIntent().getStringExtra("app_name");
        packageName = getIntent().getStringExtra("package_name");
        componentName = getIntent().getStringExtra("component_name");
        userId = getIntent().getLongExtra("user_id", 0);

        if (getResources().getConfiguration().screenWidthDp >= 600
                && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M)
            setTitle(appName);
        else {
            addPreferencesFromResource(R.xml.pref_context_menu_header);
            findPreference("header").setTitle(appName);
        }

        SharedPreferences pref = U.getSharedPreferences(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                && !U.isGame(this, packageName)) {
            addPreferencesFromResource(R.xml.pref_context_menu_show_window_sizes);
            findPreference("show_window_sizes").setOnPreferenceClickListener(this);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            int shortcutCount = getLauncherShortcuts();

            if (shortcutCount > 1) {
                addPreferencesFromResource(R.xml.pref_context_menu_shortcuts);
                findPreference("app_shortcuts").setOnPreferenceClickListener(this);
            } else if (shortcutCount == 1)
                generateShortcuts();
        }

        final PackageManager pm = getPackageManager();
        Intent homeIntent = new Intent(Intent.ACTION_MAIN);
        homeIntent.addCategory(Intent.CATEGORY_HOME);
        ResolveInfo defaultLauncher = pm.resolveActivity(homeIntent, PackageManager.MATCH_DEFAULT_ONLY);

        if (!packageName.contains(BuildConfig.BASE_APPLICATION_ID)
                && !packageName.equals(defaultLauncher.activityInfo.packageName)) {
            PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this);

            if (pba.isPinned(componentName)) {
                addPreferencesFromResource(R.xml.pref_context_menu_pin);
                findPreference("pin_app").setOnPreferenceClickListener(this);
                findPreference("pin_app").setTitle(R.string.unpin_app);
            } else if (pba.isBlocked(componentName)) {
                addPreferencesFromResource(R.xml.pref_context_menu_block);
                findPreference("block_app").setOnPreferenceClickListener(this);
                findPreference("block_app").setTitle(R.string.unblock_app);
            } else {
                final int MAX_NUM_OF_COLUMNS = U.getMaxNumOfEntries(this);

                if (pba.getPinnedApps().size() < MAX_NUM_OF_COLUMNS) {
                    addPreferencesFromResource(R.xml.pref_context_menu_pin);
                    findPreference("pin_app").setOnPreferenceClickListener(this);
                    findPreference("pin_app").setTitle(R.string.pin_app);
                }

                addPreferencesFromResource(R.xml.pref_context_menu_block);
                findPreference("block_app").setOnPreferenceClickListener(this);
                findPreference("block_app").setTitle(R.string.block_app);
            }
        }

        addPreferencesFromResource(R.xml.pref_context_menu);

        findPreference("app_info").setOnPreferenceClickListener(this);
        findPreference("uninstall").setOnPreferenceClickListener(this);
    }
}

From source file:com.vyasware.vaani.MainActivity.java

private void doOpen(String[] sentence) {
    System.out.println("open");
    for (String word : sentence) {
        switch (word) {
        //? ???  
        case "?":
        case "facebook":
            //open facebook
            Intent fbintent = new Intent();
            fbintent.setAction(Intent.ACTION_VIEW);
            fbintent.setData(android.net.Uri.parse("http://www.facebook.com"));
            startActivity(fbintent);//w w w  . j  a va 2 s  .c om
            break;
        case "whatsapp":
        case "???":
            //todo run whatsapp
            break;
        case "camera":
        case "":
        case "":
            //open camera
            Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            try {
                PackageManager pm = getPackageManager();

                final ResolveInfo mInfo = pm.resolveActivity(i, 0);

                Intent intent = new Intent();
                intent.setComponent(new ComponentName(mInfo.activityInfo.packageName, mInfo.activityInfo.name));
                intent.setAction(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);

                startActivity(intent);
            } catch (Exception e) {
                Log.i("open", "Unable to launch camera: " + e);
            }
            break;
        case "browser":
        case "?":
            // open browser
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(android.net.Uri.parse("http://www.google.com"));
            startActivity(intent);
            break;
        case "youtube":
        case "???":
            //run youtube
            Intent ytintent = new Intent();
            ytintent.setAction(Intent.ACTION_VIEW);
            ytintent.setData(android.net.Uri.parse("http://www.youtube.com"));
            startActivity(ytintent);
            break;

        }
    }

}

From source file:com.goftagram.telegram.messenger.NotificationsController.java

private static String getLauncherClassName(Context context) {
    try {/*from  ww w.  j a v a2s.  c o  m*/
        PackageManager pm = context.getPackageManager();

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
        for (ResolveInfo resolveInfo : resolveInfos) {
            String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
            if (pkgName.equalsIgnoreCase(context.getPackageName())) {
                return resolveInfo.activityInfo.name;
            }
        }
    } catch (Throwable e) {
        FileLog.e("tmessages", e);
    }
    return null;
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void updateClock(Context context, AppWidgetManager appWidgetManager, int appWidgetId, float ratio) {
    RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);

    // Launch setinngs when clicking on the time in the widget only if not a lock screen widget
    Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
    if (newOptions != null && newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
            -1) != AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) {
        Intent mIntent = new Intent(Intent.ACTION_MAIN);
        mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName component = new ComponentName("com.android.settings", "com.android.settings.Settings");
        mIntent.setComponent(component);
        widget.setOnClickPendingIntent(R.id.digital_appwidget,
                PendingIntent.getActivity(context, 0, mIntent, 0));
    }/* w w w  . j a  v a2 s .  c o  m*/

    //cg sai.pan begin
    refreshWifiStatus(context, widget);
    refreshBtStatus(context, widget);
    refreshAirplaneStatus(context, widget,
            Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0);
    mLocationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
    refreshGpsStatus(context, widget, mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
    //refreshDataStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.MOBILE_DATA, 0) != 0);
    requestLocation(context);
    //cg sai.pan end

    // SPRD for bug421127 add am/pm for widget
    WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
            R.id.the_clock);
    WidgetUtils.setClockSize(context, widget, ratio);

    // Set today's date format
    CharSequence dateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(),
            context.getString(R.string.abbrev_wday_month_day_no_year));
    widget.setCharSequence(R.id.date, "setFormat12Hour", dateFormat);
    widget.setCharSequence(R.id.date, "setFormat24Hour", dateFormat);

    appWidgetManager.updateAppWidget(appWidgetId, widget);
}

From source file:com.bridgeconn.autographago.ui.activities.SettingsActivity.java

@Override
public void onRequestPermissionsResult(final int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    switch (requestCode) {
    case Constants.RequestCodes.PERMISSION_STORAGE: {
        if (ContextCompat.checkSelfPermission(SettingsActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {

            startDownload(downloadUrl);/*  w  w  w. ja va 2  s  . c  om*/

        } else {
            String positiveButton;
            if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                positiveButton = getString(R.string.take_me_to_settings).toUpperCase();
            } else {
                positiveButton = getString(R.string.try_again).toUpperCase();
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(SettingsActivity.this,
                    R.style.DialogThemeLight);
            builder.setMessage(getString(R.string.storage_permission_message));
            builder.setPositiveButton(positiveButton, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                        Intent myAppSettings = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                                Uri.parse("package:" + SettingsActivity.this.getPackageName()));
                        myAppSettings.addCategory(Intent.CATEGORY_DEFAULT);
                        startActivityForResult(myAppSettings, Constants.RequestCodes.APP_SETTINGS_STORAGE);
                    } else {
                        ActivityCompat.requestPermissions(SettingsActivity.this,
                                new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, requestCode);
                    }
                }
            });
            builder.setNegativeButton(getString(R.string.cancel).toUpperCase(),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
            builder.show();
        }
        break;
    }
    }
}

From source file:net.evecom.android.web.Web0Activity.java

public Intent getFileIntent(File file) {
    // Uri uri = Uri.parse("http://m.ql18.com.cn/hpf10/1.pdf");
    Uri uri = Uri.fromFile(file);//from ww  w .  j  a  v a  2  s  . c  o m
    String type = getMIMEType(file);
    Log.i("tag", "type=" + type);
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(uri, type);
    return intent;
}

From source file:com.air.mobilebrowser.BrowserActivity.java

/**
 * Determine if the application is set as the default
 * home./* w ww.j  a  v a  2s .c o m*/
 * @return true if the default home package is the secure browser, false
 * otherwise.
 */
public boolean validateHomePackage() {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);

    PackageManager pm = getPackageManager();
    final ResolveInfo mInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
    String homePackage = mInfo.activityInfo.packageName;
    return homePackage.equals(getPackageName());
}

From source file:com.example.alyshia.customsimplelauncher.MainActivity.java

private void initUI() {

    mSpaceFrag.add(new AppsGridFragment());
    mSpaceFrag.add(new AppsGridFragment());

    mPagerAdapter = new workSpacePagerAdapter(getSupportFragmentManager());
    workSpaces.setAdapter(mPagerAdapter);

    Intent intent_ = new Intent(Intent.ACTION_MAIN, null);
    intent_.addCategory(Intent.CATEGORY_LAUNCHER);
    mPM = getPackageManager();//from  ww w . j  av a2  s  . c  om
    apps = mPM.queryIntentActivities(intent_, 0);
    apps_package = new ArrayList<>();
    optionalApps = new ArrayList<>();
    knoxappPrefs = getSharedPreferences(KnoxConstants.PREFS_KNOX, MODE_PRIVATE);
    knoxappPrefsEditor = knoxappPrefs.edit();

}