List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:com.google.android.apps.mytracks.samples.api.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from w w w .j a va2s .com*/ // for the MyTracks content provider myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); outputTextView = (TextView) findViewById(R.id.output); latTV = (TextView) findViewById(R.id.lat); lonTV = (TextView) findViewById(R.id.lon); timeTV = (TextView) findViewById(R.id.time); accuracyTV = (TextView) findViewById(R.id.accuracy); altitudeTV = (TextView) findViewById(R.id.altitude); speedTV = (TextView) findViewById(R.id.speed); bearingTV = (TextView) findViewById(R.id.bearing); Button addWaypointsButton = (Button) findViewById(R.id.add_waypoints_button); addWaypointsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { List<Track> tracks = myTracksProviderUtils.getAllTracks(); Calendar now = Calendar.getInstance(); for (Track track : tracks) { Waypoint waypoint = new Waypoint(); waypoint.setTrackId(track.getId()); waypoint.setName(now.getTime().toLocaleString()); waypoint.setDescription(now.getTime().toLocaleString()); myTracksProviderUtils.insertWaypoint(waypoint); } } }); // for the MyTracks service intent = new Intent(); ComponentName componentName = new ComponentName(getString(R.string.mytracks_service_package), getString(R.string.mytracks_service_class)); intent.setComponent(componentName); Button startRecordingButton = (Button) findViewById(R.id.start_recording_button); startRecordingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (myTracksService != null) { try { myTracksService.startNewTrack(); } catch (RemoteException e) { Log.e(TAG, "RemoteException", e); } // rborisov start posting every X seconds timer = new Timer(); timer.schedule(new TimerTask() { @SuppressWarnings("unused") @Override public void run() { // Track lastTrack; Location loc; // lastTrack = myTracksProviderUtils.getLastTrack(); // outputTextView.append(" -" + lastTrack.getId() + "- "); loc = myTracksProviderUtils.getLastValidTrackPoint();//lastTrack.getId()); if (loc != null) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://track.rborisov.me/trackmspost.php"); try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs .add(new BasicNameValuePair("lat", String.valueOf(loc.getLatitude()))); nameValuePairs .add(new BasicNameValuePair("lon", String.valueOf(loc.getLongitude()))); nameValuePairs .add(new BasicNameValuePair("time", String.valueOf(loc.getTime()))); nameValuePairs.add( new BasicNameValuePair("accuracy", String.valueOf(loc.getAccuracy()))); nameValuePairs.add( new BasicNameValuePair("altitude", String.valueOf(loc.getAltitude()))); nameValuePairs .add(new BasicNameValuePair("speed", String.valueOf(loc.getSpeed()))); nameValuePairs.add( new BasicNameValuePair("bearing", String.valueOf(loc.getBearing()))); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); } catch (ClientProtocolException e) { Log.e(TAG, "ClientProtocolException", e); } catch (IOException e) { Log.e(TAG, "IOException", e); } } } }, 0, 30 * 1000); // rborisov end } } }); Button stopRecordingButton = (Button) findViewById(R.id.stop_recording_button); stopRecordingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (myTracksService != null) { try { myTracksService.endCurrentTrack(); timer.cancel(); timer.purge(); } catch (RemoteException e) { Log.e(TAG, "RemoteException", e); } } } }); }
From source file:com.perm.DoomPlay.PlayingService.java
@Override public void onCreate() { super.onCreate(); isLoadingTrack = false;//from w w w . java 2 s. c om isShuffle = false; isPlaying = true; isLoop = false; afListener = new AFListener(); audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.requestAudioFocus(afListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); ComponentName componentName = new ComponentName(this, MediaButtonReceiver.class); audioManager.registerMediaButtonEventReceiver(componentName); ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).listen(callListener, CallListener.LISTEN_CALL_STATE); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); serviceAlive = true; bassPlayer = new BassPlayer(); bassPlayer.setOnCompletetion(this); }
From source file:cn.studyjams.s2.sj0119.NForget.AlarmReceiver.java
public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification timein Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using initial notification time and repeat interval time mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, RepeatTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:com.emotion.emotioncontrol.MainActivity.java
public void setLauncherIconEnabled(boolean enabled) { PackageManager p = getPackageManager(); int newState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; p.setComponentEnabledSetting(new ComponentName(this, LauncherActivity.class), newState, PackageManager.DONT_KILL_APP); }
From source file:com.cerema.cloud2.ui.dialog.ShareLinkToDialog.java
private AlertDialog createSelector(final boolean sendAction) { int titleId;/*from ww w.j a va 2 s. com*/ if (sendAction) { titleId = R.string.activity_chooser_send_file_title; } else { titleId = R.string.activity_chooser_title; } return new AlertDialog.Builder(getActivity()).setTitle(titleId) .setAdapter(mAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Add the information of the chosen activity to the intent to send ResolveInfo chosen = mAdapter.getItem(which); ActivityInfo actInfo = chosen.activityInfo; ComponentName name = new ComponentName(actInfo.applicationInfo.packageName, actInfo.name); mIntent.setComponent(name); // Send the file getActivity().startActivity(mIntent); } }).create(); }
From source file:at.diamonddogs.util.Utils.java
/** * Brings up the MAIN/LAUNCHER activity and clears the top * * @param context a {@link Context}/*w ww . ja v a 2 s . co m*/ */ public static void returnToHome(Context context) { PackageManager pm = context.getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(context.getPackageName()); List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0); Intent homeIntent = new Intent("android.intent.action.MAIN"); homeIntent.addCategory("android.intent.category.LAUNCHER"); homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); homeIntent.setComponent(new ComponentName(context.getPackageName(), activities.get(0).activityInfo.name)); context.startActivity(homeIntent); }
From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java
public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AutomuteAlarmReceiver.class); intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification timein Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using initial notification time and repeat interval time mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, RepeatTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:com.max2idea.android.fwknop.Fwknop.java
private void startApp() { Intent i = new Intent(Intent.ACTION_RUN); i.setComponent(new ComponentName("org.connectbot", "org.connectbot.HostListActivity")); PackageManager p = this.getPackageManager(); List list = p.queryIntentActivities(i, p.COMPONENT_ENABLED_STATE_DEFAULT); if (list.isEmpty()) { Log.v("SPA", "ConnectBot is not installed"); Toast.makeText(this, "ConnectBot is not installed", Toast.LENGTH_LONG).show(); } else {/*from w ww . j a v a 2s .co m*/ Log.v("SPA", "Starting connectBot"); Toast.makeText(this, "Starting ConnectBot", Toast.LENGTH_LONG); startActivity(i); } }
From source file:co.carlosandresjimenez.android.gotit.notification.AlarmReceiver.java
/** * Sets a repeating alarm that runs once a day at approximately 8:30 a.m. When the * alarm fires, the app broadcasts an Intent to this WakefulBroadcastReceiver. * * @param context/*from www. j a va 2 s. c o m*/ */ public void setAlarm(Context context) { // If the alarm has been set, cancel it. if (alarmMgr != null) { alarmIntent.cancel(); alarmMgr.cancel(alarmIntent); } alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); int userFrequencySetting = Utility.getNotificationFrequency(context); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.HOUR, userFrequencySetting); // Set the alarm to fire in X hours according to the device's // clock and user settings, and to repeat according to user settings alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), userFrequencySetting * ONE_HOUR_MILLISECONDS, alarmIntent); ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:org.jboss.aerogear.android.sync.SyncService.java
@Override public void onCreate() { try {//from w ww. java 2 s .co m super.onCreate(); ComponentName myService = new ComponentName(this, this.getClass()); Bundle data = getPackageManager().getServiceInfo(myService, PackageManager.GET_META_DATA).metaData; if (data.getString(SERVER_HOST) == null) { throw new IllegalStateException(SERVER_HOST + " may not be null"); } if (data.getString(SERVER_PATH) == null) { throw new IllegalStateException(SERVER_PATH + " may not be null"); } if (data.getInt(SERVER_PORT, -1) == -1) { throw new IllegalStateException(SERVER_PORT + " may not be null"); } JsonPatchClientSynchronizer synchronizer = new JsonPatchClientSynchronizer(); ClientInMemoryDataStore<JsonNode, JsonPatchEdit> dataStore = new ClientInMemoryDataStore<JsonNode, JsonPatchEdit>(); ClientSyncEngine<JsonNode, JsonPatchEdit> clientSyncEngine = new ClientSyncEngine<JsonNode, JsonPatchEdit>( synchronizer, dataStore, new DefaultPatchObservable<JsonNode>()); syncClient = NettySyncClient.<JsonNode, JsonPatchEdit>forHost(data.getString(SERVER_HOST)) .port(data.getInt(SERVER_PORT)).path(data.getString(SERVER_PATH)).syncEngine(clientSyncEngine) .build(); Log.i(SyncService.class.getName(), "onCreated"); } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.getMessage(), ex); throw new IllegalStateException(ex); } }