IntentUtils.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package com.ysnows.sultra.utils;
  2. import android.content.ComponentName;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import com.ysnows.base.utils.ShellUtil;
  6. public class IntentUtils {
  7. public static Intent searchIntent(Context context, String kw) {
  8. Intent intent = new Intent("android.intent.action.WEB_SEARCH");
  9. intent.putExtra("query", kw);
  10. intent.setPackage(context.getPackageName());
  11. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
  12. return intent;
  13. }
  14. public static Intent nIntent(String packageName, String className) {
  15. // if (ConfigColor.ClassName.WX_PAY_CODE.equals(className) || ConfigColor.ClassName.WX_FRIENDS_CIRCLE.equals(className)) {
  16. ShellUtil.checkRootPermission();
  17. // }
  18. Intent intent = new Intent();
  19. intent.setComponent(new ComponentName(packageName, className));
  20. return intent;
  21. }
  22. public static Intent nIntentWithAction(String action) {
  23. return new Intent(action);
  24. }
  25. public static Intent shareIntent(String packageName, String className, String content) {
  26. Intent intent = new Intent();
  27. intent.setComponent(new ComponentName(packageName, className));
  28. intent.setAction(Intent.ACTION_SEND);//设置分享行为
  29. intent.setType("text/plain");//设置分享内容的类型
  30. intent.putExtra(Intent.EXTRA_SUBJECT, "");//添加分享内容标题
  31. intent.putExtra(Intent.EXTRA_TEXT, content);//添加分享内容
  32. return intent;
  33. }
  34. public static Intent nIntentWithParams(String packageName, String className, String paramsName, String paramsValue) {
  35. // if (ConfigColor.ClassName.WX_PAY_CODE.equals(className) || ConfigColor.ClassName.WX_FRIENDS_CIRCLE.equals(className)) {
  36. ShellUtil.checkRootPermission();
  37. // }
  38. Intent intent = new Intent();
  39. intent.setComponent(new ComponentName(packageName, className));
  40. if ("@1".equals(paramsValue)) {
  41. intent.putExtra(paramsName, true);
  42. } else if ("@0".equals(paramsValue)) {
  43. intent.putExtra(paramsName, false);
  44. } else {
  45. intent.putExtra(paramsName, paramsValue);
  46. }
  47. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
  48. return intent;
  49. }
  50. }