Search in sources :

Example 1 with ActivityInfo

use of android.content.pm.ActivityInfo in project cw-omnibus by commonsguy.

the class FreecarTileService method onClick.

@Override
public void onClick() {
    super.onClick();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String cnFlat = prefs.getString(PREF_TO_LAUNCH, null);
    if (cnFlat != null) {
        ComponentName cn = ComponentName.unflattenFromString(cnFlat);
        try {
            ActivityInfo info = getPackageManager().getActivityInfo(cn, 0);
            ActivityInfo.WindowLayout layout = info.windowLayout;
            Intent i = new Intent().setComponent(cn).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Point size = new Point();
            getSystemService(DisplayManager.class).getDisplay(Display.DEFAULT_DISPLAY).getSize(size);
            if (layout == null) {
                size.x = size.x / 2;
                size.y = size.y / 2;
            } else {
                if (layout.widthFraction > 0.0f) {
                    size.x = Math.max(layout.minWidth, (int) (size.x * layout.widthFraction));
                } else {
                    size.x = layout.width;
                }
                if (layout.heightFraction > 0.0f) {
                    size.y = Math.max(layout.minHeight, (int) (size.y * layout.heightFraction));
                } else {
                    size.y = layout.height;
                }
            }
            ActivityOptions opts = ActivityOptions.makeBasic().setLaunchBounds(new Rect(0, 0, size.x, size.y));
            startActivity(i, opts.toBundle());
        } catch (Exception e) {
            Log.e(getClass().getSimpleName(), "Exception trying to launch activity", e);
            toast(R.string.msg_sorry);
        }
    } else {
        toast(R.string.msg_choose);
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) Rect(android.graphics.Rect) SharedPreferences(android.content.SharedPreferences) ComponentName(android.content.ComponentName) Intent(android.content.Intent) Point(android.graphics.Point) ActivityOptions(android.app.ActivityOptions)

Example 2 with ActivityInfo

use of android.content.pm.ActivityInfo in project cw-omnibus by commonsguy.

the class MainActivity method onListItemClick.

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    ResolveInfo launchable = adapter.getItem(position);
    ActivityInfo activity = launchable.activityInfo;
    ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
    PreferenceManager.getDefaultSharedPreferences(this).edit().putString(FreecarTileService.PREF_TO_LAUNCH, name.flattenToString()).apply();
    Toast.makeText(this, R.string.msg_saved, Toast.LENGTH_LONG).show();
    finish();
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) ComponentName(android.content.ComponentName)

Example 3 with ActivityInfo

use of android.content.pm.ActivityInfo in project cw-omnibus by commonsguy.

the class Launchalot method onListItemClick.

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    ResolveInfo launchable = adapter.getItem(position);
    ActivityInfo activity = launchable.activityInfo;
    ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
    Intent i = new Intent(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    i.setComponent(name);
    startActivity(i);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 4 with ActivityInfo

use of android.content.pm.ActivityInfo in project AndroidTraining by mixi-inc.

the class SuggestionsAdapter method getActivityIcon.

/**
     * Gets the activity or application icon for an activity.
     *
     * @param component Name of an activity.
     * @return A drawable, or {@code null} if neither the acitivy or the application
     *         have an icon set.
     */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0)
        return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString());
        return null;
    }
    return drawable;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) SpannableString(android.text.SpannableString)

Example 5 with ActivityInfo

use of android.content.pm.ActivityInfo in project atlas by alibaba.

the class AtlasBundleInfoManager method findBundleByComponentName.

