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.RITW.proximity.FeaturesActivity.java

private void setupPluginsInDrawer(final ViewGroup container) {
    final LayoutInflater inflater = LayoutInflater.from(this);
    final PackageManager pm = getPackageManager();

    // look for Master Control Panel
    final Intent mcpIntent = new Intent(Intent.ACTION_MAIN);
    mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS);
    final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0);

    // configure link to Master Control Panel
    //final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp);
    if (mcpInfo == null) {
        //   mcpItem.setTextColor(Color.GRAY);
        ColorMatrix grayscale = new ColorMatrix();
        grayscale.setSaturation(0.0f);/*from  www.j a v a  2  s .c  o  m*/
        //   mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale));
    }
    /*mcpItem.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(final View v) {
    Intent action = mcpIntent;
    if (mcpInfo == null)
       action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI));
    action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    try {
       startActivity(action);
    } catch (final ActivityNotFoundException e) {
       Toast.makeText(FeaturesActivity.this, R.string.no_application_play, Toast.LENGTH_SHORT).show();
    }
    mDrawerLayout.closeDrawers();
       }
    });*/

    // look for other plug-ins
    final Intent utilsIntent = new Intent(Intent.ACTION_MAIN);
    utilsIntent.addCategory(UTILS_CATEGORY);

    final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0);
    for (final ResolveInfo info : appList) {
        final View item = inflater.inflate(R.layout.drawer_plugin, container, false);
        final ImageView icon = (ImageView) item.findViewById(android.R.id.icon);
        final TextView label = (TextView) item.findViewById(android.R.id.text1);

        label.setText(info.loadLabel(pm));
        icon.setImageDrawable(info.loadIcon(pm));
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final Intent intent = new Intent();
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
                mDrawerLayout.closeDrawers();
            }
        });
        container.addView(item);
    }
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == android.R.id.home) {
        finish();/*from  w  ww.  j a va  2s . co m*/
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.petri.myapplication.GCMMessageListenerService.java

/**
 * Called when message is received./*from www. j  a  v  a  2s. c om*/
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    String message = data.getString("message");
    int from_id = Integer.parseInt(data.getString("from_id"));
    int to_id = Integer.parseInt(data.getString("to_id"));
    Log.d(TAG, "From: " + from);
    Log.d(TAG, "Message: " + message);
    DatabaseHelper helper = new DatabaseHelper(this);
    SQLiteDatabase db = helper.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put("message", message);
    values.put("from_id", from_id);
    values.put("to_id", to_id);

    // Insert the new row, returning the primary key value of the new row
    long newRowId;
    newRowId = db.insert("messages", "message_id", values);
    String strSQL = "UPDATE chats SET last_activity = CURRENT_TIMESTAMP WHERE user_id = " + from_id;
    db.execSQL(strSQL);

    //        SQLiteDatabase dbr = helper.getReadableDatabase();

    //        Cursor cursor = dbr.query(false, "messages", new String[]{"message"}, null, null, null, null, null, null);
    //        cursor.moveToLast();
    //        String this_message = cursor.getString(
    //                cursor.getColumnIndexOrThrow("message")
    //        );
    //        Log.d("mygcm", this_message);

    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction(ChatActivity.MessageResponseReceiver.ACTION_RESP);
    broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
    broadcastIntent.putExtra("from_id", from_id);
    LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);

    //        SQLiteDatabase mydatabase =
    //        mydatabase.execSQL("CREATE TABLE IF NOT EXISTS messages(message_id INT auto_increment, message TEXT, primary key(message_id));");
    //        mydatabase.execSQL("INSERT INTO TutorialsPoint VALUES('null','" + message + "');");
    /**
     * Production applications would usually process the message here.
     * Eg: - Syncing with server.
     *     - Store message in local database.
     *     - Update UI.
     */

    /**
     * In some cases it may be useful to show a notification indicating to the user
     * that a message was received.
     */
    sendNotification(message, from_id);
}

From source file:com.guodong.sun.guodong.activity.MainActivity.java

@Override
public void onBackPressed() {
    if (JCVideoPlayer.backPress())
        return;/*from   w w  w . j  a va 2 s . c o m*/

    if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        mDrawerLayout.closeDrawers();
    } else {
        Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
        launcherIntent.addCategory(Intent.CATEGORY_HOME);
        startActivity(launcherIntent);
        //            if ((System.currentTimeMillis() - exitTime) > 2000) {
        //                Toast.makeText(MainActivity.this, "?", Toast.LENGTH_SHORT).show();
        //                exitTime = System.currentTimeMillis();
        //            } else {
        //                String size = GlideCacheUtil.getInstance().getCacheSize(MainActivity.this);
        //                if (Double.valueOf(size.substring(0, size.length() - 2)) >= 50)
        //                    GlideCacheUtil.getInstance().clearImageAllCache(MainActivity.this);
        //                super.onBackPressed();
        //            }
    }
}

From source file:com.example.qrcode.BarcodeScanner.java

/**
 * Starts an intent to scan and decode a barcode.
 *///  w  w w .java  2s .c  o  m
