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.gigathinking.simpleapplock.ResetUnlockMethod.java

@Override
public void onBackPressed() {
    finish();/*w w  w  .  j ava 2s .  co m*/
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

From source file:com.android.talkbacktests.testsession.NotificationTest.java

private void showCustomNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext()).setAutoCancel(true)
            .setSmallIcon(android.R.drawable.ic_notification_overlay)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    RemoteViews contentView = new RemoteViews(getContext().getPackageName(), R.layout.custom_notification);
    contentView.setImageViewResource(R.id.notification_image, android.R.drawable.ic_dialog_email);
    contentView.setTextViewText(R.id.notification_title, getString(R.string.custom_notification_title));
    contentView.setTextViewText(R.id.notification_text, getString(R.string.custom_notification_text));
    builder.setContent(contentView);//from w w w  .j  a  v  a  2s  .  c om

    Intent resultIntent = new Intent(getContext(), MainActivity.class);
    resultIntent.setAction(Intent.ACTION_MAIN);
    resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, resultIntent, 0);
    builder.setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID_LAST_VIEW, builder.build());
}

From source file:com.gigaset.home.Home.java

/**
 * Loads the list of installed applications in mApplications.
 *//*www  .j a v  a2  s  .co  m*/
private void loadApplications(boolean isLaunching) {

    if (isLaunching && mApplications != null) {
        return;
    }

    PackageManager manager = getPackageManager();

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

    final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
    Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));

    if (apps != null) {
        final int count = apps.size();

        if (mApplications == null) {
            mApplications = new ArrayList<ApplicationInfo>(count);
        }
        mApplications.clear();

        ApplicationInfo application;
        // ********************* ADD Key Pad **********************************
        application = new ApplicationInfo();
        application.title = "Key Pad";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_iocon_key_pad);
        application.setActivity(
                new ComponentName("com.android.contacts", "com.android.contacts.activities.DialtactsActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Messages *********************************
        application = new ApplicationInfo();
        application.title = "Messages";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_icon_messages);
        application.setActivity(new ComponentName("com.android.mms", "com.android.mms.ui.ConversationList"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Contacts *********************************
        application = new ApplicationInfo();
        application.title = "Contacts";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_icon_contacts);
        application.setActivity(
                new ComponentName("com.android.contacts", "com.android.contacts.activities.PeopleActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Call Log *********************************
        // http://hi-android.info/src/index.html            
        application = new ApplicationInfo();
        application.title = "Call List";
        application.icon = getResources().getDrawable(R.drawable.main_screen_icon_call_log);

        application.setActivityWithAction(Intent.ACTION_VIEW, CallLog.Calls.CONTENT_TYPE);
        mApplications.add(application);

        // ********************* ADD Browser **********************************
        application = new ApplicationInfo();
        application.title = "Browser";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_icon_browser);
        application.setActivity(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Call Settings ****************************
        application = new ApplicationInfo();
        application.title = "Call Settings";
        application.icon = application.icon = getResources()
                .getDrawable(R.drawable.main_screen_icon_call_settings);
        application.setActivity(new ComponentName("com.android.settings", "com.android.settings.Settings"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        //            
        //            for (int i = 0; i < count; i++) 
        //            {
        //                ApplicationInfo application = new ApplicationInfo();
        //                ResolveInfo info = apps.get(i);
        //
        //                application.title = info.loadLabel(manager);
        //                application.setActivity(new ComponentName(
        //                        info.activityInfo.applicationInfo.packageName,
        //                        info.activityInfo.name),
        //                        Intent.FLAG_ACTIVITY_NEW_TASK
        //                        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        //                
        //                Log.v("Home APP", "package neme= "+info.activityInfo.applicationInfo.packageName);
        //                Log.v("Home APP", "neme= "+info.activityInfo.name);
        //                Log.v("Home APP", "title= "+application.title);
        //                
        //                
        //                application.icon = info.activityInfo.loadIcon(manager);
        //                
        //                // Replace Icons
        //                if((application.title+"").equals("Browser"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_browser);
        //                if((application.title+"").equals("Phone"))       application.icon = getResources().getDrawable(R.drawable.main_screen_iocon_key_pad);
        //                if((application.title+"").equals("People"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_contacts);
        //                if((application.title+"").equals("Messaging"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_messages);
        //                if((application.title+"").equals("Settings"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_call_settings);
        //                //if((application.title+"").equals("Call Log")) application.icon = getResources().getDrawable(R.drawable.main_screen_icon_call_log);
        //                
        //                // Add Application
        //                if((application.title+"").equals("Browser"))    mApplications.add(application);
        //                if((application.title+"").equals("Phone"))       mApplications.add(application);
        //                if((application.title+"").equals("People"))    mApplications.add(application);
        //                if((application.title+"").equals("Messaging"))    mApplications.add(application);
        //                if((application.title+"").equals("Settings"))    mApplications.add(application);
        //
        //            }

    }
}

From source file:org.thomnichols.android.gmarks.WebViewLoginActivity.java

protected void showTwoFactorAuthDialog() {
    dismissWaitDialog();/* ww w .  j a v  a2  s  .c  om*/

    final Intent launchAuthIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
            .setClassName(AUTHENTICATOR_PACKAGE, "com.google.android.apps.authenticator.AuthenticatorActivity");

    ResolveInfo ri = getPackageManager().resolveActivity(launchAuthIntent, 0);
    if (ri == null) {
        WebViewLoginActivity.this.showAuthenticatorMissingDialog();
        return;
    }
    Log.d(TAG, "Resolve info: " + ri);

    new AlertDialog.Builder(this).setTitle(R.string.two_factor_auth_dlg_title)
            .setMessage(Html.fromHtml(getString(R.string.two_factor_auth_dlg_msg))).setCancelable(true)
            .setNegativeButton(R.string.btn_cancel, new OnClickListener() {
                public void onClick(DialogInterface dlg, int _) {
                    dlg.dismiss();
                }
            }).setPositiveButton(R.string.btn_ok, new OnClickListener() {
                public void onClick(DialogInterface dlg, int _) {
                    //               dlg.dismiss();
                    try {
                        startActivity(launchAuthIntent);
                    } catch (ActivityNotFoundException ex) {
                        Log.d(TAG, "Activity not found", ex);
                        WebViewLoginActivity.this.showAuthenticatorMissingDialog();
                    }
                    //               catch ( Exception ex ) {
                    //                  Log.w(TAG,"Unexpected exception from activity launch",ex);
                    //               }
                }
            }).show();
}

From source file:com.wrmndfzzy.atomize.intro.IntroActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length <= 0 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
            // permission denied, boo! Disable the
            // functionality that depends on this permission.
            Toast.makeText(IntroActivity.this, "Read permissions are required to run this app.",
                    Toast.LENGTH_LONG).show();
            Intent homeIntent = new Intent(Intent.ACTION_MAIN);
            homeIntent.addCategory(Intent.CATEGORY_HOME);
            homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(homeIntent);//  w  w  w.  j a v a  2s.co m
        } else {
            Toast.makeText(IntroActivity.this, "Read permissions granted!", Toast.LENGTH_SHORT).show();
        }
        break;
    }

    case MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length <= 0 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
            // permission denied, boo! Disable the
            // functionality that depends on this permission.
            Toast.makeText(IntroActivity.this, "Write permissions are required to run this app.",
                    Toast.LENGTH_LONG).show();
            Intent homeIntent = new Intent(Intent.ACTION_MAIN);
            homeIntent.addCategory(Intent.CATEGORY_HOME);
            homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(homeIntent);
        } else {
            Toast.makeText(IntroActivity.this, "Write permissions granted!", Toast.LENGTH_SHORT).show();
        }
        break;
    }
    }
}

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