//    private String getFromAssets(String fileName,Context context){
//        BufferedReader bufReader = null;
//        try {
//            InputStreamReader inputReader = new InputStreamReader(context.getResources().getAssets().open(fileName), CHARSET);
//            bufReader = new BufferedReader(inputReader);
//            String line="";
//            String result="";
//            while((line = bufReader.readLine()) != null)
//                result += line;
//            return result;
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        } finally {
//            if(bufReader!=null){
//                try {
//                    bufReader.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }
//
//    private String getFromFile(String fileName){
//        File file = new File(fileName);
//        Long fileLength = file.length();
//        byte[] filecontent = new byte[fileLength.intValue()];
//        try {
//            FileInputStream in = new FileInputStream(file);
//            in.read(filecontent);
//            in.close();
//            return new String(filecontent,CHARSET);
//        } catch (Throwable e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
private String findBundleByComponentName(String componentClassName) {
    getComponentInfoFromManifestIfNeed();
    ComponentName componentName = new ComponentName(RuntimeVariables.androidApplication.getPackageName(), componentClassName);
    if (activityInfos != null) {
        ActivityInfo info = activityInfos.get(componentClassName);
        if (info != null) {
            if (info.metaData != null) {
                return info.metaData.getString("bundleLocation");
            } else {
                try {
                    ActivityInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getActivityInfo(componentName, PackageManager.GET_META_DATA);
                    if (detailInfo != null && detailInfo.metaData != null) {
                        info.metaData = detailInfo.metaData;
                        return detailInfo.metaData.getString("bundleLocation");
                    } else {
                        return null;
                    }
                } catch (Throwable e) {
                }
            }
        }
    }
    if (serviceInfos != null) {
        ServiceInfo info = serviceInfos.get(componentClassName);
        if (info != null) {
            if (info.metaData != null) {
                return info.metaData.getString("bundleLocation");
            } else {
                try {
                    ServiceInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getServiceInfo(componentName, PackageManager.GET_META_DATA);
                    if (detailInfo != null && detailInfo.metaData != null) {
                        info = detailInfo;
                        return detailInfo.metaData.getString("bundleLocation");
                    } else {
                        return null;
                    }
                } catch (Throwable e) {
                }
            }
        }
    }
    if (receiverInfos != null) {
        ActivityInfo info = receiverInfos.get(componentClassName);
        if (info != null) {
            if (info.metaData != null) {
                return info.metaData.getString("bundleLocation");
            } else {
                try {
                    ActivityInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getReceiverInfo(componentName, PackageManager.GET_META_DATA);
                    if (detailInfo != null && detailInfo.metaData != null) {
                        info.metaData = detailInfo.metaData;
                        return detailInfo.metaData.getString("bundleLocation");
                    } else {
                        return null;
                    }
                } catch (Throwable e) {
                }
            }
        }
    }
    if (providerInfos != null) {
        ProviderInfo info = providerInfos.get(componentClassName);
        if (info != null) {
            if (info.metaData != null) {
                return info.metaData.getString("bundleLocation");
            } else {
                try {
                    ProviderInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getProviderInfo(componentName, PackageManager.GET_META_DATA);
                    if (detailInfo != null && detailInfo.metaData != null) {
                        info.metaData = detailInfo.metaData;
                        return detailInfo.metaData.getString("bundleLocation");
                    } else {
                        return null;
                    }
                } catch (Throwable e) {
                }
            }
        }
    }
    return null;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) ActivityInfo(android.content.pm.ActivityInfo) ProviderInfo(android.content.pm.ProviderInfo) ComponentName(android.content.ComponentName)

Aggregations

ActivityInfo (android.content.pm.ActivityInfo)886 ResolveInfo (android.content.pm.ResolveInfo)360 Intent (android.content.Intent)339 ComponentName (android.content.ComponentName)324 PackageManager (android.content.pm.PackageManager)215 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)141 ArrayList (java.util.ArrayList)139 ApplicationInfo (android.content.pm.ApplicationInfo)115 Test (org.junit.Test)113 RemoteException (android.os.RemoteException)82 Bundle (android.os.Bundle)68 PendingIntent (android.app.PendingIntent)62 Drawable (android.graphics.drawable.Drawable)61 IOException (java.io.IOException)60 PackageInfo (android.content.pm.PackageInfo)59 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)54 XmlResourceParser (android.content.res.XmlResourceParser)43 Point (android.graphics.Point)35 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)34 Context (android.content.Context)33