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:com.asksven.betterbatterystats.PackageFragmentActivity.java

public static void showAppOps(Context context, String packageName) {

    Intent intent = null;//  w ww .ja  v  a 2 s  . c  o m
    // JB
    if (Build.VERSION.SDK_INT == 18) {
        intent = new Intent("android.settings.APP_OPS_SETTINGS");
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
    } else if (Build.VERSION.SDK_INT >= 19) {
        // @see http://brightechno.com/blog/archives/211
        intent = new Intent();
        intent.setClassName("com.android.settings", "com.android.settings.Settings");
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.putExtra(":android:show_fragment", "com.android.settings.applications.AppOpsSummary");
    }

    if (intent != null) {
        try {
            context.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(context, context.getString(R.string.message_no_appops), Toast.LENGTH_SHORT).show();
        }

    }
}

From source file:com.amaze.carbonfilemanager.services.ExtractService.java

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
    Bundle b = new Bundle();
    String file = intent.getStringExtra(KEY_PATH_ZIP);
    String extractPath = intent.getStringExtra(KEY_PATH_EXTRACT);

    if (extractPath != null) {
        // a custom dynamic path to extract files to
        epath = extractPath;/*  www . j  a va 2s  .  c  o  m*/
    } else {

        epath = PreferenceManager.getDefaultSharedPreferences(this).getString(KEY_PATH_EXTRACT, file);
    }
    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    entries = intent.getStringArrayListExtra(KEY_ENTRIES_ZIP);

    b.putString(KEY_PATH_ZIP, file);

    totalSize = getTotalSize(file);
    progressHandler = new ProgressHandler(1, totalSize);

    progressHandler.setProgressListener(new ProgressHandler.ProgressListener() {
        @Override
        public void onProgressed(String fileName, int sourceFiles, int sourceProgress, long totalSize,
                long writtenSize, int speed) {
            publishResults(startId, fileName, sourceFiles, sourceProgress, totalSize, writtenSize, speed,
                    false);
        }
    });

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    mBuilder = new NotificationCompat.Builder(cd);
    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setContentTitle(getResources().getString(R.string.extracting))
            .setContentText(new File(file).getName()).setSmallIcon(R.drawable.ic_zip_box_grey600_36dp);
    startForeground(Integer.parseInt("123" + startId), mBuilder.build());

    new DoWork().execute(b);
    return START_STICKY;
}

From source file:com.pillowapps.liqear.activities.ImagePagerActivity.java

@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case android.R.id.home:
        finish();//from  w  w w.ja  v  a2 s .  c  o m
        Intent intent = new Intent(ImagePagerActivity.this, MainActivity.class);
        intent.setAction(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        break;
    case R.id.download_image_button: {
        if (imageUrls.size() <= pager.getCurrentItem()) {
            break;
        }
        String imageUrl = imageUrls.get(pager.getCurrentItem());

        String root = Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_PICTURES;
        File myDir = new File(root);
        if (!myDir.exists()) {
            boolean directoryCreated = myDir.mkdirs();
            if (!directoryCreated) {
                break;
            }
        }
        String fileName = artist + "_" + Utils.formatMillisToFileName(System.currentTimeMillis()) + ".jpg";

        File fileForImage = new File(myDir, fileName);

        InputStream sourceStream = null;
        OutputStream targetStream = null;
        File cachedImage = ImageLoader.getInstance().getDiscCache().get(imageUrl);
        try {
            if (cachedImage.exists()) { // if image was cached by UIL
                sourceStream = new FileInputStream(cachedImage);
            } else { // otherwise - download image
                ImageDownloader downloader = new URLConnectionImageDownloader();
                sourceStream = downloader.getStream(new URI(imageUrl));
            }

            targetStream = new FileOutputStream(fileForImage);
            FileUtils.copyStream(sourceStream, targetStream);
            Toast.makeText(ImagePagerActivity.this,
                    getString(R.string.saved) + " " + fileForImage.getAbsolutePath(), Toast.LENGTH_SHORT)
                    .show();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } finally {
            if (targetStream != null) {
                try {
                    targetStream.close();
                } catch (IOException ignored) {
                }
            }
            if (sourceStream != null) {
                try {
                    sourceStream.close();
                } catch (IOException ignored) {
                }
            }
        }
    }
        break;
    default:
        break;
    }
    return false;
}

From source file:ie.ucd.www.bee.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        Log.e("KEY_EVENT", "KeyEvent.KEYCODE_BACK");
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);/* www.j  a  v  a2 s  .  c  o m*/
        break;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:io.github.runassudo.ptoffline.fragments.SettingsFragment.java

