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.pmarks.chromadoze.NoiseService.java

private Notification makeNotify() {
    // android:launchMode="singleTask" ensures that the latest instance
    // of the Activity will be reachable from the Launcher.  However, a
    // naive Intent can still overwrite the task, so we track down the
    // existing task by pretending to be the Launcher.
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ChromaDoze.class)
            .setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER), 0);

    Notification n = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_bars).setWhen(0)
            .setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.notification_text))
            .setContentIntent(contentIntent).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build();

    // Add a Stop button to the Notification bar.  Not trying to support
    // this pre-ICS, because the click detection and styling are weird.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        addButtonToNotification(n);/*from  w  w w .ja  v a2s  . c  o  m*/
    }
    return n;
}

From source file:mf.stickybit.android.trackergps.LoginActivity.java

public void checkLogin(boolean isLogin) {
    if (isLogin) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancelAll();
        final Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(Intent.ACTION_MAIN);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        Notification notification = new NotificationCompat.Builder(this)
                .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0))
                .setSmallIcon(R.drawable.trackergps_icon)
                .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.trackergps_icon))
                .setTicker("TrackerGPS").setWhen(System.currentTimeMillis()).setAutoCancel(false)
                .setContentTitle("TrackerGPS esta ejecutandose").setContentText("A la espera...").build();
        notification.flags |= Notification.FLAG_NO_CLEAR;
        notificationManager.notify(0, notification);

        moveTaskToBack(true);//w  ww.  j ava  2s.c  o m
    } else {
        if ((getCantidadFails() == (getResources().getInteger(R.integer.login_max_retry)))) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Fallo "
                    + String.valueOf(
                            (int) getApplicationContext().getResources().getInteger(R.integer.login_max_retry))
                    + " veces al iniciar sesin.")
                    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            finish();
                        }
                    });
            builder.show();
        } else {
            clear();
            mPasswordView.setError(getString(R.string.error_incorrect_password));
            mPasswordView.requestFocus();
        }

    }
}

From source file:com.fvd.nimbus.MainActivity.java

public static void createShortcut(Context context) {

    Intent shortcutIntent = new Intent(context, MainActivity.class);
    shortcutIntent.setAction(Intent.ACTION_MAIN);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Nimbus Clipper");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, R.drawable.app_icon));
    addIntent.putExtra("duplicate", false);
    addIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);// ww w. j av a 2s  .  c  om
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
}

From source file:com.oo58.game.texaspoker.AppActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //         this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED);//
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    mContext = AppActivity.this;

    try {/*from www . jav  a2s  . c o m*/
        ApplicationInfo appInfo = this.getPackageManager().getApplicationInfo(getPackageName(),
                PackageManager.GET_META_DATA);
        String msg = appInfo.metaData.getString("data_Name");

        //         int channelid = Integer.parseInt(msg) ;
        //         
        //         System.out.println(channelid);

    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    mAct = this;
    allContext = this.getApplicationContext();
    mTencent = Tencent.createInstance("1104823392", getApplicationContext());
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "MyLock");
    mWakeLock.acquire();

    MobclickAgent.setDebugMode(false);
    MobclickAgent.updateOnlineConfig(this);
    AnalyticsConfig.enableEncrypt(true);

    checkUpdate();

    PackageManager pm2 = getPackageManager();
    homeInfo = pm2.resolveActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 0);

    mNetChecker.initAndRegListener(mContext);

    mWXPay.init(this);

    MobClickCppHelper.init(this);

    //      // logcatdebug
    //       XGPushConfig.enableDebug(this, true);
    //      // registerPush(getApplicationContext(), XGIOperateCallback)callback
    //      // registerPush(getApplicationContext(),account)
    //      // 
    //      // ApplicationContext
    //      Context context = getApplicationContext();
    //      XGPushManager.registerPush(context);    
    //       
    //      // 2.362
    //      Intent service = new Intent(context, XGPushService.class);
    //      context.startService(service);

    // API
    // registerPush(context,account)registerPush(context,account, XGIOperateCallback)accountAPPqqopenid
    // registerPush(context,"*")account="*"
    // unregisterPush(context)
    // setTag(context, tagName)
    // deleteTag(context, tagName)

    updateListViewReceiver = new MsgReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("com.oo58.game.texaspoker.activity.UPDATE_LISTVIEW");
    registerReceiver(updateListViewReceiver, intentFilter);

    XGPushManager.registerPush(getApplicationContext(), new XGIOperateCallback() {
        @Override
        public void onSuccess(Object data, int flag) {
            //                  Log.w(Constants.LogTag,
            //                        "+++ register push sucess. token:" + data);

        }

        @Override
        public void onFail(Object data, int errCode, String msg) {
            //                  Log.w(Constants.LogTag,
            //                        "+++ register push fail. token:" + data
            //                              + ", errCode:" + errCode + ",msg:"
            //                              + msg);

        }
    });

    //javajosnC++demo
    /*      JSONObject jsonObj = new JSONObject();  
            try {
             jsonObj.put("Int_att",25);
               jsonObj.put("String_att","str");//string  
               jsonObj.put("Double_att",12.25);//double  
               jsonObj.put("Boolean_att",true);//boolean  
          } catch (JSONException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
          }//int  
            
            PushJson(jsonObj.toString()) ;*/

}

From source file:org.chromium.chrome.browser.preferences.Preferences.java

/**
 * Starts a new Preferences activity showing the desired fragment.
 *
 * @param fragmentClass The Class of the fragment to show.
 * @param args Arguments to pass to Fragment.instantiate(), or null.
 *///w w w. j a  v  a2s.co m
