List of usage examples for android.content Intent ACTION_MAIN
String ACTION_MAIN
To view the source code for android.content Intent ACTION_MAIN.
Click Source Link
From source file:com.jecelyin.editor.v2.ui.MainActivity.java
private boolean processIntentImpl() throws Throwable { Intent intent = getIntent();/*w w w.java 2s . co m*/ L.d("intent=" + intent); if (intent == null) return true; //pass hint String action = intent.getAction(); // action == null if change theme if (action == null || Intent.ACTION_MAIN.equals(action)) { return true; } if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)) { if (intent.getScheme().equals("content")) { InputStream attachment = getContentResolver().openInputStream(intent.getData()); String text = IOUtils.toString(attachment); openText(text); return true; } else if (intent.getScheme().equals("file")) { Uri mUri = intent.getData(); String file = mUri != null ? mUri.getPath() : null; if (!TextUtils.isEmpty(file)) { openFile(file); return true; } } } else if (Intent.ACTION_SEND.equals(action) && intent.getExtras() != null) { Bundle extras = intent.getExtras(); CharSequence text = extras.getCharSequence(Intent.EXTRA_TEXT); if (text != null) { openText(text); return true; } else { Object stream = extras.get(Intent.EXTRA_STREAM); if (stream != null && stream instanceof Uri) { openFile(((Uri) stream).getPath()); return true; } } } return false; }
From source file:org.zywx.wbpalmstar.engine.universalex.EUExWidget.java
private String getMainActivity(String pkgName) { String className = null;/*from www.java2 s. com*/ PackageInfo pi = null; try { pi = mContext.getPackageManager().getPackageInfo(pkgName, 0); } catch (NameNotFoundException e) { e.printStackTrace(); } if (pi == null) return null; Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); resolveIntent.setPackage(pi.packageName); List<ResolveInfo> apps = mContext.getPackageManager().queryIntentActivities(resolveIntent, 0); if (apps == null || apps.size() == 0) return null; ResolveInfo ri = apps.iterator().next(); if (ri != null) { className = ri.activityInfo.name; } return className; }
From source file:com.quickcar.thuexe.UI.ListPassengerActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { if (doubleBackToExitPressedOnce) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);//from w w w. j av a 2 s . c o m } else { Toast.makeText(mContext, getResources().getString(R.string.notice_close_app), Toast.LENGTH_SHORT) .show(); this.doubleBackToExitPressedOnce = true; new Handler().postDelayed(new Runnable() { @Override public void run() { doubleBackToExitPressedOnce = false; } }, 2000); } return true; } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 1) { finish(); } return super.onKeyDown(keyCode, event); }
From source file:com.dnielfe.manager.AppManager.java
private void createshortcut() { Intent shortcutIntent = new Intent(AppManager.this, AppManager.class); shortcutIntent.setAction(Intent.ACTION_MAIN); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.appmanager)); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(AppManager.this, R.drawable.type_apk)); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); AppManager.this.sendBroadcast(addIntent); Toast.makeText(AppManager.this, getString(R.string.shortcutcreated), Toast.LENGTH_SHORT).show(); }
From source file:com.android.launcher4.InstallShortcutReceiver.java
private static ShortcutInfo getShortcutInfo(Context context, Intent data, Intent launchIntent) { if (launchIntent.getAction() == null) { launchIntent.setAction(Intent.ACTION_VIEW); } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) && launchIntent.getCategories() != null && launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); }/*from w ww . ja va 2 s. c o m*/ LauncherAppState app = LauncherAppState.getInstance(); ShortcutInfo info = app.getModel().infoFromShortcutIntent(context, data, null); info.title = ensureValidName(context, launchIntent, info.title); return info; }
From source file:edu.missouri.bas.service.SensorService.java
@SuppressWarnings("deprecation") @Override//ww w . j a v a2s . co m public void onCreate() { super.onCreate(); Log.d(TAG, "Starting sensor service"); mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100); soundsMap = new HashMap<Integer, Integer>(); soundsMap.put(SOUND1, mSoundPool.load(this, R.raw.bodysensor_alarm, 1)); soundsMap.put(SOUND2, mSoundPool.load(this, R.raw.voice_notification, 1)); serviceContext = this; mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothMacAddress = mBluetoothAdapter.getAddress(); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); //Get location manager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); activityRecognition = new ActivityRecognitionScan(getApplicationContext()); activityRecognition.startActivityRecognitionScan(); mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); serviceWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SensorServiceLock"); serviceWakeLock.acquire(); //Initialize start time stime = System.currentTimeMillis(); //Setup calendar object Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(stime); /* * Setup notification manager */ notification = new Notification(R.drawable.icon2, "Recorded", System.currentTimeMillis()); notification.defaults = 0; notification.flags |= Notification.FLAG_ONGOING_EVENT; notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent notifyIntent = new Intent(Intent.ACTION_MAIN); notifyIntent.setClass(this, MainActivity.class); /* * Display notification that service has started */ notification.tickerText = "Sensor Service Running"; PendingIntent contentIntent = PendingIntent.getActivity(SensorService.this, 0, notifyIntent, Notification.FLAG_ONGOING_EVENT); notification.setLatestEventInfo(SensorService.this, getString(R.string.app_name), "Recording service started at: " + cal.getTime().toString(), contentIntent); notificationManager.notify(SensorService.SERVICE_NOTIFICATION_ID, notification); // locationControl = new LocationControl(this, mLocationManager, 1000 * 60, 200, 5000); IntentFilter activityResultFilter = new IntentFilter(XMLSurveyActivity.INTENT_ACTION_SURVEY_RESULTS); SensorService.this.registerReceiver(alarmReceiver, activityResultFilter); IntentFilter sensorDataFilter = new IntentFilter(SensorService.ACTION_SENSOR_DATA); SensorService.this.registerReceiver(alarmReceiver, sensorDataFilter); Log.d(TAG, "Sensor service created."); try { prepareIO(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } prepareAlarms(); Intent startSensors = new Intent(SensorService.ACTION_START_SENSORS); this.sendBroadcast(startSensors); Intent scheduleCheckConnection = new Intent(SensorService.ACTION_SCHEDULE_CHECK); scheduleCheck = PendingIntent.getBroadcast(serviceContext, 0, scheduleCheckConnection, 0); mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000 * 60 * 5, 1000 * 60 * 5, scheduleCheck); mLocationClient = new LocationClient(this, this, this); }
From source file:net.ustyugov.jtalk.Notify.java
public static void fileProgress(String filename, Status status) { 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); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(service); mBuilder.setContentTitle(filename);//from w ww . j av a2 s.c o m mBuilder.setContentIntent(contentIntent); mBuilder.setOngoing(false); if (status == Status.complete) { mBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done); mBuilder.setTicker(service.getString(R.string.Completed)); mBuilder.setContentText(service.getString(R.string.Completed)); mBuilder.setAutoCancel(true); } else if (status == Status.cancelled) { mBuilder.setSmallIcon(android.R.drawable.stat_sys_warning); mBuilder.setTicker(service.getString(R.string.Canceled)); mBuilder.setContentText(service.getString(R.string.Canceled)); mBuilder.setAutoCancel(true); } else if (status == Status.refused) { mBuilder.setSmallIcon(android.R.drawable.stat_sys_warning); mBuilder.setTicker(service.getString(R.string.Canceled)); mBuilder.setContentText(service.getString(R.string.Canceled)); mBuilder.setAutoCancel(true); } else if (status == Status.negotiating_transfer) { mBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done); mBuilder.setTicker(service.getString(R.string.Waiting)); mBuilder.setContentText(service.getString(R.string.Waiting)); } else if (status == Status.in_progress) { mBuilder.setSmallIcon(android.R.drawable.stat_sys_download); mBuilder.setTicker(service.getString(R.string.Downloading)); mBuilder.setContentText(service.getString(R.string.Downloading)); } else if (status == Status.error) { mBuilder.setSmallIcon(android.R.drawable.stat_sys_warning); mBuilder.setTicker(service.getString(R.string.Error)); mBuilder.setContentText(service.getString(R.string.Error)); mBuilder.setAutoCancel(true); } else { return; } NotificationManager mng = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE); mng.notify(NOTIFICATION_FILE, mBuilder.build()); }
From source file:com.jedi.setupwizard.ui.SetupWizardActivity.java
private void finalizeSetup() { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); disableSetupWizards(intent);/*from w ww . j a v a 2s .c om*/ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); finish(); }
From source file:com.gizwits.framework.activity.BaseActivity.java
/** * ??app/*from w w w . jav a 2 s .c om*/ */ public void exit() { if (!isExit) { isExit = true; Toast.makeText(getApplicationContext(), getString(R.string.tip_exit), Toast.LENGTH_SHORT).show(); handler.sendEmptyMessageDelayed(0, 2000); } else { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); Historys.exit(); } }
From source file:com.nbplus.vbroadlauncher.HomeLauncherActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); boolean isTablet = DisplayUtils.isTabletDevice(this); LauncherSettings.getInstance(this).setIsSmartPhone(!isTablet); overridePendingTransition(R.anim.fade_in, R.anim.fade_out); setContentView(R.layout.activity_home_launcher); DeviceUtils.showDeviceInformation(); Log.d(TAG, ">>>DisplayUtils.getScreenDensity(this) = " + DisplayUtils.getScreenDensity(this)); // vitamio library load if (!LibsChecker.checkVitamioLibs(this)) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() { @Override// w ww. j av a2 s. com public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); alert.setMessage(R.string.alert_media_message); alert.show(); return; } mCurrentLocale = getResources().getConfiguration().locale; if (BuildConfig.DEBUG) { Point p = DisplayUtils.getScreenSize(this); Log.d(TAG, "Screen size px = " + p.x + ", py = " + p.y); Point screen = p; p = DisplayUtils.getScreenDp(this); Log.d(TAG, "Screen dp x = " + p.x + ", y = " + p.y); int density = DisplayUtils.getScreenDensity(this); Log.d(TAG, "Screen density = " + density); } if (isTablet) { //is tablet Log.d(TAG, "Tablet"); } else { //is phone Log.d(TAG, "isTabletDevice() returns Phone.. now check display inches"); double diagonalInches = DisplayUtils.getDisplayInches(this); if (diagonalInches >= 6.4) { // 800x400 ? portrait ? 6.43 ? . // 6.5inch device or bigger Log.d(TAG, "DisplayUtils.getDisplayInches() bigger than 6.5"); } else { if (!Constants.OPEN_BETA_PHONE) { // smaller device Log.d(TAG, "DisplayUtils.getDisplayInches() smaller than 6.5"); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); alert.setMessage(R.string.alert_phone_message); alert.show(); return; } } } if (!Constants.OPEN_BETA_PHONE || !LauncherSettings.getInstance(this).isSmartPhone()) { if (isMyLauncherDefault()) { Log.d(TAG, "isMyLauncherDefault() == true"); // fake home key event. Intent fakeIntent = new Intent(); fakeIntent.setAction(Intent.ACTION_MAIN); fakeIntent.addCategory(Intent.CATEGORY_HOME); fakeIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); startActivity(fakeIntent); } else { Log.d(TAG, "Constants.OPEN_BETA_PHONE == false || isMyLauncherDefault() == false"); //resetPreferredLauncherAndOpenChooser(); } } // ? .. ? ? ?. // ? ?. IntentFilter filter = new IntentFilter(); filter.addAction(Constants.ACTION_LAUNCHER_ACTIVITY_RUNNING); filter.addAction(IoTConstants.ACTION_RECEIVE_EMERGENCY_CALL_DEVICE_BROADCAST); LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, filter); Intent intent = new Intent(Constants.ACTION_LAUNCHER_ACTIVITY_RUNNING); mActivityRunningTime = System.currentTimeMillis(); intent.putExtra(Constants.EXTRA_LAUNCHER_ACTIVITY_RUNNING, mActivityRunningTime); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); // set background image setContentViewByOrientation(); if (LauncherSettings.getInstance(this).getPreferredUserLocation() == null) { Location defaultLocation = new Location("stub"); defaultLocation.setLongitude(126.929810); defaultLocation.setLatitude(37.488201); LauncherSettings.getInstance(this).setPreferredUserLocation(defaultLocation); } // First we need to check availability of play services mResultReceiver = new AddressResultReceiver(mActivityHandler); // Set defaults, then update using values stored in the Bundle. mAddressRequested = false; mAddressOutput = null; // Update values using data stored in the Bundle. updateValuesFromBundle(savedInstanceState); /** * ? ??? ? . * ?? ? . */ mBroadcastFramelayout = (FrameLayout) findViewById(R.id.realtimeBroadcastFragment); if (mBroadcastFramelayout != null) { mBroadcastFramelayout.setVisibility(View.GONE); } FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Bundle bundle; // check installation or bind to service VBroadcastServer serverInfo = LauncherSettings.getInstance(this).getServerInformation(); if (serverInfo == null || !Constants.VBROAD_INITIAL_PAGE.equals(serverInfo.getInitialServerPage())) { // ? ?. // ? Registration ? . LauncherSettings.getInstance(this).setServerInformation(null); LauncherSettings.getInstance(this).setIsCompletedSetup(false); // open user register fragment RegisterFragment registerFragment = new RegisterFragment(); bundle = new Bundle(); registerFragment.setArguments(bundle); fragmentTransaction.replace(R.id.launcherFragment, registerFragment); } else { if (LauncherSettings.getInstance(this).isCompletedSetup() == false) { LauncherSettings.getInstance(this).setServerInformation(null); // open user register fragment RegisterFragment registerFragment = new RegisterFragment(); bundle = new Bundle(); registerFragment.setArguments(bundle); fragmentTransaction.replace(R.id.launcherFragment, registerFragment); } else { // open main launcher fragment LauncherFragment launcherFragment = new LauncherFragment(); bundle = new Bundle(); launcherFragment.setArguments(bundle); fragmentTransaction.replace(R.id.launcherFragment, launcherFragment); } } fragmentTransaction.commit(); // initialize iot interface. String collectServerAddress = null; if (serverInfo != null) { String apiServer = serverInfo.getApiServer(); if (StringUtils.isEmptyString(apiServer)) { collectServerAddress = null; } else { collectServerAddress = apiServer + Constants.API_COLLECTED_IOT_DATA_CONTEXT; } } IoTResultCodes resCode = IoTInterface.getInstance().initialize(this, LauncherSettings.getInstance(this).getDeviceID(), collectServerAddress); if (!resCode.equals(IoTResultCodes.SUCCESS)) { if (resCode.equals(IoTResultCodes.BIND_SERVICE_FAILED)) { Toast.makeText(getApplicationContext(), "Bind IoT Service failed!!!", Toast.LENGTH_SHORT).show(); } } }