Example usage for android.content Intent getComponent

List of usage examples for android.content Intent getComponent

Introduction

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

Prototype

public @Nullable ComponentName getComponent() 

Source Link

Document

Retrieve the concrete component associated with the intent.

Usage

From source file:com.achep.base.ui.activities.SettingsActivity.java

/**
 * Checks if the component name in the intent is different from the Settings class and
 * returns the class name to load as a fragment.
 *//*  w w w . j  a va  2s  . c  o m*/
private String getStartingFragmentClass(Intent intent) {
    if (mFragmentClass != null)
        return mFragmentClass;

    String intentClass = intent.getComponent().getClassName();
    return intentClass.equals(getClass().getName()) ? null : intentClass;
}

From source file:com.hanuor.sapphire.utils.intentation.IntentationPrime.java

public String intentToJSON(Context con, Intent intent) throws JsonProcessingException {

    ObjectMapper mapper = new ObjectMapper();
    String getContextName = null;
    String getClassName = null;/*from  w  ww. ja  v  a2  s  . co m*/
    try {
        getClassName = intent.getComponent().getClassName();
        getContextName = con.getPackageName();
    } catch (Exception e) {
        e.printStackTrace();

    }
    HashMap<String, String> makeInsideJsonArray = new HashMap<String, String>();

    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("className", getClassName);
    hashMap.put("context", getContextName);
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Set<String> keys = bundle.keySet();
        Iterator<String> it = keys.iterator();
        Log.d("SappsnoopDog", "" + keys.size());
        while (it.hasNext()) {
            String key = it.next();

            Log.d("Sapptagdog", "TYPE   " + bundle.get(key).toString());
            Log.d("NERVE", "" + bundle.get(key).getClass().getAnnotations());

            String type = bundle.get(key).getClass().getSimpleName();
            Log.d("SappDogTAG", key + " OF TYPE " + type);
            switch (type) {
            case "String":
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString());
                Log.d("SappDogTAG", "bool array");
                break;
            case "String[]":
                makeInsideJsonArray.put(key,
                        type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString().replace(" ", ""));
                Log.d("SappDogTAG", "bool array");
                break;
            case "Integer":
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString());

                Log.d("SappDogTAG", "bool array");
                break;
            case "Double":
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString());
                Log.d("SappDogTAG", "bool array");
                break;
            case "double[]":

                double[] newDouble = (double[]) bundle.get(key);
                String fromDouble = Arrays.toString(newDouble);
                makeInsideJsonArray.put(key,
                        type + LibraryDatabase.JSONSEPERATOR + fromDouble.replace(" ", ""));
                Log.d("SappDogTAG", "bool array");
                break;
            case "int[]":
                int[] newArray = (int[]) bundle.get(key);
                String fromArray = Arrays.toString(newArray);
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromArray.replace(" ", ""));
                Log.d("SappDogTAG", "bool array");
                break;
            case "Boolean":
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString());
                Log.d("SappDogTAG", "bool array");
                break;
            case "boolean[]":

                boolean[] newBool = (boolean[]) bundle.get(key);
                String fromBool = Arrays.toString(newBool);
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromBool.replace(" ", ""));
                Log.d("SappDogTAG", "bool array");
                break;
            case "Char":
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString());
                Log.d("SappDogTAG", "bool array");
                break;
            case "char[]":

                char[] newChar = (char[]) bundle.get(key);
                String fromChar = Arrays.toString(newChar);
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromChar.replace(" ", ""));
                Log.d("SappDogTAG", "bool array");
                break;
            case "CharSequence":
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString());
                Log.d("SappDogTAG", "bool array");
                break;
            case "charsequence[]":

                makeInsideJsonArray.put(key,
                        type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString().replace(" ", ""));
                Log.d("SappDogTAG", "bool array");
                break;
            case "Byte":
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString());
                Log.d("SappDogTAG", "bool array");
                break;
            case "byte[]":

                byte[] newByte = (byte[]) bundle.get(key);
                String fromByte = Arrays.toString(newByte);
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromByte.replace(" ", ""));
                Log.d("SappDogTAG", "bool array");
                break;
            case "Float":
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString());
                Log.d("SappDogTAG", "bool array");
                break;
            case "float[]":

                float[] newFloat = (float[]) bundle.get(key);
                String fromFloat = Arrays.toString(newFloat);
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromFloat.replace(" ", ""));
                Log.d("SappDogTAG", "bool array");
                break;
            case "Short":
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString());
                Log.d("SappDogTAG", "bool array");
                break;
            case "short[]":

                short[] newShort = (short[]) bundle.get(key);
                String fromShort = Arrays.toString(newShort);
                fromShort = fromShort.replace(" ", "");
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + fromShort.replace(" ", ""));
                Log.d("SappDogTAG", "bool array");
                break;
            case "Long":
                makeInsideJsonArray.put(key, type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString());
                Log.d("SappDogTAG", "bool array");
                break;
            case "long[]":

                long[] newLong = (long[]) bundle.get(key);
                String fromLong = Arrays.toString(newLong);
                makeInsideJsonArray.put(key,
                        type + LibraryDatabase.JSONSEPERATOR + bundle.get(key).toString().replace(" ", ""));
                Log.d("SappDogTAG", "bool array");
                break;

            case "ArrayList":
                ArrayList<Object> obj = (ArrayList<Object>) bundle.get(key);
                Object[] objArr = obj.toArray();
                if (objArr[0] instanceof Integer) {
                    ArrayList<Integer> newIntegerArray = bundle.getIntegerArrayList(key);
                    makeInsideJsonArray.put(key, type + "Integer" + LibraryDatabase.JSONSEPERATOR
                            + newIntegerArray.toString().replace(" ", ""));

                } else if (objArr[0] instanceof String) {
                    ArrayList<String> newStringArray = bundle.getStringArrayList(key);

                    makeInsideJsonArray.put(key, type + "String" + LibraryDatabase.JSONSEPERATOR
                            + newStringArray.toString().replace(" ", ""));

                }
                break;

            default:
                // whatever
            }

            hashMap.put(key, bundle.get(key).toString());
        }
    }
    String passArray = mapper.writeValueAsString(makeInsideJsonArray);
    hashMap.put("intentExtras", passArray);
    Log.d("GOGTAD", "" + passArray);

    String intentString = mapper.writeValueAsString(intent);
    Log.d("IntentString", "" + mapper.writeValueAsString(hashMap));
    StringBuilder a1S = new StringBuilder(mapper.writeValueAsString(hashMap));
    a1S.deleteCharAt(mapper.writeValueAsString(hashMap).length() - 1);
    a1S.append(",");
    String s1t = a1S.toString();

    StringBuilder sb = new StringBuilder(intentString);
    sb.deleteCharAt(0);
    String retrString = sb.toString();
    StringBuilder newS = new StringBuilder();
    newS.append(s1t);
    newS.append(retrString);
    Log.d("Insnsns", newS.toString());
    return newS.toString();
}

