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.fitc.dooropener.lib.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param status GCM message received./* w ww  .j  a  va2s .  c o  m*/
 */
private void sendNotification(GcmDataPayload status) {

    /**
     * This code should find launcher activity of app using this librbary and set it as the what gets launched
     */
    Intent intent = null;
    final PackageManager packageManager = getPackageManager();
    Log.i(TAG, "PACKAGE NAME " + getPackageName());

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

    List<ResolveInfo> appList = packageManager.queryIntentActivities(mainIntent, 0);

    for (final ResolveInfo resolveInfo : appList) {
        if (getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)
        {
            intent = packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
            break;
        }
    }
    PendingIntent pendingIntent = null;
    if (intent != null) {
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        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)
            .setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setContentTitle(getResources().getString(R.string.notif_content_title))
            .setContentText(status.getStatusData()).setAutoCancel(true).setSound(defaultSoundUri);

    if (pendingIntent != null) {
        notificationBuilder.setContentIntent(pendingIntent);
    }

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

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

From source file:info.balthaus.geologrenewed.app.service.BackgroundService.java

@SuppressLint("NewApi")
@Override/*w w w . j  a  v  a 2 s  .c  o  m*/
public void onCreate() {
    super.onCreate();
    Debug.log("Service created");

    if (thread == null) {
        Debug.log("Launching thread");
        thread = new ServiceThread();
        thread.setContext(getApplicationContext());
        thread.start();
    }

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GeoLog Wakelock");

    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.setClass(this, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent = PendingIntent.getActivity(this, 0, i, 0);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = (new Notification.Builder(this)).setSmallIcon(R.drawable.ic_stat_service)
            .setContentIntent(notificationIntent).setWhen(System.currentTimeMillis()).setAutoCancel(false)
            .setOngoing(true).setContentTitle(getString(R.string.service_title))
            .setContentText(getString(R.string.service_waiting));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        notificationBuilder.setShowWhen(false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        /* quick turn off, maybe ? if added, make sure to add a button to preferences to disable these buttons
        notificationBuilder.
        setPriority(Notification.PRIORITY_MAX).
        addAction(0, "A", notificationIntent).
        addAction(0, "B", notificationIntent).
        addAction(0, "C", notificationIntent);
        */
    }

    updateNotification();
}

From source file:org.alfresco.mobile.android.application.security.PassCodeActivity.java

@Override
public void onBackPressed() {
    // We go back to the device home.
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(startMain);//w  w w .j a  va  2s. c  om
}

From source file:com.google.android.gms.nearby.messages.samples.hellobeacons.BackgroundSubscribeIntentService.java

private void updateNotification() {
    List<String> messages = Utils.getCachedMessages(getApplicationContext());
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    Intent launchIntent = new Intent(getApplicationContext(), MainActivity.class);
    launchIntent.setAction(Intent.ACTION_MAIN);
    launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, launchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    String contentTitle = getContentTitle(messages);
    String contentText = "Deseja abrir a porta?";

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_digitaldesk_big).setContentTitle(contentTitle)
            .setContentText(contentText).setStyle(new NotificationCompat.BigTextStyle().bigText(contentText))
            .setOngoing(false).setContentIntent(pi);
    notificationManager.notify(MESSAGES_NOTIFICATION_ID, notificationBuilder.build());
}

From source file:com.filemanager.free.services.CopyService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) throws NullPointerException {
    Bundle b = new Bundle();
    ArrayList<BaseFile> files = intent.getParcelableArrayListExtra("FILE_PATHS");
    String FILE2 = intent.getStringExtra("COPY_DIRECTORY");
    int mode = intent.getIntExtra("MODE", 0);
    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    b.putInt("id", startId);
    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.putExtra("openprocesses", true);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    mBuilder = new NotificationCompat.Builder(c);
    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setContentTitle(getResources().getString(R.string.copying))

            .setSmallIcon(R.drawable.ic_content_copy_white_36dp);
    if (foreground) {
        startForeground(Integer.parseInt("456" + startId), mBuilder.build());
        foreground = false;// ww  w.ja  v  a  2  s  . c o m
    }
    b.putBoolean("move", intent.getBooleanExtra("move", false));
    b.putString("FILE2", FILE2);
    b.putInt("MODE", mode);
    b.putParcelableArrayList("files", files);
    hash.put(startId, true);
    DataPackage intent1 = new DataPackage();
    intent1.setName(files.get(0).getName());
    intent1.setTotal(0);
    intent1.setDone(0);
    intent1.setId(startId);
    intent1.setP1(0);
    intent1.setP2(0);
    intent1.setMove(intent.getBooleanExtra("move", false));
    intent1.setCompleted(false);
    hash1.put(startId, intent1);
    //going async
    new DoInBackground().execute(b);

    // If we get killed, after returning from here, restart
    return START_STICKY;
}

From source file:org.pquery.Main.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // We only want single instance of this activity at top
    // If launched via a notification and by normal icon android can try
    //to create another copy of activity down stack
    // Don't want that so pop superfluus activity
    ////from   w w w.  j  a  v  a2s.  c om
    // http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ
    if (!isTaskRoot()) {
        final Intent intent = getIntent();
        final String intentAction = intent.getAction();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null
                && intentAction.equals(Intent.ACTION_MAIN)) {
            Logger.w("Not root. Finishing Main Activity instead of launching");
            finish();
            return;
        }
    }

    // Make Jericho form parsing case sensitive
    Config.CurrentCompatibilityMode = Config.CompatibilityMode.MOZILLA;

    // Enable logging (if pref set)
    // If first time logging has been initialised a new log file will be created
    Logger.setEnable(Prefs.getDebug(this));
    Logger.d("enter");

    // Enable progress bar at top of window
    requestWindowFeature(Window.FEATURE_PROGRESS);

    setContentView(R.layout.main2);

    String title = getIntent().getStringExtra("title");
    if (title != null)
        doDialog = true;
}