@Override
public void onCreatePreferences(Bundle savedInstanceState, String s) {
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    TransportNetwork network = Preferences.getTransportNetwork(getActivity());

    // Fill in current home location if available
    network_pref = findPreference("pref_key_network");
    if (network != null)
        network_pref.setSummary(network.getName());

    network_pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override/*w  ww .  ja  v  a 2 s .  c  om*/
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(getActivity(), PickNetworkProviderActivity.class);

            //            View view = preference.getView(null, null);
            View view = getView();
            if (view != null)
                view = view.findFocus();

            ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(view, (int) view.getX(),
                    (int) view.getY(), 0, 0);
            ActivityCompat.startActivityForResult(getActivity(), intent, MainActivity.CHANGED_NETWORK_PROVIDER,
                    options.toBundle());

            return true;
        }
    });

    home = findPreference("pref_key_home");
    home.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            // show home picker dialog
            HomePickerDialogFragment setHomeFragment = HomePickerDialogFragment.newInstance();
            setHomeFragment.setOnHomeChangedListener(SettingsFragment.this);
            FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
            setHomeFragment.show(ft, HomePickerDialogFragment.TAG);

            return true;
        }
    });

    // Fill in current home location if available
    if (network != null)
        setHome(null);

    quickhome = findPreference("pref_key_create_quickhome_shortcut");
    quickhome.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            // create launcher shortcut
            Intent addIntent = new Intent();
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, TransportrUtils.getShortcutIntent(getContext()));
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.widget_name_quickhome));
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                    Intent.ShortcutIconResource.fromContext(getContext(), R.drawable.ic_quickhome_widget));
            addIntent.putExtra("duplicate", false);
            addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            getContext().sendBroadcast(addIntent);

            // switch to home-screen to let the user see the new shortcut
            Intent startMain = new Intent(Intent.ACTION_MAIN);
            startMain.addCategory(Intent.CATEGORY_HOME);
            startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(startMain);

            return true;
        }
    });
}

From source file:org.mozilla.focus.activity.MainActivity.java

@Override
protected void onResumeFragments() {
    super.onResumeFragments();

    final SafeIntent intent = new SafeIntent(getIntent());

    if (ACTION_ERASE.equals(intent.getAction())) {
        processEraseAction(intent);//  w  w w .  ja  v  a  2  s . co m

        // We do not want to erase again the next time we resume the app.
        setIntent(new Intent(Intent.ACTION_MAIN));
    }

    if (pendingUrl != null && !Settings.getInstance(this).shouldShowFirstrun()) {
        // We have received an URL in onNewIntent(). Let's load it now.
        // Unless we're trying to show the firstrun screen, in which case we leave it pending until
        // firstrun is dismissed.
        showBrowserScreen(pendingUrl);
        pendingUrl = null;
    }
}

From source file:de.grobox.liberario.settings.SettingsFragment.java

@Override
public void onCreatePreferences(Bundle savedInstanceState, String s) {
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    TransportNetwork network = Preferences.getTransportNetwork(getActivity());

    // Fill in current home location if available
    network_pref = findPreference("pref_key_network");
    if (network != null)
        network_pref.setSummary(network.getName(getContext()));

    network_pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override//from  w  ww.  java 2 s .  c  o m
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(getActivity(), PickTransportNetworkActivity.class);
            View view = getView();
            if (view != null)
                view = view.findFocus();

            ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(view, (int) view.getX(),
                    (int) view.getY(), 0, 0);
            ActivityCompat.startActivityForResult(getActivity(), intent, REQUEST_NETWORK_PROVIDER_CHANGE,
                    options.toBundle());
            return true;
        }
    });

    // TODO remove from here
    home = findPreference("pref_key_home");
    home.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            // show home picker dialog
            HomePickerDialogFragment setHomeFragment = HomePickerDialogFragment.newInstance();
            FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
            setHomeFragment.show(ft, HomePickerDialogFragment.TAG);

            return true;
        }
    });
    // Fill in current home location if available
    if (network != null)
        setHome(null);

    quickhome = findPreference("pref_key_create_quickhome_shortcut");
    quickhome.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            // create launcher shortcut
            Intent addIntent = new Intent();
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, TransportrUtils.getShortcutIntent(getContext()));
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.widget_name_quickhome));
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                    Intent.ShortcutIconResource.fromContext(getContext(), R.drawable.ic_quickhome_widget));
            addIntent.putExtra("duplicate", false);
            addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            getContext().sendBroadcast(addIntent);

            // switch to home-screen to let the user see the new shortcut
            Intent startMain = new Intent(Intent.ACTION_MAIN);
            startMain.addCategory(Intent.CATEGORY_HOME);
            startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(startMain);

            return true;
        }
    });
}