public static void connectingNotify(String account) {
    JTalkService service = JTalkService.getInstance();
    Intent i = new Intent(service, RosterActivity.class);
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(service, 0, i, 0);

    String str = service.getString(R.string.Connecting);
    service.setGlobalState(str + ": " + account);
    service.sendBroadcast(new Intent(Constants.UPDATE));

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(service);
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(service.getResources(), R.drawable.ic_launcher));
    mBuilder.setSmallIcon(R.drawable.stat_offline);
    mBuilder.setContentTitle(str);//from   w w w . j av  a  2s  . com
    mBuilder.setContentText(account);
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
    mBuilder.setProgress(0, 0, true);

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

From source file:com.amaze.filemanager.asynchronous.services.CopyService.java

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {

    Bundle b = new Bundle();
    isRootExplorer = intent.getBooleanExtra(TAG_IS_ROOT_EXPLORER, false);
    ArrayList<HybridFileParcelable> files = intent.getParcelableArrayListExtra(TAG_COPY_SOURCES);
    String targetPath = intent.getStringExtra(TAG_COPY_TARGET);
    int mode = intent.getIntExtra(TAG_COPY_OPEN_MODE, OpenMode.UNKNOWN.ordinal());
    final boolean move = intent.getBooleanExtra(TAG_COPY_MOVE, false);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(c);
    accentColor = ((AppConfig) getApplication()).getUtilsProvider().getColorPreference()
            .getCurrentUserColorPreferences(this, sharedPreferences).accent;

    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    b.putInt(TAG_COPY_START_ID, startId);

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    customSmallContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_small);
    customBigContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_big);

    Intent stopIntent = new Intent(TAG_BROADCAST_COPY_CANCEL);
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(c, 1234, stopIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_content_copy_white_36dp,
            getString(R.string.stop_ftp), stopPendingIntent);

    mBuilder = new NotificationCompat.Builder(c, NotificationConstants.CHANNEL_NORMAL_ID)
            .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_content_copy_white_36dp)
            .setCustomContentView(customSmallContentViews).setCustomBigContentView(customBigContentViews)
            .setCustomHeadsUpContentView(customSmallContentViews)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle()).addAction(action).setOngoing(true)
            .setColor(accentColor);//  ww  w .  jav  a 2 s. c  o  m

    // set default notification views text

    NotificationConstants.setMetadata(c, mBuilder, NotificationConstants.TYPE_NORMAL);

    startForeground(NotificationConstants.COPY_ID, mBuilder.build());
    initNotificationViews();

    b.putBoolean(TAG_COPY_MOVE, move);
    b.putString(TAG_COPY_TARGET, targetPath);
    b.putInt(TAG_COPY_OPEN_MODE, mode);
    b.putParcelableArrayList(TAG_COPY_SOURCES, files);

    super.onStartCommand(intent, flags, startId);
    super.progressHalted();
    //going async
    new DoInBackground(isRootExplorer).execute(b);

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