From source file:org.totschnig.myexpenses.activity.ManageCategories.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();//from  ww  w. j  a v a 2 s. c  om
    String action = intent.getAction();
    int title = 0;
    switch (action == null ? "" : action) {
    case Intent.ACTION_MAIN:
    case "myexpenses.intent.manage.categories":
        helpVariant = HelpVariant.manage;
        title = R.string.pref_manage_categories_title;
        break;
    case "myexpenses.intent.distribution":
        helpVariant = HelpVariant.distribution;
        //title is set in categories list
        break;
    case "myexpenses.intent.select_filter":
        helpVariant = HelpVariant.select_filter;
        title = R.string.search_category;
        break;
    default:
        helpVariant = HelpVariant.select_mapping;
        title = R.string.select_category;
    }
    setTheme(helpVariant.equals(HelpVariant.distribution) ? MyApplication.getThemeId()
            : MyApplication.getThemeIdEditDialog());
    super.onCreate(savedInstanceState);
    if (helpVariant.equals(HelpVariant.distribution)) {
        DisplayMetrics dm = getResources().getDisplayMetrics();

        final int REL_SWIPE_MIN_DISTANCE = (int) (SWIPE_MIN_DISTANCE * dm.densityDpi / 160.0f);
        final int REL_SWIPE_MAX_OFF_PATH = (int) (SWIPE_MAX_OFF_PATH * dm.densityDpi / 160.0f);
        final int REL_SWIPE_THRESHOLD_VELOCITY = (int) (SWIPE_THRESHOLD_VELOCITY * dm.densityDpi / 160.0f);
        mDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                //http://stackoverflow.com/questions/937313/android-basic-gesture-detection
                try {
                    if (Math.abs(e1.getY() - e2.getY()) > REL_SWIPE_MAX_OFF_PATH)
                        return false;
                    if (e1.getX() - e2.getX() > REL_SWIPE_MIN_DISTANCE
                            && Math.abs(velocityX) > REL_SWIPE_THRESHOLD_VELOCITY) {
                        mListFragment.forward();
                        return true;
                    } else if (e2.getX() - e1.getX() > REL_SWIPE_MIN_DISTANCE
                            && Math.abs(velocityX) > REL_SWIPE_THRESHOLD_VELOCITY) {
                        mListFragment.back();
                        return true;
                    }
                } catch (Exception e) {
                }
                return false;
            }
        });
    }
    setContentView(R.layout.select_category);
    setupToolbar(true);
    if (title != 0)
        getSupportActionBar().setTitle(title);
    FragmentManager fm = getSupportFragmentManager();
    mListFragment = ((CategoryList) fm.findFragmentById(R.id.category_list));
    if (helpVariant.equals(HelpVariant.select_mapping) || helpVariant.equals(HelpVariant.manage)) {
        configureFloatingActionButton(R.string.menu_create_main_cat);
    } else {
        findViewById(R.id.CREATE_COMMAND).setVisibility(View.GONE);
    }
}

From source file:org.ohmage.fragments.StreamsFragment.java

/**
 * Checks for multiple different intents that might launch the stream.
 *//*from   w  ww. j  a  v a2  s. com*/
private Intent launchStreamIntent(AppEntry app) {
    String packageName = app.getInfo().packageName;
    Intent intent;

    // Check for the new action configure
    intent = new Intent(StreamContract.ACTION_CONFIGURE).setPackage(packageName);
    if (Util.activityExists(getActivity(), intent)) {
        return intent;
    }

    // Check for the old action configure
    intent = new Intent("org.ohmage.probes.ACTION_CONFIGURE").setPackage(packageName).setDataAndType(null,
            "*/*");
    if (Util.activityExists(getActivity(), intent)) {
        return intent;
    }

    // Check for a main activity
    intent = new Intent(Intent.ACTION_MAIN).setPackage(packageName);
    if (Util.activityExists(getActivity(), intent)) {
        return intent;
    }

    // Any activity will work...
    intent = new Intent().setPackage(packageName);
    if (Util.activityExists(getActivity(), intent)) {
        return intent;
    }

    return null;
}

From source file:hku.fyp14017.blencode.utils.StatusBarNotificationManager.java

public int createCopyNotification(Context context, String programName) {
    if (context == null || programName == null) {
        return -1;
    }/*w w w  .j a  v  a2  s  .c  o m*/
    initNotificationManager(context);

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

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

    NotificationData data = new NotificationData(context, pendingIntent,
            hku.fyp14017.blencode.R.drawable.ic_stat, programName,
            hku.fyp14017.blencode.R.string.notification_copy_title_pending,
            hku.fyp14017.blencode.R.string.notification_title_open,
            hku.fyp14017.blencode.R.string.notification_copy_pending,
            hku.fyp14017.blencode.R.string.notification_copy_finished);

    int id = createNotification(context, data);
    showOrUpdateNotification(id, 0);
    return id;
}

From source file:com.gigathinking.simpleapplock.UnlockWithGesture.java

@Override
public void onBackPressed() {
    if (changeLock) {
        setResult(AppLockApplication.RESULT_NOT_OK);
        finish();/*  w  w  w. jav  a2 s . c om*/
        return;
    }
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}