public void scan(JSONArray args) {
    Intent intentScan = new Intent(SCAN_INTENT);
    intentScan.addCategory(Intent.CATEGORY_DEFAULT);

    // add config as intent extras
    if (args.length() > 0) {

        JSONObject obj;
        JSONArray names;
        String key;
        Object value;

        for (int i = 0; i < args.length(); i++) {

            try {
                obj = args.getJSONObject(i);
            } catch (JSONException e) {
                Log.i("CordovaLog", e.getLocalizedMessage());
                continue;
            }

            names = obj.names();
            for (int j = 0; j < names.length(); j++) {
                try {
                    key = names.getString(j);
                    value = obj.get(key);

                    if (value instanceof Integer) {
                        intentScan.putExtra(key, (Integer) value);
                    } else if (value instanceof String) {
                        intentScan.putExtra(key, (String) value);
                    }

                } catch (JSONException e) {
                    Log.i("CordovaLog", e.getLocalizedMessage());
                    continue;
                }
            }
        }

    }

    // avoid calling other phonegap apps
    intentScan.setPackage(this.cordova.getActivity().getApplicationContext().getPackageName());

    this.cordova.startActivityForResult((CordovaPlugin) this, intentScan, REQUEST_CODE);
}

From source file:com.appmanager.parimal.activity.MainActivity.java

private void loadApps() {

    manager = this.getPackageManager();
    apps = new ArrayList<AppDetail>();

    Intent i = new Intent(Intent.ACTION_MAIN, null);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    AppEntryDBHelper mDbHelper = new AppEntryDBHelper(getApplicationContext());
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    List<ResolveInfo> availableActivities = manager.queryIntentActivities(i, 0);
    for (ResolveInfo ri : availableActivities) {
        if (!ri.activityInfo.packageName.matches("com.appmanager.parimal")) {
            AppDetail app = new AppDetail();
            app.setLabel(ri.loadLabel(manager));
            app.setName(ri.activityInfo.packageName);
            app.setIcon(ri.activityInfo.loadIcon(manager));
            apps.add(app);//from ww  w  . j  a  v a  2 s.c  o  m
            ContentValues values = new ContentValues();
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_NAME, ri.loadLabel(manager).toString());
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_PACKAGE, ri.activityInfo.packageName);
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_CATEGORY, "Uncategorized");
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_PIN, "0000");
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_PIN_USE, "false");
            values.put(AppsReaderContract.AppEntry.COLUMN_APP_USAGE, "0");

            long newRowId;
            newRowId = db.insert(AppsReaderContract.AppEntry.TABLE_NAME, null, values);
        }

    }
    db.close();
}

From source file:com.doomy.decode.ResultDialogFragment.java

private void createURLIntent(String myURL) {
    Intent mIntent = new Intent();
    mIntent.setAction(Intent.ACTION_VIEW);
    mIntent.addCategory(Intent.CATEGORY_BROWSABLE);
    mIntent.setData(Uri.parse(myURL));//from  w  ww . j  a v a  2s. c  o  m
    startActivity(mIntent);
}

From source file:com.example.android.notepad.NotesList.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    //final boolean haveItems = getListAdapter().getCount() > 0;
    boolean haveItems = true;

    // If there are any notes in the list (which implies that one of
    // them is selected), then we need to generate the actions that
    // can be performed on the current selection.  This will be a combination
    // of our own specific actions along with any extensions that can be
    // found.//w  ww .j av a2 s.  c o  m
    if (haveItems) {
        // This is the selected item.
        Uri uri = ContentUris.withAppendedId(getIntent().getData(), getSelectedItemId());

        // Build menu...  always starts with the EDIT action...
        Intent[] specifics = new Intent[1];
        specifics[0] = new Intent(Intent.ACTION_EDIT, uri);
        MenuItem[] items = new MenuItem[1];

        // ... is followed by whatever other actions are available...
        Intent intent = new Intent(null, uri);
        intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
        menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items);

        // Give a shortcut to the edit action.
        if (items[0] != null) {
            items[0].setShortcut('1', 'e');
        }
    } else {
        menu.removeGroup(Menu.CATEGORY_ALTERNATIVE);
    }

    return true;
}

From source file:com.example.android.notepad.NotesList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    // This is our one standard application action -- inserting a
    // new note into the list.
    menu.add(0, MENU_ITEM_INSERT, 0, R.string.menu_insert).setShortcut('3', 'a')
            .setIcon(android.R.drawable.ic_menu_add);

    // ilya: add refresh
    menu.add(0, MENU_ITEM_REFRESH, 0, "Refresh").setShortcut('4', 'r').setIcon(android.R.drawable.ic_menu_view);

    // Generate any additional actions that can be performed on the
    // overall list.  In a normal install, there are no additional
    // actions found here, but this allows other applications to extend
    // our menu with their own actions.
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, NotesList.class), null,
            intent, 0, null);/*from w  ww.  j ava2 s. c  o  m*/

    return true;
}

From source file:com.phonegap.plugins.discoverscanar.DiscoverScanAR.java

/**
 * Starts an intent to scan and decode a barcode.
 *//*w w w  . j  a  v a2 s .  co  m*/
public void scan() {
    Intent intentScan = new Intent(SCAN_INTENT);
    intentScan.addCategory(Intent.CATEGORY_DEFAULT);

    this.cordova.startActivityForResult((CordovaPlugin) this, intentScan, REQUEST_SCAN_CODE);
}