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.example.android.pharmacyinventory.EditorActivity.java

public void openImageSelector() {
    Intent intent;

    if (Build.VERSION.SDK_INT < 19) {
        intent = new Intent(Intent.ACTION_GET_CONTENT);
    } else {//from   w w  w .ja  va 2 s  .c om
        intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    }

    intent.setType("image/*");
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}

From source file:com.spydiko.rotationmanager.MainActivity.java

public void updateApps() {
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "0");
    Intent localIntent = new Intent("android.intent.action.MAIN", null);
    localIntent.addCategory("android.intent.category.LAUNCHER");
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "1");
    packageManager = getPackageManager();
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "2");
    List<ResolveInfo> rInfo = packageManager.queryIntentActivities(localIntent, 1);
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "3");
    List<ApplicationInfo> packages = new ArrayList<ApplicationInfo>();
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "4");
    for (ResolveInfo info : rInfo) {
        packages.add(info.activityInfo.applicationInfo);
    }/*from w  w  w.  j  a  v a  2 s  . c  o m*/
    Model temp;
    for (ApplicationInfo packageInfo : packages) {
        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Installed package :" + packageInfo.packageName);
        if (names.contains(packageInfo.packageName)) {
            continue;
        }
        names.add(packageInfo.packageName);
        temp = new Model((String) packageManager.getApplicationLabel(packageInfo));
        temp.setPackageName(packageInfo.packageName);
        Drawable pic = packageInfo.loadIcon(packageManager);
        temp.setLabel(pic);
        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Installed package :" + temp.getName());
        //temp.put(IS_CHECKED, true);
        if (myapp.loadPreferences(packageInfo.packageName, true))
            temp.setSelectedPortrait(true);
        if (myapp.loadPreferences(packageInfo.packageName, false))
            temp.setSelectedLandscape(true);
        activities.add(temp);

        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Launch Activity :" + packageManager.getLaunchIntentForPackage(packageInfo.packageName));
    }
    // Search and show launchers
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    final ResolveInfo res = packageManager.resolveActivity(intent, 0);
    if (res.activityInfo == null) {
        // should not happen. A home is always installed, isn't it?
    } else if (!names.contains(res.activityInfo.applicationInfo.packageName)) {
        names.add(res.activityInfo.applicationInfo.packageName);
        Model launcher = new Model(
                (String) packageManager.getApplicationLabel(res.activityInfo.applicationInfo));
        launcher.setPackageName(res.activityInfo.applicationInfo.packageName);
        Drawable launcher_pic = res.activityInfo.applicationInfo.loadIcon(packageManager);
        launcher.setLabel(launcher_pic);
        if (myapp.loadPreferences(res.activityInfo.applicationInfo.packageName, true))
            launcher.setSelectedPortrait(true);
        if (myapp.loadPreferences(res.activityInfo.applicationInfo.packageName, false))
            launcher.setSelectedLandscape(true);
        activities.add(launcher);
    }
    if (!names.contains("com.android.phone")) {
        names.add("com.android.phone");
        Model phone = new Model("Phone During Call");
        phone.setPackageName("com.android.phone");
        Drawable ic_phone = getResources().getDrawable(R.drawable.ic_phone);
        phone.setLabel(ic_phone);
        if (myapp.loadPreferences("com.android.phone", true))
            phone.setSelectedPortrait(true);
        if (myapp.loadPreferences("com.android.phone", false))
            phone.setSelectedLandscape(true);
        activities.add(phone);
    }

    Collections.sort(activities, new SortByString());

    Collections.sort(activities, new SortByCheck());

    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "END");
}

From source file:org.ohthehumanity.carrie.CarrieActivity.java

/** Called when the activity is first created. */
@Override/*w w  w  .  j av a  2s.  c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mServerName = "";
    setContentView(R.layout.main);

    // instantiate our preferences backend
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // set callback function when settings change
    mPreferences.registerOnSharedPreferenceChangeListener(this);

    if (mPreferences.getString("server", null) == null) {
        setStatus("Server not set");
    } else if (mPreferences.getString("port", null) == null) {
        setStatus("Port not configured");
    }

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm.getActiveNetworkInfo().getType() != ConnectivityManager.TYPE_WIFI) {

        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
        dlgAlert.setTitle("WiFi not active");
        dlgAlert.setMessage(
                "This application is usually used on a local network over a WiFi. Open WiFi settings?");
        dlgAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    //Yes button clicked
                    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    final ComponentName cn = new ComponentName("com.android.settings",
                            "com.android.settings.wifi.WifiSettings");
                    intent.setComponent(cn);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    //Log.i(TAG, "Not opening wifi");
                    //No button clicked
                    break;
                }
            }
        });

        dlgAlert.setNegativeButton("No", null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
    }

    updateTitle();
    updateSkipLabels();
    updateServerName();
}

From source file:biz.bokhorst.bpt.BPTService.java

private Notification getNotification(String text) {
    // Build intent
    Intent toLaunch = new Intent(this, BackPackTrack.class);
    toLaunch.setAction("android.intent.action.MAIN");
    toLaunch.addCategory("android.intent.category.LAUNCHER");
    toLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    // Build pending intent
    PendingIntent intentBack = PendingIntent.getActivity(this, 0, toLaunch, PendingIntent.FLAG_UPDATE_CURRENT);

    // Build result intent update
    Intent resultIntentUpdate = new Intent(this, BPTService.class);
    resultIntentUpdate.setAction("Update");

    // Build pending intent waypoint
    PendingIntent pendingIntentUpdate = PendingIntent.getService(this, 2, resultIntentUpdate,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Build result intent waypoint
    Intent resultIntentWaypoint = new Intent(this, BPTService.class);
    resultIntentWaypoint.setAction("Waypoint");

    // Build pending intent waypoint
    PendingIntent pendingIntentWaypoint = PendingIntent.getService(this, 2, resultIntentWaypoint,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Build notification
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setSmallIcon(R.drawable.icon);
    notificationBuilder.setContentTitle(getString(R.string.app_name));
    notificationBuilder.setContentText(text);
    notificationBuilder.setContentIntent(intentBack);
    notificationBuilder.setWhen(System.currentTimeMillis());
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.addAction(android.R.drawable.ic_menu_mylocation, getString(R.string.Update),
            pendingIntentUpdate);/*from   ww  w.  j a  va  2  s .c  o m*/
    notificationBuilder.addAction(android.R.drawable.ic_menu_add, getString(R.string.Waypoint),
            pendingIntentWaypoint);
    Notification notification = notificationBuilder.build();
    return notification;
}

