android.content.Intent.hasCategory()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(295)

本文整理了Java中android.content.Intent.hasCategory()方法的一些代码示例,展示了Intent.hasCategory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.hasCategory()方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:hasCategory

Intent.hasCategory介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

// Possible work around for market launches. See http://code.google.com/p/android/issues/detail?id=2373
// for more details. Essentially, the market launches the main activity on top of other activities.
// we never want this to happen. Instead, we check if we are the root and if not, we finish.
if (!isTaskRoot()) {
  final Intent intent = getIntent();
  if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(intent.getAction())) {
    Log.w(LOG_TAG, "Main Activity is not the root.  Finishing Main Activity instead of launching.");
    finish();
    return;       
  }
}

代码示例来源:origin: stackoverflow.com

if (!isTaskRoot()) {
  Intent intent = getIntent();
  String action = intent.getAction();
  if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action != null && action.equals(Intent.ACTION_MAIN)) {
    finish();
    return;
  }
}

代码示例来源:origin: TeamNewPipe/NewPipe

@Override
protected void onNewIntent(Intent intent) {
  if (DEBUG) Log.d(TAG, "onNewIntent() called with: intent = [" + intent + "]");
  if (intent != null) {
    // Return if launched from a launcher (e.g. Nova Launcher, Pixel Launcher ...)
    // to not destroy the already created backstack
    String action = intent.getAction();
    if ((action != null && action.equals(Intent.ACTION_MAIN)) && intent.hasCategory(Intent.CATEGORY_LAUNCHER)) return;
  }
  super.onNewIntent(intent);
  setIntent(intent);
  handleIntent(intent);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public boolean onControlRequest(Intent i, ControlRequestCallback cb) {
 if (i.hasCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)) {
  if (MediaControlIntent.ACTION_PLAY.equals(i.getAction())) {
   return(onPlayRequest(i, cb));
  }
  else if (MediaControlIntent.ACTION_PAUSE.equals(i.getAction())) {
   return(onPauseRequest(i, cb));
  }
  else if (MediaControlIntent.ACTION_RESUME.equals(i.getAction())) {
   return(onResumeRequest(i, cb));
  }
  else if (MediaControlIntent.ACTION_STOP.equals(i.getAction())) {
   return(onStopRequest(i, cb));
  }
  else if (MediaControlIntent.ACTION_GET_STATUS.equals(i.getAction())) {
   return(onGetStatusRequest(i, cb));
  }
  else if (MediaControlIntent.ACTION_SEEK.equals(i.getAction())) {
   return(onSeekRequest(i, cb));
  }
 }
 Log.w(getClass().getSimpleName(), "unexpected control request"
   + i.toString());
 return(false);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public boolean onControlRequest(Intent i, ControlRequestCallback cb) {
 if (i.hasCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)) {
  if (MediaControlIntent.ACTION_PLAY.equals(i.getAction())) {
   return(onPlayRequest(i, cb));
  }
  else if (MediaControlIntent.ACTION_PAUSE.equals(i.getAction())) {
   return(onPauseRequest(i, cb));
  }
  else if (MediaControlIntent.ACTION_RESUME.equals(i.getAction())) {
   return(onResumeRequest(i, cb));
  }
  else if (MediaControlIntent.ACTION_STOP.equals(i.getAction())) {
   return(onStopRequest(i, cb));
  }
  else if (MediaControlIntent.ACTION_GET_STATUS.equals(i.getAction())) {
   return(onGetStatusRequest(i, cb));
  }
  else if (MediaControlIntent.ACTION_SEEK.equals(i.getAction())) {
   return(onSeekRequest(i, cb));
  }
 }
 Log.w(getClass().getSimpleName(), "unexpected control request"
   + i.toString());
 return(false);
}

