List of usage examples for android.content Intent addCategory
public @NonNull Intent addCategory(String category)
From source file:com.byhook.cordova.chromelauncher.ChromeLauncher.java
/** * Executes the request and returns PluginResult. * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return A PluginResult object with a status and message. *///from w w w. ja va 2 s . c om public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult.Status status = PluginResult.Status.OK; String result = ""; if (action.equals("open")) { String url = args.getString(0); Intent i = new Intent("android.intent.action.MAIN"); i.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main")); i.addCategory("android.intent.category.LAUNCHER"); i.setData(Uri.parse(url)); ((Activity) cordova).startActivity(i); } else if (action.equals("checkInstall")) { if (isInstalled("com.android.chrome")) { callbackContext.sendPluginResult(new PluginResult(status, true)); return true; } else { status = PluginResult.Status.ERROR; callbackContext.sendPluginResult(new PluginResult(status, false)); return true; } } else if (action.equals("openStore")) { Uri marketUri = Uri.parse("market://details?id=com.android.chrome"); Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri); ((Activity) cordova).startActivity(marketIntent); } callbackContext.sendPluginResult(new PluginResult(status, result)); return true; }
From source file:com.dm.material.dashboard.candybar.tasks.IconRequestTask.java
@Override protected Boolean doInBackground(Void... voids) { while (!isCancelled()) { try {/*from w w w.j a v a 2 s . c o m*/ Thread.sleep(1); if (mContext.get().getResources().getBoolean(R.bool.enable_icon_request) || mContext.get().getResources().getBoolean(R.bool.enable_premium_request)) { List<Request> requests = new ArrayList<>(); HashMap<String, String> appFilter = RequestHelper.getAppFilter(mContext.get(), RequestHelper.Key.ACTIVITY); if (appFilter.size() == 0) { mError = Extras.Error.APPFILTER_NULL; return false; } PackageManager packageManager = mContext.get().getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> installedApps = packageManager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); if (installedApps == null || installedApps.size() == 0) { mError = Extras.Error.INSTALLED_APPS_NULL; return false; } CandyBarMainActivity.sInstalledAppsCount = installedApps.size(); try { Collections.sort(installedApps, new ResolveInfo.DisplayNameComparator(packageManager)); } catch (Exception ignored) { } for (ResolveInfo app : installedApps) { String packageName = app.activityInfo.packageName; String activity = packageName + "/" + app.activityInfo.name; String value = appFilter.get(activity); if (value == null) { String name = LocaleHelper.getOtherAppLocaleName(mContext.get(), new Locale("en"), packageName); if (name == null) { name = app.activityInfo.loadLabel(packageManager).toString(); } boolean requested = Database.get(mContext.get()).isRequested(activity); Request request = Request.Builder().name(name).packageName(app.activityInfo.packageName) .activity(activity).requested(requested).build(); requests.add(request); } } CandyBarMainActivity.sMissedApps = requests; } return true; } catch (Exception e) { CandyBarMainActivity.sMissedApps = null; mError = Extras.Error.DATABASE_ERROR; LogUtil.e(Log.getStackTraceString(e)); return false; } } return false; }
From source file:com.dcs.fakecurrencydetector.MainActivity.java
public void AppExit() { this.finish(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);//from w ww .j a va 2 s . co m /*int pid = android.os.Process.myPid();=====> use this if you want to kill your activity. But its not a good one to do. android.os.Process.killProcess(pid);*/ }
From source file:DetailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); detector = new GestureDetector(this, new GalleryGestureDetector()); listener = new View.OnTouchListener() { @Override// w ww . j a v a2 s .c o m public boolean onTouch(View v, MotionEvent event) { return detector.onTouchEvent(event); } }; ImageIndex = 0; detailImage = (ImageView) findViewById(R.id.detail_image); detailImage.setOnTouchListener(listener); TextView detailName = (TextView) findViewById(R.id.detail_name); TextView detailDistance = (TextView) findViewById(R.id.detail_distance); TextView detailText = (TextView) findViewById(R.id.detail_text); detailText.setMovementMethod(new ScrollingMovementMethod()); ImageView detailWebLink = (ImageView) findViewById(R.id.detail_web_link); int i = MainActivity.currentItem; Random n = new Random(); int m = n.nextInt((600 - 20) + 1) + 20; setTitle(getString(R.string.app_name) + " - " + MainData.nameArray[i]); detailImage.setImageResource(MainData.detailImageArray[i]); detailName.setText(MainData.nameArray[i]); detailDistance.setText(String.valueOf(m) + " miles"); detailText.setText(MainData.detailTextArray[i]); detailWebLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setData(Uri.parse(MainData.detailWebLink[MainActivity.currentItem])); startActivity(intent); } }); }
From source file:com.gigathinking.simpleapplock.ResetUnlockMethod.java
@Override public void onBackPressed() { finish();//from ww w . ja v a 2 s. c o m Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); }
From source file:com.mono.applink.Twitter.java
/** Called when the activity is first created. */ @Override/* w w w .j a v a 2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final String url = getIntent().getData().toString(); if (url.contains("twitter.com") && !url.contains("status") && !url.contains("direct_messages") && !url.contains("user_spam_reports") && !url.contains("account") && !url.contains("settings"))//Just if it is a link of a user profile { new TwitterUser().execute(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Sorry, but this type of link is not currently supported"); builder.setOnCancelListener(new OnCancelListener() { public void onCancel(DialogInterface dialog) { finish(); } }); builder.setPositiveButton("Open in Browser", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent i = new Intent(); i.setAction("android.intent.action.VIEW"); i.addCategory("android.intent.category.BROWSABLE"); i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity")); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setData(Uri.parse(url)); startActivity(i); finish(); } }); AlertDialog alert = builder.create(); alert.show(); } }
From source file:com.chess.genesis.activity.GameListLocalFrag.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.new_game: new NewLocalGameDialog(act, handle).show(); break;//from www. j a v a 2s .c o m case R.id.import_game: Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent = intent.addCategory(Intent.CATEGORY_OPENABLE).setType("text/*"); intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); try { startActivityForResult(intent, Enums.IMPORT_GAME); } catch (final ActivityNotFoundException e) { Toast.makeText(act, "No File Manager Installed", Toast.LENGTH_LONG).show(); } break; default: return super.onOptionsItemSelected(item); } return true; }
From source file:com.buddi.client.dfu.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 w w w .j a v a2s. co 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.example.administrator.winsoftsalesproject.activity.NavHomeActivity.java
public void exitDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Do You Want To Exit?").setTitle("Exit App"); builder.setPositiveButton("Cancel", new DialogInterface.OnClickListener() { @Override/*from w ww.j ava2 s. c o m*/ public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent homeIntent = new Intent(Intent.ACTION_MAIN); homeIntent.addCategory(Intent.CATEGORY_HOME); homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); sessionManger.logoutUser(); NavHomeActivity.this.finish(); startActivity(homeIntent); } }); AlertDialog dialog = builder.create(); dialog.show(); }
From source file:com.farmerbb.notepad.fragment.WelcomeFragment.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override/*from w ww .j a v a 2 s. c om*/ public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_settings: Intent intentSettings = new Intent(getActivity(), SettingsActivity.class); startActivity(intentSettings); return true; case R.id.action_import: Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "text/plain", "text/html", "text/x-markdown" }); intent.setType("*/*"); try { getActivity().startActivityForResult(intent, 42); } catch (ActivityNotFoundException e) { showToast(R.string.error_importing_notes); } return true; case R.id.action_about: DialogFragment aboutFragment = new AboutDialogFragment(); aboutFragment.show(getFragmentManager(), "about"); return true; default: return super.onOptionsItemSelected(item); } }