Example usage for android.content Intent ACTION_MAIN

List of usage examples for android.content Intent ACTION_MAIN

Introduction

In this page you can find the example usage for android.content Intent ACTION_MAIN.

Prototype

String ACTION_MAIN

To view the source code for android.content Intent ACTION_MAIN.

Click Source Link

Document

Activity Action: Start as a main entry point, does not expect to receive data.

Usage

From source file:net.ustyugov.jtalk.Notify.java

public static void offlineNotify(Context context, String state) {
    if (state == null)
        state = "";
    Intent i = new Intent(context, RosterActivity.class);
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i, 0);

    JTalkService service = JTalkService.getInstance();
    service.setGlobalState(state);//  w  w w.  j  a  v  a 2  s. c o  m
    context.sendBroadcast(new Intent(Constants.UPDATE));

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher));
    mBuilder.setSmallIcon(R.drawable.stat_offline);
    mBuilder.setContentTitle(context.getString(R.string.app_name));
    mBuilder.setContentText(state);
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);

    NotificationManager mng = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mng.notify(NOTIFICATION, mBuilder.build());
}

From source file:edu.uwp.alga.MainActivity.java

@Override
public void onBackPressed() {
    super.onBackPressed();
    if (mViewPager.getCurrentItem() == 0) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//***Change Here***
        startActivity(intent);//w  w w. j  a v  a 2s. c  o  m
        finish();
        System.exit(0);
    }

}

From source file:com.zetcheck.MenuActivity.java

@Override
public void onBackPressed() {
    if (mViewPager.getCurrentItem() != 1) {
        mViewPager.setCurrentItem(1);/* w w w.  j  ava  2  s  . c o m*/
        return;
    }
    Intent intent1 = new Intent(Intent.ACTION_MAIN);
    intent1.addCategory(Intent.CATEGORY_HOME);
    intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent1);
}

From source file:org.ohthehumanity.carrie.CarrieActivity.java

/** Called when the activity is first created. */
@Override//from  ww  w.  j a v a 2 s . c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mServerName = "";
    setContentView(R.layout.main);

    // instantiate our preferences backend
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // set callback function when settings change
    mPreferences.registerOnSharedPreferenceChangeListener(this);

    if (mPreferences.getString("server", null) == null) {
        setStatus("Server not set");
    } else if (mPreferences.getString("port", null) == null) {
        setStatus("Port not configured");
    }

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm.getActiveNetworkInfo().getType() != ConnectivityManager.TYPE_WIFI) {

        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
        dlgAlert.setTitle("WiFi not active");
        dlgAlert.setMessage(
                "This application is usually used on a local network over a WiFi. Open WiFi settings?");
        dlgAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    //Yes button clicked
                    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    final ComponentName cn = new ComponentName("com.android.settings",
                            "com.android.settings.wifi.WifiSettings");
                    intent.setComponent(cn);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    //Log.i(TAG, "Not opening wifi");
                    //No button clicked
                    break;
                }
            }
        });

        dlgAlert.setNegativeButton("No", null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
    }

    updateTitle();
    updateSkipLabels();
    updateServerName();
}

From source file:com.app.basarnas.fcm.MyFirebaseMessagingService.java

private void sendNotification() {
    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra(Config.JSON_DATA_NOTIFICATION, jsonDataNotification);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(dataNotification.getText()))
            .setSmallIcon(R.mipmap.ic_launcher, 10)
            .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
            .setContentTitle(dataNotification.getTitle())
            .setContentText(CommonUtilities.toHtml(dataNotification.getText()))
            .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(Config.NOTIFICATION_ID /* ID of notification */, notificationBuilder.build());
}

From source file:com.nma.util.sdcardtrac.GraphActivity.java

@Override
public void onCreate(Bundle savedInstance) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstance);
    setContentView(R.layout.graph);/*from ww w.j  a v a2 s .co m*/

    // Setup debug logging
    SettingsActivity.ENABLE_DEBUG = pref.getBoolean(SettingsActivity.ENABLE_DEBUG_KEY, false);

    // ActionBar
    actionBar = getSupportActionBar();
    // Add a custom view with a spinner
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(R.layout.graph_action_bar);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    actionBar.addTab(actionBar.newTab().setText(TAB_NAME_EXT_STORAGE)
            .setTabListener(new GraphTabListener(this, TAB_NAME_EXT_STORAGE)));
    /*Log.d(getClass().getName(), "Creating 2");
    actionBar.addTab(actionBar.newTab().setText(TAB_NAME_INT_STORAGE)
    .setTabListener(new GraphTabListener(this, TAB_NAME_INT_STORAGE)));*/

    durationSel = (Spinner) findViewById(R.id.graph_action_bar_spinner);
    durationSel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            interval = parent.getItemAtPosition(position).toString();

            refreshGraph(true, interval);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    // Help on first
    showTips = pref.getBoolean(SHOW_HELP_TAG, true);
    if (showTips) {
        showHelp();
    }

    // Start service
    alarmEnabled = pref.getBoolean(SettingsActivity.ALARM_RUNNING_KEY, false);
    boolean reInst = false;
    if (savedInstance != null) {
        Parcelable spinner;
        reInst = savedInstance.getBoolean(SettingsActivity.ALARM_RUNNING_KEY, false);
        interval = savedInstance.getString("interval", "Day");
        spinner = savedInstance.getParcelable("spinner");
        if (spinner != null)
            durationSel.onRestoreInstanceState(spinner);
    }

    if (alarmEnabled && !reInst) {
        Intent serviceIntent = new Intent(this, FileObserverService.class);
        serviceIntent.setAction(Intent.ACTION_MAIN);
        startService(serviceIntent);
    }
}

From source file:com.koma.music.main.MainActivity.java

private void backToHome() {
    Intent launcher = new Intent(Intent.ACTION_MAIN);
    launcher.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launcher.addCategory(Intent.CATEGORY_HOME);
    startActivity(launcher);//ww  w .ja  va2 s  . c  o  m
}

From source file:no.android.proxime.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 ww.  ja  v a2  s .  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);
            startActivity(action);
            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:at.diamonddogs.util.Utils.java

/**
 * Brings up the MAIN/LAUNCHER activity and clears the top
 *
 * @param context a {@link Context}/* www . j  a  va 2s. c  o m*/
 */
public static void returnToHome(Context context) {
    PackageManager pm = context.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setPackage(context.getPackageName());
    List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
    Intent homeIntent = new Intent("android.intent.action.MAIN");
    homeIntent.addCategory("android.intent.category.LAUNCHER");
    homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    homeIntent.setComponent(new ComponentName(context.getPackageName(), activities.get(0).activityInfo.name));
    context.startActivity(homeIntent);
}

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);// w w  w. j  a  va2s.  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);
    }
}