Search in sources :

Example 36 with Intent

use of android.content.Intent in project AndroidTreeView by bmelnychuk.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final LinkedHashMap<String, Class<?>> listItems = new LinkedHashMap<>();
    listItems.put("Folder Structure Example", FolderStructureFragment.class);
    listItems.put("Custom Holder Example", CustomViewHolderFragment.class);
    listItems.put("Selectable Nodes", SelectableTreeFragment.class);
    listItems.put("2d scrolling", TwoDScrollingFragment.class);
    listItems.put("Expand with arrow only", TwoDScrollingArrowExpandFragment.class);
    final List<String> list = new ArrayList(listItems.keySet());
    final ListView listview = (ListView) findViewById(R.id.listview);
    final SimpleArrayAdapter adapter = new SimpleArrayAdapter(this, list);
    listview.setAdapter(adapter);
    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Class<?> clazz = listItems.values().toArray(new Class<?>[] {})[position];
            Intent i = new Intent(MainActivity.this, SingleFragmentActivity.class);
            i.putExtra(SingleFragmentActivity.FRAGMENT_PARAM, clazz);
            MainActivity.this.startActivity(i);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) LinkedHashMap(java.util.LinkedHashMap) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView)

Example 37 with Intent

use of android.content.Intent in project VirtualApp by asLody.

the class VirtualCore method getLaunchIntent.

public Intent getLaunchIntent(String packageName, int userId) {
    VPackageManager pm = VPackageManager.get();
    Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
    intentToResolve.addCategory(Intent.CATEGORY_INFO);
    intentToResolve.setPackage(packageName);
    List<ResolveInfo> ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
    // Otherwise, try to find a main launcher activity.
    if (ris == null || ris.size() <= 0) {
        // reuse the intent instance
        intentToResolve.removeCategory(Intent.CATEGORY_INFO);
        intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
        intentToResolve.setPackage(packageName);
        ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
    }
    if (ris == null || ris.size() <= 0) {
        return null;
    }
    Intent intent = new Intent(intentToResolve);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClassName(ris.get(0).activityInfo.packageName, ris.get(0).activityInfo.name);
    return intent;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) VPackageManager(com.lody.virtual.client.ipc.VPackageManager) Intent(android.content.Intent)

Example 38 with Intent

use of android.content.Intent in project VirtualApp by asLody.

the class VirtualCore method createShortcut.

public boolean createShortcut(int userId, String packageName, Intent splash, OnEmitShortcutListener listener) {
    InstalledAppInfo setting = getInstalledAppInfo(packageName, 0);
    if (setting == null) {
        return false;
    }
    ApplicationInfo appInfo = setting.getApplicationInfo(userId);
    PackageManager pm = context.getPackageManager();
    String name;
    Bitmap icon;
    try {
        CharSequence sequence = appInfo.loadLabel(pm);
        name = sequence.toString();
        icon = BitmapUtils.drawableToBitmap(appInfo.loadIcon(pm));
    } catch (Throwable e) {
        return false;
    }
    if (listener != null) {
        String newName = listener.getName(name);
        if (newName != null) {
            name = newName;
        }
        Bitmap newIcon = listener.getIcon(icon);
        if (newIcon != null) {
            icon = newIcon;
        }
    }
    Intent targetIntent = getLaunchIntent(packageName, userId);
    if (targetIntent == null) {
        return false;
    }
    Intent shortcutIntent = new Intent();
    shortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
    shortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
    if (splash != null) {
        shortcutIntent.putExtra("_VA_|_splash_", splash.toUri(0));
    }
    shortcutIntent.putExtra("_VA_|_intent_", targetIntent);
    shortcutIntent.putExtra("_VA_|_uri_", targetIntent.toUri(0));
    shortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
    return true;
}
Also used : Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) VPackageManager(com.lody.virtual.client.ipc.VPackageManager) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent)

Example 39 with Intent

use of android.content.Intent in project VirtualApp by asLody.

the class ActivityFixer method fixActivity.

public static void fixActivity(Activity activity) {
    Context baseContext = activity.getBaseContext();
    try {
        TypedArray typedArray = activity.obtainStyledAttributes((R_Hide.styleable.Window.get()));
        if (typedArray != null) {
            boolean showWallpaper = typedArray.getBoolean(R_Hide.styleable.Window_windowShowWallpaper.get(), false);
            if (showWallpaper) {
                activity.getWindow().setBackgroundDrawable(WallpaperManager.getInstance(activity).getDrawable());
            }
            typedArray.recycle();
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Intent intent = activity.getIntent();
        ApplicationInfo applicationInfo = baseContext.getApplicationInfo();
        PackageManager pm = activity.getPackageManager();
        if (intent != null && activity.isTaskRoot()) {
            try {
                String label = applicationInfo.loadLabel(pm) + "";
                Bitmap icon = null;
                Drawable drawable = applicationInfo.loadIcon(pm);
                if (drawable instanceof BitmapDrawable) {
                    icon = ((BitmapDrawable) drawable).getBitmap();
                }
                activity.setTaskDescription(new ActivityManager.TaskDescription(label, icon));
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Context(android.content.Context) ApplicationInfo(android.content.pm.ApplicationInfo) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ActivityManager(android.app.ActivityManager) Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) TypedArray(android.content.res.TypedArray)

Example 40 with Intent

use of android.content.Intent in project VirtualApp by asLody.

the class AppInstrumentation method callActivityOnResume.

@Override
public void callActivityOnResume(Activity activity) {
    VirtualCore.get().getComponentDelegate().beforeActivityResume(activity);
    VActivityManager.get().onActivityResumed(activity);
    super.callActivityOnResume(activity);
    VirtualCore.get().getComponentDelegate().afterActivityResume(activity);
    Intent intent = activity.getIntent();
    if (intent != null) {
        Bundle bundle = intent.getBundleExtra("_VA_|_sender_");
        if (bundle != null) {
            IBinder loadingPageToken = BundleCompat.getBinder(bundle, "_VA_|_loading_token_");
            ActivityManagerCompat.finishActivity(loadingPageToken, -1, null);
        }
    }
}
Also used : IBinder(android.os.IBinder) Bundle(android.os.Bundle) Intent(android.content.Intent)

Aggregations

Intent (android.content.Intent)14391 PendingIntent (android.app.PendingIntent)2805 View (android.view.View)1068 ComponentName (android.content.ComponentName)965 Bundle (android.os.Bundle)888 Uri (android.net.Uri)762 ResolveInfo (android.content.pm.ResolveInfo)757 Context (android.content.Context)686 TextView (android.widget.TextView)669 RemoteException (android.os.RemoteException)657 Test (org.junit.Test)590 PackageManager (android.content.pm.PackageManager)553 IntentFilter (android.content.IntentFilter)519 ArrayList (java.util.ArrayList)486 ActivityNotFoundException (android.content.ActivityNotFoundException)398 ImageView (android.widget.ImageView)395 File (java.io.File)364 IOException (java.io.IOException)361 BroadcastReceiver (android.content.BroadcastReceiver)360 Notification (android.app.Notification)302