代码示例来源:origin: pockethub/PocketHub

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  final Intent intent = getIntent();
  final Uri data = intent.getData();
  final Intent newIntent = getIntentForURI(data);
  if (newIntent != null) {
    startActivity(newIntent);
    finish();
    return;
  }
  if (!intent.hasCategory(CATEGORY_BROWSABLE)) {
    startActivity(new Intent(ACTION_VIEW, data).addCategory(CATEGORY_BROWSABLE));
    finish();
  } else {
    showParseError(data.toString());
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldSupportCategories() throws Exception {
 Intent intent = new Intent();
 Intent self = intent.addCategory("category.name.1");
 intent.addCategory("category.name.2");
 assertTrue(intent.hasCategory("category.name.1"));
 assertTrue(intent.hasCategory("category.name.2"));
 Set<String> categories = intent.getCategories();
 assertTrue(categories.contains("category.name.1"));
 assertTrue(categories.contains("category.name.2"));
 intent.removeCategory("category.name.1");
 assertFalse(intent.hasCategory("category.name.1"));
 assertTrue(intent.hasCategory("category.name.2"));
 intent.removeCategory("category.name.2");
 assertFalse(intent.hasCategory("category.name.2"));
 assertThat(intent.getCategories()).isNull();
 assertSame(self, intent);
}

代码示例来源:origin: aa112901/remusic

if (intent.hasCategory(Intent.CATEGORY_ALTERNATIVE)) {
  Uri data = intent.getData();
  int buttonId = Integer.parseInt(data.getSchemeSpecificPart());

代码示例来源:origin: stackoverflow.com

Intent intent = getIntent();
if (Intent.ACTION_MAIN.equals(intent.getAction()) && intent.hasCategory(Intent.CATEGORY_LAUNCHER)) {
  // started by launcher
}

代码示例来源:origin: stackoverflow.com

if (!isTaskRoot()) {
  final Intent intent = getIntent();
  if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(intent.getAction())) {
    finish();
    return;
  }
}

代码示例来源:origin: stackoverflow.com

if (!isTaskRoot())
{
  final Intent intent = getIntent();
  final String intentAction = intent.getAction(); 
  if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN))
  {
    Log.w(LOG_TAG, "Main Activity is not the root.  Finishing Main Activity instead of launching.");
    finish();
    return;       
  }
}

代码示例来源:origin: stackoverflow.com

if (!isTaskRoot())
   {
     final Intent intent = getIntent();
     final String intentAction = intent.getAction(); 
     if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
       finish();
       return;       
     }
   }

代码示例来源:origin: stackoverflow.com

// Possible work around for market launches. See http://code.google.com/p/android/issues/detail?id=2373
 // for more details. Essentially, the market launches the main activity on top of other activities.
 // we never want this to happen. Instead, we check if we are the root and if not, we finish.
 if (!isTaskRoot()) {
   final Intent intent = getIntent();
   final String intentAction = intent.getAction(); 
   if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
     finish();
     return;       
   }
 }

代码示例来源:origin: stackoverflow.com

if (!isTaskRoot()) {
  final Intent intent = getIntent();
  final String intentAction = intent.getAction();
  if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) &&
      intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
    finish();
  }
}

代码示例来源:origin: stackoverflow.com

if (!isTaskRoot()) {
     Intent intent = getIntent();
     String action = intent.getAction();
     if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action != null && action.equals(Intent.ACTION_MAIN)) {
       finish();
       return;
     }
   }

代码示例来源:origin: stackoverflow.com

if (!isTaskRoot()) {
  final Intent intent = getIntent();
  final String intentAction = intent.getAction();
  if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) &&
      intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
    finish(); return;
  }
}

代码示例来源:origin: stackoverflow.com

if (!isTaskRoot()) {
   Intent intent = getIntent();
   String action = intent.getAction();
   if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action != null && action.equals(Intent.ACTION_MAIN)) {
     finish();
     return;
   }
 }

代码示例来源:origin: stackoverflow.com

if (!isTaskRoot()) {
  final Intent intent = getIntent();
  final String intentAction = intent.getAction(); 
  if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
    Log.w(LOG_TAG, "Main Activity is not the root.  Finishing Main Activity instead of launching.");
    finish();
    return;       
  }
}

代码示例来源:origin: stackoverflow.com

if (isTaskRoot()) {
  final Intent intent = getIntent();
  final String intentAction = intent.getAction();
  if (!intent.hasCategory(Intent.CATEGORY_LAUNCHER) &&
      intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
    finish();
    System.exit(0);
  }
}

代码示例来源:origin: stackoverflow.com

Put below code on the onCreate() of launcher activity-

final Intent intent = getIntent();
if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0
    && intent.hasCategory(Intent.CATEGORY_LAUNCHER)
    && intent.getAction() != null
    && intent.getAction().equals(Intent.ACTION_MAIN)) {
  finish();// finish this launcher activity
  return;
}

相关文章

Intent类方法