From source file:com.wso2.mobile.mdm.DisplayDeviceInfoActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && FROM_ACTIVITY != null
            && FROM_ACTIVITY.equals(AlreadyRegisteredActivity.class.getSimpleName())) {
        Intent intent = new Intent(DisplayDeviceInfoActivity.this, AlreadyRegisteredActivity.class);
        intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
                DisplayDeviceInfoActivity.class.getSimpleName());
        intent.putExtra(getResources().getString(R.string.intent_extra_regid), REG_ID);
        startActivity(intent);/*from ww  w  . j ava2  s .c  o  m*/
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BACK) {
        Intent i = new Intent();
        i.setAction(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_HOME);
        this.startActivity(i);
        this.finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:edu.mit.mobile.android.locast.itineraries.ItineraryList.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_grid_activity);
    mProgressBar = (NotificationProgressBar) (findViewById(R.id.progressNotification));

    findViewById(R.id.refresh).setOnClickListener(this);
    findViewById(R.id.home).setOnClickListener(this);

    mListView = (GridView) findViewById(android.R.id.list);
    mListView.setOnItemClickListener(this);
    mListView.setEmptyView(findViewById(R.id.progressNotification));
    mRefresh = (RefreshButton) findViewById(R.id.refresh);
    mRefresh.setOnClickListener(this);

    final Intent intent = getIntent();
    final String action = intent.getAction();

    mImageCache = ImageCache.getInstance(this);

    if (Intent.ACTION_VIEW.equals(action)) {
        loadData(intent.getData());//w  ww.  j a v a2s  . c  om

    } else if (Intent.ACTION_MAIN.equals(action)) {
        loadData(Itinerary.CONTENT_URI);
    }
}

From source file:com.magnet.mmx.client.MMXWakeupIntentService.java

private void invokeNotificationForPush(GCMPayload payload) {
    // Launch the activity with action=MAIN, category=DEFAULT.  Make sure that
    // it has DEFAULT category declared in AndroidManifest.xml intent-filter.
    PendingIntent intent = PendingIntent.getActivity(this.getApplicationContext(), 0,
            new Intent(Intent.ACTION_MAIN).setPackage(this.getPackageName())
                    .addCategory(Intent.CATEGORY_DEFAULT) // it is redundant
                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                    .addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED),
            PendingIntent.FLAG_UPDATE_CURRENT);
    // If title is not specified, use the app name (compatible with iOS push notification)
    String title = (payload.getTitle() == null) ? this.getApplicationInfo().name : payload.getTitle();
    Notification.Builder noteBuilder = new Notification.Builder(this).setContentIntent(intent)
            .setAutoCancel(true).setWhen(System.currentTimeMillis()).setContentTitle(title)
            .setContentText(payload.getBody());
    if (payload.getSound() != null) {
        // TODO: cannot handle custom sound yet; use notification ring tone.
        noteBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    }/*from  w  ww  .j av a 2 s .  c  o m*/
    if (payload.getIcon() != null) {
        noteBuilder.setSmallIcon(
                this.getResources().getIdentifier(payload.getIcon(), "drawable", this.getPackageName()));
    } else {
        noteBuilder.setSmallIcon(this.getApplicationInfo().icon);
    }
    if (payload.getBadge() != null) {
        noteBuilder.setNumber(payload.getBadge());
    }
    NotificationManager noteMgr = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    noteMgr.notify(sNoteId++, noteBuilder.build());
}