當前位置: 首頁>>代碼示例>>Java>>正文


Java Intent.ACTION_MAIN屬性代碼示例

本文整理匯總了Java中android.content.Intent.ACTION_MAIN屬性的典型用法代碼示例。如果您正苦於以下問題:Java Intent.ACTION_MAIN屬性的具體用法?Java Intent.ACTION_MAIN怎麽用?Java Intent.ACTION_MAIN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.content.Intent的用法示例。


在下文中一共展示了Intent.ACTION_MAIN屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAppOpenIntentByPackageName

public static Intent getAppOpenIntentByPackageName(Context context, String packageName) {
    // MainActivity完整名
    String mainAct = null;
    // 根據包名尋找MainActivity
    PackageManager pkgMag = context.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);

    List<ResolveInfo> list = pkgMag.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES);
    for (int i = 0; i < list.size(); i++) {
        ResolveInfo info = list.get(i);
        if (info.activityInfo.packageName.equals(packageName)) {
            mainAct = info.activityInfo.name;
            break;
        }
    }
    if (TextUtils.isEmpty(mainAct)) {
        return null;
    }
    intent.setComponent(new ComponentName(packageName, mainAct));
    return intent;
}
 
開發者ID:junchenChow,項目名稱:exciting-app,代碼行數:23,代碼來源:CommonUtil.java

示例2: connectSrcHandlerToPackageSync

/**
 * Connect handler to named package/class synchronously.
 *
 * @param srcContext is the context of the source
 * @param srcHandler is the hander to receive CONNECTED & DISCONNECTED
 *            messages
 * @param dstPackageName is the destination package name
 * @param dstClassName is the fully qualified class name (i.e. contains
 *            package name)
 *
 * @return STATUS_SUCCESSFUL on success any other value is an error.
 */
public int connectSrcHandlerToPackageSync(
        Context srcContext, Handler srcHandler, String dstPackageName, String dstClassName) {
    if (DBG) log("connect srcHandler to dst Package & class E");

    mConnection = new AsyncChannelConnection();

    /* Initialize the source information */
    mSrcContext = srcContext;
    mSrcHandler = srcHandler;
    mSrcMessenger = new Messenger(srcHandler);

    /*
     * Initialize destination information to null they will
     * be initialized when the AsyncChannelConnection#onServiceConnected
     * is called
     */
    mDstMessenger = null;

    /* Send intent to create the connection */
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClassName(dstPackageName, dstClassName);
    boolean result = srcContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    if (DBG) log("connect srcHandler to dst Package & class X result=" + result);
    return result ? STATUS_SUCCESSFUL : STATUS_BINDING_UNSUCCESSFUL;
}
 
開發者ID:jasonwang18,項目名稱:pluginMVPM,代碼行數:37,代碼來源:AsyncChannel.java

示例3: onClick

@Override
public void onClick(View view) {
    if (view.getId() == R.id.choice_tv) {
        PreferenceManager.getDefaultSharedPreferences(getActivity())
                .edit()
                .putString(UI_CHOICE_LEANBACK_KEY, UI_CHOICE_LEANBACK_TV_VALUE) // string definitions in preference_video.xml and in @array/ui_mode_leanback_entryvalues
                .commit();

    }
    else if (view.getId() == R.id.choice_tablet) {
        PreferenceManager.getDefaultSharedPreferences(getActivity())
                .edit()
                .putString(UI_CHOICE_LEANBACK_KEY, UI_CHOICE_LEANBACK_TABLET_VALUE) // string definitions in preference_video.xml and in @array/ui_mode_leanback_entryvalues
                .commit();
    }
    dismiss();

    // Quit the current activity and relaunch the entry acivity
    getActivity().finish();

    Intent i = new Intent(Intent.ACTION_MAIN);
    i.setClass(getActivity(), EntryActivity.class);
    startActivity(i);
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:24,代碼來源:UiChoiceDialog.java

示例4: recommendTest

private void recommendTest(String recName, String productID, String productCat, int countCheck)
{
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(RecommendationActivity.RECOMMENDATION_NAME, recName);
    intent.putExtra(RecommendationActivity.RECOMMENDATION_PRODUCT_ID, productID);
    intent.putExtra(RecommendationActivity.RECOMMENDATION_PRODUCT_CAT, productCat);
    mActivityRule.launchActivity(intent);
    //Wait for recommendation request done
    while (!mActivityRule.getActivity().isRequestFinished()) {
        getInstrumentation().waitForIdleSync();
    }

    //Check results
    assertEquals(WebtrekkRecommendations.QueryRecommendationResult.RECEIVED_OK, mActivityRule.getActivity().getLastResult());

    if (countCheck > 0)
      assertTrue(mActivityRule.getActivity().getRecommendationCount() >= countCheck);
    else
      assertEquals(0, mActivityRule.getActivity().getRecommendationCount());
    assertTrue(mActivityRule.getActivity().isUsedUIThread());
}
 
開發者ID:Webtrekk,項目名稱:webtrekk-android-sdk,代碼行數:22,代碼來源:RecommendationsTest.java

示例5: loadApplications

public static List<AppInfo> loadApplications(Context context) {
	PackageManager packageManager = context.getPackageManager();
	Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
	mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
	List<ResolveInfo> intentActivities = packageManager.queryIntentActivities(mainIntent, 0);
	List<AppInfo> entries = new ArrayList<>();

	if (intentActivities != null) {
		for (ResolveInfo resolveInfo : intentActivities) {
			if (!context.getPackageName().equals(resolveInfo.activityInfo.packageName))
				entries.add(new AppInfo(packageManager, resolveInfo));
		}
	}

	Collections.sort(entries, new Comparator<AppInfo>() {
		@Override
		public int compare(AppInfo lhs, AppInfo rhs) {
			return lhs.getName().compareToIgnoreCase(rhs.getName());
		}
	});
	return entries;
}
 
開發者ID:alescdb,項目名稱:LauncherTV,代碼行數:22,代碼來源:Utils.java

示例6: onBackPressed

@Override
public void onBackPressed() {
    if (doubleBackToExitPressedOnce) {
        super.onBackPressed();
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return;
    }

    this.doubleBackToExitPressedOnce = true;
    Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            doubleBackToExitPressedOnce=false;
        }
    }, 2000);
}
 