public void startFragment(String fragmentClass, Bundle args) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClass(this, getClass());
    intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentClass);
    intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
    startActivity(intent);
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == android.R.id.home) {
        finish();/*from w  w w  .  j av  a  2s.  c om*/
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_list_activity);

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

    mListView = (ListView) findViewById(android.R.id.list);
    mListView.setOnItemClickListener(this);
    mListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.list_footer, null), null, false);
    mListView.setEmptyView(findViewById(android.R.id.empty));
    mRefresh = (RefreshButton) findViewById(R.id.refresh);
    mRefresh.setOnClickListener(this);
    if (Constants.USE_APPUPDATE_CHECKER) {
        mAppUpdateChecker = new AppUpdateChecker(this, getString(R.string.app_update_url),
                new AppUpdateChecker.OnUpdateDialog(this, getString(R.string.app_name)));
        mAppUpdateChecker.checkForUpdates();
    }//from  ww w.j  av a  2  s  . co m

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

    mImageCache = ImageCache.getInstance(this);

    firstTime = checkFirstTime();

    if (REQUIRE_LOGIN) {
        final NetworkClient nc = NetworkClient.getInstance(this);

        if (!nc.isAuthenticated()) {
            startActivityForResult(new Intent(this, AuthenticatorActivity.class), REQUEST_SIGNIN);
            return;
        }
    }

    if (Intent.ACTION_VIEW.equals(action)) {
        loadData(intent.getData());

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

}

From source file:com.example.android.home.Home.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Close the menu
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        getWindow().closeAllPanels();/* w  w w.j  a v a  2  s  .co m*/
    }
}

From source file:de.azapps.mirakel.dashclock.MirakelExtension.java

@Override
protected void onUpdateData(final int reason) {
    // Get values from Settings
    final Optional<ListMirakel> listMirakelOptional = SettingsHelper.getList();
    if (!listMirakelOptional.isPresent()) {
        reportError(this, getString(R.string.list_not_found), getString(R.string.list_not_found_message));
        return;//from ww  w .j  a v a  2  s.c o  m
    }
    final int maxTasks = SettingsHelper.getMaxTasks();
    final ListMirakel listMirakel = listMirakelOptional.get();
    final MirakelQueryBuilder mirakelQueryBuilder = listMirakel.getTasksQueryBuilder();
    final Cursor cursor;
    try {
        cursor = mirakelQueryBuilder.query(Task.URI);
    } catch (final SecurityException ignored) {
        reportError(this, getString(R.string.no_permission_title), getString(R.string.no_permission));
        return;
    } catch (final RuntimeException e) {
        reportError(this, getString(R.string.cannot_communicate), getString(R.string.unexpected_error));
        Log.e(TAG, "Cannot communicate to Mirakel", e);
        return;
    }
    // Set Status
    if (cursor.getCount() == 0 && !SettingsHelper.showEmpty()) {
        Log.d(TAG, "hide");
        publishUpdate(new ExtensionData().visible(false));
    } else {
        final boolean showDue = SettingsHelper.showDue();
        final SimpleDateFormat dateFormat = new SimpleDateFormat(getString(R.string.due_outformat),
                Locale.getDefault());

        final String status = getResources().getQuantityString(R.plurals.status, cursor.getCount(),
                cursor.getCount());
        final String tasks[] = new String[Math.min(maxTasks, cursor.getCount())];
        int i = 0;
        while (cursor.moveToNext() && i < maxTasks) {
            final Task task = MirakelQueryBuilder.cursorToObject(cursor, Task.class);
            final Optional<Calendar> dueOptional = task.getDue();
            final StringBuilder taskRow = new StringBuilder();
            if (dueOptional.isPresent() && showDue) {
                taskRow.append(dateFormat.format(dueOptional.get().getTime())).append(": ");
            }
            taskRow.append(task.getName());
            tasks[i] = taskRow.toString();
            i++;
        }
        cursor.close();

        // Add click-event
        final Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setComponent(
                new ComponentName("de.azapps.mirakelandroid", "de.azapps.mirakel.main_activity.MainActivity"));
        intent.setAction("de.azapps.mirakel.SHOW_LIST");
        intent.putExtra("de.azapps.mirakel.EXTRA_LIST_ID", listMirakel.getId());
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        // Set Content
        publishUpdate(new ExtensionData().visible(true).icon(R.drawable.ic_mirakel).status(status)
                .expandedBody(TextUtils.join("\n", tasks)).clickIntent(intent));
    }
}

From source file:com.uphyca.testing.junit3.support.v4.FragmentUnitTestCase.java

private void attachActivity(Object lastNonConfigurationInstance) throws Exception {
    if (mActivityAttached) {
        return;/*w  w w.j  a  va  2s  . com*/
    }

    IBinder token = null;
    if (mApplication == null) {
        setApplication(new MockApplication());
    }
    if (mActivity == null) {
        setActivity(new MockFragmentActivity());
    }
    ComponentName cn = new ComponentName(mActivity.getClass().getPackage().getName(),
            mActivity.getClass().getName());
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setComponent(cn);
    ActivityInfo info = new ActivityInfo();
    CharSequence title = mActivity.getClass().getName();
    mMockParent = new MockParent();
    String id = null;
    ActivityTrojanHorse.callAttach(getInstrumentation(), mActivity, mFragmentContext, token, mApplication,
            intent, info, title, mMockParent, id, lastNonConfigurationInstance);

    mActivityAttached = true;
}