From source file:com.tenforwardconsulting.cordova.BackgroundGeolocationPlugin.java

public void showAppSettings() {
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(Uri.parse("package:" + getContext().getPackageName()));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    getContext().startActivity(intent);//from www. j ava 2  s.  co m
}

From source file:com.novemser.voicetest.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_template);

    initView();//ww  w . java2  s  . co m
    //test.db?
    db = openOrCreateDatabase("alarm.db", Context.MODE_PRIVATE, null);

    mAdapter = new ListMessageAdapter(this, mDatas);
    mChatView.setAdapter(mAdapter);
    packageManager = getPackageManager();

    // Context
    BaseAction.context = getApplicationContext();

    SpeechUtility.createUtility(getApplicationContext(), SpeechConstant.APPID + "=573d5744");
    //1.RecognizerDialog
    mDialog = new RecognizerDialog(this, null);
    mIat = SpeechRecognizer.createRecognizer(getApplicationContext(), null);
    //2.accent? language?
    mDialog.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
    mDialog.setParameter(SpeechConstant.ACCENT, "mandarin");

    //?UI???onResult?
    //

    //         mDialog.setParameter("asr_sch", "1");
    //         mDialog.setParameter("nlp_version", "2.0");
    //3.?
    mDialog.setListener(new RecognizerDialogListener() {
        @Override
        public void onResult(RecognizerResult recognizerResult, boolean b) {
            Log.d("VoiceResult", recognizerResult.getResultString());
            printResult(recognizerResult);
        }

        @Override
        public void onError(SpeechError speechError) {

        }
    });

    // 4.
    mStartVoiceRecord.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //dialog
            mDialog.show();
        }
    });

    // ?TTS
    initTTS();

    // 5.??
    understander = TextUnderstander.createTextUnderstander(this, null);

    // 6.???
    SharedPreferences sharedPreferences = getSharedPreferences("user", MODE_PRIVATE);

    if (!sharedPreferences.getBoolean("isContactUploaded", false)) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        ContactManager manager = ContactManager.createManager(this, contactListener);
        manager.asyncQueryAllContactsName();
        editor.putBoolean("isContactUploaded", true);
        editor.apply();
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.title_toolbar));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        toolbar.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
    }
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    new Thread(new Runnable() {
        /**
         * ?
         */
        @Override
        public void run() {
            //?
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            resolveInfoList = packageManager.queryIntentActivities(mainIntent, 0);
            //???
            Collections.sort(resolveInfoList, new ResolveInfo.DisplayNameComparator(packageManager));
            for (ResolveInfo res : resolveInfoList) {
                String pkg = res.activityInfo.packageName;
                String cls = res.activityInfo.name;
                String name = res.loadLabel(packageManager).toString();
                Log.d("ApplicationInfo:", "Pkg:" + pkg + "   Class:" + cls + "   Name:" + name);
            }
        }
    }).start();

    // ?
    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).build();
}

From source file:com.danvelazco.fbwrapper.activity.BaseFacebookWebViewActivity.java

/**
 * {@inheritDoc}// ww w  .ja  va  2 s .c  o  m
 */
@Override
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
    Logger.d(LOG_TAG, "openFileChooser()");
    mUploadMessage = uploadMsg;
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("image/*");
    startActivityForResult(Intent.createChooser(i, getString(R.string.upload_file_choose)),
            RESULT_CODE_FILE_UPLOAD);
}

From source file:info.guardianproject.otr.app.im.app.WelcomeActivity.java

Intent getEditAccountIntent() {
    Intent intent = new Intent(Intent.ACTION_EDIT, ContentUris.withAppendedId(Imps.Account.CONTENT_URI,
            mProviderCursor.getLong(ACTIVE_ACCOUNT_ID_COLUMN)));
    intent.putExtra("isSignedIn", isSignedIn(mProviderCursor));
    intent.addCategory(getProviderCategory(mProviderCursor));
    return intent;
}

From source file:br.com.anteros.vendas.gui.AnexoCadastroActivity.java

/**
 * Seleciona outros tipos de arquivos para anexar
 *//* w ww  .  j  a v  a2s . c om*/
private void selecionarOutrosTiposArquivo() {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("file/*");
    startActivityForResult(Intent.createChooser(intent, "Selecione"), SELECIONAR_ARQUIVO);
}

From source file:com.anjalimacwan.MainActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private void reallyExportNote() {
    String filename = "";

    try {//from w ww . ja v a2 s  .  com
        filename = loadNoteTitle(filesToExport[fileBeingExported].toString());
    } catch (IOException e) {
        /* Gracefully fail */ }

    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TITLE, generateFilename(filename));

    try {
        startActivityForResult(intent, EXPORT);
    } catch (ActivityNotFoundException e) {
        showToast(R.string.error_exporting_notes);
    }
}