開發者ID:NullPointersInc,項目名稱:Bella-Android,代碼行數:22,代碼來源:MainActivity.java

示例7: onSelected

@Override
public void onSelected(int buttonIndex) {
	Intent intent = new Intent(Intent.ACTION_MAIN);
	intent.setClassName("com.android.settings", "com.android.settings.wifi.WifiSettings");
	mActivity.startActivitiesSafely(intent, new Intent(Settings.ACTION_WIRELESS_SETTINGS), new Intent(
			Settings.ACTION_WIFI_SETTINGS));
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:7,代碼來源:WiFiSettingHandler.java

示例8: onBackPressed

@Override
public void onBackPressed() {
    if (exitOnBackPressed)
    {
        // Exit the app.
        // If logged out from the main activity pressing back in the LoginActivity will get me back to the Main so this have to be done.
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
    else super.onBackPressed();

}
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:14,代碼來源:ChatSDKAbstractLoginActivity.java

示例9: startSubtitlesWizard

protected void startSubtitlesWizard(String videoPath) {
    if (videoPath != null && videoPath.length() > 0) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClass(getActivity(), SubtitlesWizardActivity.class);
        intent.setData(Uri.parse(videoPath));
        startActivity(intent);
    }
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:8,代碼來源:Browser.java

示例10: onServiceConnected

public void onServiceConnected(ComponentName classname, IBinder obj) {
    mService = IMediaPlaybackService.Stub.asInterface(obj);
    startPlayback();
    try {
        // Assume something is playing when the service says it is,
        // but also if the audio ID is valid but the service is paused.
        if (mService.getAudioId() >= 0 || mService.isPlaying()
                || mService.getPath() != null) {
            // something is playing now, we're done
            mRepeatButton.setVisibility(View.VISIBLE);
            mShuffleButton.setVisibility(View.VISIBLE);
            setRepeatButtonImage();
            setShuffleButtonImage();
            setPauseButtonImage();
            return;
        }
    } catch (RemoteException ex) {
    }
    // Service is dead or not playing anything. If we got here as part
    // of a "play this file" Intent, exit. Otherwise go to the Music
    // app start screen.
    if (getIntent().getData() == null) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setClass(MediaLockscreenActivity.this,
                OnlineActivity.class);
        startActivity(intent);
    }
    finish();
}
 
開發者ID:89luca89,項目名稱:ThunderMusic,代碼行數:30,代碼來源:MediaLockscreenActivity.java

示例11: clickExit

public void clickExit(MenuItem item)
{
    Intent intent=new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    metr.stop();
    startActivity(intent);
    finish();
}
 
開發者ID:JosielSantos,項目名稱:android-metronome,代碼行數:9,代碼來源:Base.java

示例12: startActivityForProfile

public void startActivityForProfile(ComponentName component, UserHandleCompat user,
        Rect sourceBounds, Bundle opts) {
    Intent launchIntent = new Intent(Intent.ACTION_MAIN);
    launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    launchIntent.setComponent(component);
    launchIntent.setSourceBounds(sourceBounds);
    launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mContext.startActivity(launchIntent, opts);
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:9,代碼來源:LauncherAppsCompatV16.java

示例13: onBackPressed

@Override
public void onBackPressed() { //Método de back do botão do celular

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);

    } else {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        startActivity(intent);
    }

}
 
開發者ID:gabriel-silva,項目名稱:MapaDeIgarassu,代碼行數:15,代碼來源:MapActivity.java

示例14: startActivity

private XulHttpServerResponse startActivity(XulHttpServerRequest request, String[] params) {
	if (params == null) {
		return null;
	}
	String activity = params.length > 0 ? params[0].trim() : null;
	String action = params.length > 1 ? params[1].trim() : Intent.ACTION_MAIN;
	String category = params.length > 2 ? params[2].trim() : null;

	return startActivity(request, activity, action, category);
}
 
開發者ID:starcor-company,項目名稱:starcor.xul,代碼行數:10,代碼來源:XulDebugServer.java

示例15: getLauncherPackageName

/**
 * 獲取正在運行桌麵包名
 */
public static String getLauncherPackageName(Context context) {
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0);
    return res.activityInfo.packageName;
}
 
開發者ID:XYScience,項目名稱:StopApp,代碼行數:9,代碼來源:CommonUtil.java


注:本文中的android.content.Intent.ACTION_MAIN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。