From source file:git.egatuts.nxtremotecontroller.activity.MainActivity.java

@Override
public int[] onForward(Intent intent) {
    /*//from   ww  w. j  av  a 2  s . c  o m
     *  Here we check which activity is starting comparing the full class names (including package).
     *  If we are generating an intent adding a category the defClass statement
     *  will generate and propagate a NullPointerException. FUCK IT!
     */
    try {
        String defClass = intent.getComponent().getClassName();
        if (defClass.equals(SettingsActivity.class.getName())) {
            return new int[] { R.anim.settings_transition_in, R.anim.settings_transition_out };
        } else if (defClass.equals(ControllerActivity.class.getName())) {
            return new int[] { R.anim.controller_transition_in, R.anim.controller_transition_out };
        }
    } catch (NullPointerException e) {
        //e.printStackTrace();
    }
    return new int[] {};
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/* w ww .j  a  va  2s . c  om*/
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:com.llf.android.launcher3.InstallShortcutReceiver.java

@Override
public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from w  w w.  j a  v  a  2  s.  c om*/
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall
    // back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:com.aidy.launcher3.ui.receiver.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from ww  w  .ja  va  2 s.co  m*/
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall
    // back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:org.rm3l.ddwrt.tiles.admin.nvram.AdminNVRAMTile.java

private void setShareFile(File file) {
    if (mShareActionProvider == null) {
        return;/* w  w  w. ja  v a2s .c o m*/
    }

    final Uri uriForFile = FileProvider.getUriForFile(mParentFragmentActivity, "org.rm3l.fileprovider", file);

    mShareActionProvider
            .setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {
                @Override
                public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
                    mParentFragmentActivity.grantUriPermission(intent.getComponent().getPackageName(),
                            uriForFile, Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    return true;
                }
            });

    final Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_STREAM, uriForFile);
    if (mRouter != null) {
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, String.format("NVRAM Variables dump from router '%s' (%s)",
                mRouter.getName(), mRouter.getRemoteIpAddress()));
    }
    sendIntent.setData(uriForFile);
    sendIntent.setType("text/plain");
    sendIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    setShareIntent(sendIntent);

}

From source file:com.andernity.launcher2.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from www .ja  v  a 2  s.co m*/
    }

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    boolean launcherNotLoaded = LauncherModel.getCellCountX() <= 0 || LauncherModel.getCellCountY() <= 0;

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;
    if (mUseInstallQueue || launcherNotLoaded) {
        String spKey = LauncherApplication.getSharedPreferencesKey();
        SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
        addToInstallQueue(sp, info);
    } else {
        processInstallShortcut(context, info);
    }
}

From source file:com.ddj.launcher2.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//from   w  w w. ja  v  a2  s .  co m
    }

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    boolean launcherNotLoaded = LauncherModel.getCellCountX() <= 0 || LauncherModel.getCellCountY() <= 0;

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;
    if (mUseInstallQueue || launcherNotLoaded) {
        String spKey = LauncherUtil.getSharedPreferencesKey();
        SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
        addToInstallQueue(sp, info);
    } else {
        processInstallShortcut(context, info);
    }
}

From source file:ch.fixme.status.Main.java

@Override
public void startActivity(Intent intent) {
    // http://stackoverflow.com/questions/13691241/autolink-not-working-on-htc-htclinkifydispatcher
    try {//from  w ww  .j a v  a2  s.co  m
        /* First attempt at fixing an HTC broken by evil Apple patents. */
        if (intent.getComponent() != null
                && ".HtcLinkifyDispatcherActivity".equals(intent.getComponent().getShortClassName()))
            intent.setComponent(null);
        super.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        /*
         * Probably an HTC broken by evil Apple patents. This is not
         * perfect, but better than crashing the whole application.
         */
        super.startActivity(Intent.createChooser(intent, null));
    }
}