From source file:com.launcher.silverfish.AppDrawerTabFragment.java

/**
 * Loads apps from the database//from w  w  w  .  j a v a  2s .c  o  m
 */
private void loadApps() {

    Intent i = new Intent(Intent.ACTION_MAIN, null);
    i.addCategory(Intent.CATEGORY_LAUNCHER);

    switch (tabId) {
    case 1:
        // Tab 1 is a special tab and includes all except for the once in other tabs
        // so we retrieve all apps that are in the database
        LinkedList<String> ordered_apps = sqlHelper.getAllApps();

        // And all installed apps on the device
        List<ResolveInfo> availableActivities = mPacMan.queryIntentActivities(i, 0);

        // And only add those that are not in the database
        for (int j = 0; j < availableActivities.size(); j++) {
            ResolveInfo ri = availableActivities.get(j);

            // Skip the apps that are in the database
            if (ordered_apps.contains(ri.activityInfo.packageName)) {
                continue;
            }

            AppDetail app = new AppDetail();
            app.label = ri.loadLabel(mPacMan);
            app.name = ri.activityInfo.packageName;

            // Load the icon later in an async task.
            app.icon = null;

            appsList.add(app);
        }
        break;
    default:
        // All other tabs just query the apps from the database
        LinkedList<String> app_names = sqlHelper.getAppsForTab(tabId);
        for (String app_name : app_names) {

            boolean success = addAppToList(app_name);
            // If the app could not be added then it was probably uninstalled,
            // so we have to remove it from the database
            if (!success) {
                Log.d("DB", "Removing app " + app_name + " from db");
                sqlHelper.removeAppFromTab(app_name, this.tabId);
            }
        }

        // show the empty category notice if this tab is empty
        if (app_names.size() == 0) {
            showEmptyCategoryNotice();
        }
    }
}

From source file:org.catrobat.catroid.utils.StatusBarNotificationManager.java

public int createDownloadNotification(Context context, String programName) {
    if (context == null || programName == null) {
        return -1;
    }//from  ww w. jav  a2 s  .c  o m
    initNotificationManager(context);

    Intent downloadIntent = new Intent(context, MainMenuActivity.class);
    downloadIntent.setAction(Intent.ACTION_MAIN).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
            .putExtra(EXTRA_PROJECT_NAME, programName);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, downloadIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationData data = new NotificationData(context, pendingIntent, R.drawable.ic_stat, programName,
            R.string.notification_download_title_pending, R.string.notification_title_open,
            R.string.notification_download_pending, R.string.notification_download_finished);

    return createNotification(context, data);
}

From source file:com.aylanetworks.aura.GcmIntentService.java

private void sendNotification(String msg, String sound) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    // Find the launcher class for our application
    PackageManager pm = getPackageManager();
    String packageName = getPackageName();
    Intent query = new Intent(Intent.ACTION_MAIN);
    Class launcherClass = null;//www  .j a v  a  2  s. c  om
    query.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> foundIntents = pm.queryIntentActivities(query, 0);
    for (ResolveInfo info : foundIntents) {
        if (TextUtils.equals(info.activityInfo.packageName, packageName)) {
            launcherClass = info.activityInfo.getClass();
        }
    }

    if (launcherClass == null) {
        Log.e(TAG, "Could not find application launcher class");
        return;
    }

    Intent appIntent = new Intent(this, launcherClass); // main activity of Ayla Control/aMCA
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, appIntent, 0);

    //Determine the sound to be played
    Uri soundUri = null;
    if (sound == null) {
        // NOP
        //PushNotification.playSound("bdth.mp3");
    } else if (sound.equals("none")) {
        // NOP
    } else if (sound.equals("default")) {
        soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // TYPE_NOTIFICATION or TYPE_ALARM
    } else if (sound.equals("alarm")) {
        soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); // TYPE_NOTIFICATION or TYPE_ALARM
    } else {
        boolean playedSound;
        playedSound = PushNotification.playSound(sound);
        if (playedSound == false) {
            soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // TYPE_NOTIFICATION or TYPE_ALARM
        }
    }

    // @formatter:off
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            //.setSound(soundUri)
            .setSmallIcon(R.drawable.ic_push_icon).setContentTitle(getResources().getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setLights(0xFFff0000, 500, 500) // flashing red light
            .setContentText(msg).setAutoCancel(true)
            //.setPriority(Notification.FLAG_HIGH_PRIORITY)
            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.FLAG_SHOW_LIGHTS);
    // @formatter:on

    if (soundUri != null) {
        mBuilder.setSound(soundUri);
    }
    mBuilder.setPriority(PRIORITY_MAX);
    mBuilder.setContentIntent(contentIntent);

    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}