Java Code Examples for android.content.Intent.ACTION_MAIN

The following are Jave code examples for showing how to use ACTION_MAIN of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: exciting-app   File: CommonUtil.java   View Source Code Vote up 9 votes
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;
}
 
Example 2
Project: pluginMVPM   File: AsyncChannel.java   View Source Code Vote up 8 votes
/**
 * 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;
}
 
Example 3
Project: aos-Video   File: UiChoiceDialog.java   View Source Code Vote up 7 votes
@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);
}
 
Example 4
Project: webtrekk-android-sdk   File: RecommendationsTest.java   View Source Code Vote up 7 votes
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());
}
 
Example 5
Project: LauncherTV   File: Utils.java   View Source Code Vote up 7 votes
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;
}
 
Example 6
Project: Bella-Android   File: MainActivity.java   View Source Code Vote up 7 votes
@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);
}
 
Example 7
Project: buildAPKsApps   File: WiFiSettingHandler.java   View Source Code Vote up 6 votes
@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));
}
 
Example 8
Project: chat-sdk-android-push-firebase   File: ChatSDKAbstractLoginActivity.java   View Source Code Vote up 6 votes
@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();

}
 
Example 9
Project: aos-Video   File: Browser.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 10
Project: ThunderMusic   File: MediaLockscreenActivity.java   View Source Code Vote up 6 votes
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();
}
 
Example 11
Project: android-metronome   File: Base.java   View Source Code Vote up 6 votes
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();
}
 
Example 12
Project: FlickLauncher   File: LauncherAppsCompatV16.java   View Source Code Vote up 6 votes
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);
}
 
Example 13
Project: MapaDeIgarassu   File: MapActivity.java   View Source Code Vote up 6 votes
@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);
    }

}
 
Example 14
Project: starcor.xul   File: XulDebugServer.java   View Source Code Vote up 6 votes
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);
}
 
Example 15
Project: StopApp   File: CommonUtil.java   View Source Code Vote up 6 votes
/**
 * 获取正在运行桌面包名
 */
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;
}
 
Example 16
Project: Quadro   File: HomeActivity.java   View Source Code Vote up 6 votes
@Override
public void onBackPressed() {
    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);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}
 
Example 17
Project: TIIEHenry-Android-SDK   File: AppUtils.java   View Source Code Vote up 6 votes
/**
 * 获取应用程序下所有Activity
 *
 * @param activity
 * @return
 */
public static ArrayList<String> getActivities(Context activity) {
    ArrayList<String> result = new ArrayList<String>();
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.setPackage(activity.getPackageName());
    for (ResolveInfo info : activity.getPackageManager()
            .queryIntentActivities(intent, 0)) {
        result.add(info.activityInfo.name);
    }
    return result;
}
 
Example 18
Project: PicKing   File: PackageUtil.java   View Source Code Vote up 6 votes
/**
 * 启动应用
 */
public static boolean startAppByPackageName(Context context, String packageName, Map<String, String> param) {
    android.content.pm.PackageInfo pi = null;
    try {
        pi = context.getPackageManager().getPackageInfo(packageName, 0);
        Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
        resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {
            resolveIntent.setPackage(pi.packageName);
        }

        List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0);

        ResolveInfo ri = apps.iterator().next();
        if (ri != null) {
            String packageName1 = ri.activityInfo.packageName;
            String className = ri.activityInfo.name;

            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);

            ComponentName cn = new ComponentName(packageName1, className);

            intent.setComponent(cn);
            if (param != null) {
                for (Map.Entry<String, String> en : param.entrySet()) {
                    intent.putExtra(en.getKey(), en.getValue());
                }
            }
            context.startActivity(intent);
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(context.getApplicationContext(), "启动失败",
                Toast.LENGTH_LONG).show();
    }
    return false;
}
 
Example 19
Project: AndroidBasicLibs   File: SystemUtils.java   View Source Code Vote up 5 votes
public static void goHome(Context context) {
    Intent mHomeIntent = new Intent(Intent.ACTION_MAIN);
    mHomeIntent.addCategory(Intent.CATEGORY_HOME);
    mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    context.startActivity(mHomeIntent);
}
 
Example 20
Project: LaunchEnr   File: LoaderCursor.java   View Source Code Vote up 5 votes
/**
 * Make an ShortcutInfo object for a shortcut that is an application.
 */
public ShortcutInfo getAppShortcutInfo(
        Intent intent, boolean allowMissingTarget, boolean useLowResIcon) {
    if (user == null) {
        return null;
    }

    ComponentName componentName = intent.getComponent();
    if (componentName == null) {
        return null;
    }

    Intent newIntent = new Intent(Intent.ACTION_MAIN, null);
    newIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    newIntent.setComponent(componentName);
    LauncherActivityInfo lai = LauncherAppsCompat.getInstance(mContext)
            .resolveActivity(newIntent, user);
    if ((lai == null) && !allowMissingTarget) {
        return null;
    }

    final ShortcutInfo info = new ShortcutInfo();
    info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
    info.user = user;
    info.intent = newIntent;

    mIconCache.getTitleAndIcon(info, lai, useLowResIcon);
    if (mIconCache.isDefaultIcon(info.iconBitmap, user)) {
        Bitmap icon = loadIcon(info);
        info.iconBitmap = icon != null ? icon : info.iconBitmap;
    }

    if (lai != null && PackageManagerHelper.isAppSuspended(lai.getApplicationInfo())) {
        info.isDisabled = ShortcutInfo.FLAG_DISABLED_SUSPENDED;
    }

    // from the db
    if (TextUtils.isEmpty(info.title)) {
        info.title = getTitle();
    }

    // fall back to the class name of the activity
    if (info.title == null) {
        info.title = componentName.getClassName();
    }

    info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
    return info;
}