Java Code Examples for android.app.Activity#startService()

The following examples show how to use android.app.Activity#startService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VoIPHelper.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static void doInitiateCall(TLRPC.User user, Activity activity) {
	if (activity == null || user == null) {
		return;
	}
	if (System.currentTimeMillis() - lastCallTime < 2000)
		return;
	lastCallTime = System.currentTimeMillis();
	Intent intent = new Intent(activity, VoIPService.class);
	intent.putExtra("user_id", user.id);
	intent.putExtra("is_outgoing", true);
	intent.putExtra("start_incall_activity", true);
	intent.putExtra("account", UserConfig.selectedAccount);
	try {
		activity.startService(intent);
	} catch (Throwable e) {
		FileLog.e(e);
	}
}
 
Example 2
Source File: VoIPHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static void doInitiateCall(TLRPC.User user, Activity activity) {
	if (activity == null || user == null) {
		return;
	}
	if (System.currentTimeMillis() - lastCallTime < 2000)
		return;
	lastCallTime = System.currentTimeMillis();
	Intent intent = new Intent(activity, VoIPService.class);
	intent.putExtra("user_id", user.id);
	intent.putExtra("is_outgoing", true);
	intent.putExtra("start_incall_activity", true);
	intent.putExtra("account", UserConfig.selectedAccount);
	try {
		activity.startService(intent);
	} catch (Throwable e) {
		FileLog.e(e);
	}
}
 
Example 3
Source File: VoIPHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static void doInitiateCall(TLRPC.User user, Activity activity) {
	if (activity == null || user==null) {
		return;
	}
	if(System.currentTimeMillis()-lastCallTime<2000)
		return;
	lastCallTime=System.currentTimeMillis();
	Intent intent = new Intent(activity, VoIPService.class);
	intent.putExtra("user_id", user.id);
	intent.putExtra("is_outgoing", true);
	intent.putExtra("start_incall_activity", true);
	intent.putExtra("account", UserConfig.selectedAccount);
	try {
		activity.startService(intent);
	} catch (Throwable e) {
		FileLog.e(e);
	}
}
 
Example 4
Source File: CaptureHelper.java    From Telecine with Apache License 2.0 6 votes vote down vote up
static boolean handleActivityResult(Activity activity, int requestCode, int resultCode,
    Intent data, Analytics analytics) {
  if (requestCode != CREATE_SCREEN_CAPTURE) {
    return false;
  }

  if (resultCode == Activity.RESULT_OK) {
    Timber.d("Acquired permission to screen capture. Starting service.");
    activity.startService(TelecineService.newIntent(activity, resultCode, data));
  } else {
    Timber.d("Failed to acquire permission to screen capture.");
  }

  analytics.send(new HitBuilders.EventBuilder() //
      .setCategory(Analytics.CATEGORY_SETTINGS)
      .setAction(Analytics.ACTION_CAPTURE_INTENT_RESULT)
      .setValue(resultCode)
      .build());

  return true;
}
 
Example 5
Source File: DownloadFileIntentService.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
public static void startService(Activity activity, Parcelable[] downloadables, final ProgressBar progressBar, final TextView progressView, final ProgressBarDialogFragment.IProgressChangeListener iProgressChangeListener) {
    Intent intent = new Intent(activity, DownloadFileIntentService.class);
    intent.setAction(DownloadResultReceiver.DOWNLOAD_ACTION);
    intent.putExtra(DownloadResultReceiver.EXTRA_KEY, new DownloadResultReceiver(new Handler()) {
        @Override
        public ProgressBar getProgressBar() {
            return progressBar;
        }

        @Override
        public TextView getProgressView() {
            return progressView;
        }

        @Override
        public ProgressBarDialogFragment.IProgressChangeListener getProgressChangeListener() {
            return iProgressChangeListener;
        }
    });
    intent.putExtra(DownloadResultReceiver.EXTRA_FILES_KEY, downloadables);
    activity.startService(intent);
}
 
Example 6
Source File: TiGooshModule.java    From ti.goosh with MIT License 6 votes vote down vote up
@Kroll.method
public void registerForPushNotifications(HashMap options) {
	Activity activity = TiApplication.getAppRootOrCurrentActivity();

	if (false == options.containsKey("callback")) {
		Log.e(LCAT, "You have to specify a callback attribute when calling registerForPushNotifications");
		return;
	}

	messageCallback = (KrollFunction)options.get("callback");

	successCallback = options.containsKey("success") ? (KrollFunction)options.get("success") : null;
	errorCallback = options.containsKey("error") ? (KrollFunction)options.get("error") : null;

	parseBootIntent();

	if (checkPlayServices()) {
		activity.startService( new Intent(activity, RegistrationIntentService.class) );
	}
}
 
Example 7
Source File: UpdateFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onDeviceSelected(final BluetoothDevice device, final String name) {
    if (mConnectionProgressDialog != null) {
        mConnectionProgressDialog.setTitle(getString(R.string.prog_dialog_connect_title));
        mConnectionProgressDialog.setMessage(getString(R.string.prog_dialog_connect_message));
        mConnectionProgressDialog.show();
    }

    final Activity activity = getActivity();
    final Intent service = new Intent(activity, UpdateService.class);
    service.putExtra(UpdateService.EXTRA_DATA, device);
    updateUiForBeacons(BluetoothProfile.STATE_CONNECTED, UpdateService.LOCKED);
    activity.startService(service);
    mBounnd = true;
    activity.bindService(service, mServiceConnection, 0);
}
 
Example 8
Source File: DownloadsScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
    // Skip when in choice mode
    Activity activity = getActivity2();
    if (null == activity || null == mRecyclerView || mRecyclerView.isInCustomChoice()) {
        return false;
    }

    int id = item.getItemId();
    switch (id) {
        case R.id.action_start_all: {
            Intent intent = new Intent(activity, DownloadService.class);
            intent.setAction(DownloadService.ACTION_START_ALL);
            activity.startService(intent);
            return true;
        }
        case R.id.action_stop_all: {
            if (null != mDownloadManager) {
                mDownloadManager.stopAllDownload();
            }
            return true;
        }
        case R.id.action_reset_reading_progress: {
            new AlertDialog.Builder(getContext())
                    .setMessage(R.string.reset_reading_progress_message)
                    .setNegativeButton(android.R.string.cancel, null)
                    .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                        if (mDownloadManager != null) {
                            mDownloadManager.resetAllReadingProgress();
                        }
                    }).show();
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: DownloadsScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
    // Skip when in choice mode
    Activity activity = getActivity2();
    if (null == activity || null == mRecyclerView || mRecyclerView.isInCustomChoice()) {
        return false;
    }

    int id = item.getItemId();
    switch (id) {
        case R.id.action_start_all: {
            Intent intent = new Intent(activity, DownloadService.class);
            intent.setAction(DownloadService.ACTION_START_ALL);
            activity.startService(intent);
            return true;
        }
        case R.id.action_stop_all: {
            if (null != mDownloadManager) {
                mDownloadManager.stopAllDownload();
            }
            return true;
        }
        case R.id.action_reset_reading_progress: {
            new AlertDialog.Builder(getContext())
                    .setMessage(R.string.reset_reading_progress_message)
                    .setNegativeButton(android.R.string.cancel, null)
                    .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                        if (mDownloadManager != null) {
                            mDownloadManager.resetAllReadingProgress();
                        }
                    }).show();
            return true;
        }
    }
    return false;
}
 
Example 10
Source File: GpsServiceUtilities.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Start the service.
 *
 * @param activity the activity to use.
 */
public static void startGpsService(Activity activity) {
    Intent intent = new Intent(activity, GpsService.class);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        activity.startForegroundService(intent);
    } else {
        activity.startService(intent);
    }

}
 
Example 11
Source File: ActivityOverider.java    From AndroidPlugin with MIT License 5 votes vote down vote up
/**
 * 覆盖 StarService 方法
 * 
 * @param intent
 * @param fromAct
 */
public static ComponentName overrideStartService(Activity fromAct,
        String pluginId, Intent intent) {
    // TODO 覆盖 StarService 方法
    Log.d(tag, "overrideStartService");
    return fromAct.startService(intent);
}
 
Example 12
Source File: PlaylistFragment.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Activity containerActivity = getActivity();
    Intent playlistIntent = new Intent(containerActivity, MediaPlayerService.class);
    if (MediaPlayerService.mHasLaunched) {
        if (!mBound) {
            containerActivity.bindService(playlistIntent, mConnection, Context.BIND_AUTO_CREATE);
        }
    } else {
        containerActivity.startService(playlistIntent);
        containerActivity.bindService(playlistIntent, mConnection, Context.BIND_AUTO_CREATE);
    }
}
 
Example 13
Source File: SensonListener.java    From LLApp with Apache License 2.0 5 votes vote down vote up
public void startService(Activity activity){
    //开启服务
    Intent intent = new Intent(activity,AidlService.class);
    activity.startService(intent);
    //连接远程Service和Activity
    Intent bindIntent = new Intent(activity,AidlService.class);
    activity.bindService(bindIntent,sc,BIND_AUTO_CREATE);
}
 
Example 14
Source File: ShareService.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
public static void upServer(Activity activity) {
    if (isRunning) {
        Intent intent = new Intent(activity, ShareService.class);
        intent.setAction(ActionStartService);
        activity.startService(intent);
    }
}
 
Example 15
Source File: ShareService.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
public static void startThis(Activity activity, List<BookSourceBean> bookSourceBeans) {
    String key = String.valueOf(System.currentTimeMillis());
    BitIntentDataManager.getInstance().putData(key, bookSourceBeans);
    Intent intent = new Intent(activity, ShareService.class);
    intent.putExtra("data_key", key);
    intent.setAction(ActionStartService);
    activity.startService(intent);
}
 
Example 16
Source File: DownloadsScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    Context context = getContext2();
    Activity activity = getActivity2();
    EasyRecyclerView recyclerView = mRecyclerView;
    if (null == context || null == activity || null == recyclerView || recyclerView.isInCustomChoice()) {
        return;
    }
    List<DownloadInfo> list = mList;
    if (list == null) {
        return;
    }
    int size = list.size();
    int index = recyclerView.getChildAdapterPosition(itemView);
    if (index < 0 || index >= size) {
        return;
    }

    if (thumb == v) {
        Bundle args = new Bundle();
        args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO);
        args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, list.get(index));
        Announcer announcer = new Announcer(GalleryDetailScene.class).setArgs(args);
        announcer.setTranHelper(new EnterGalleryDetailTransaction(thumb));
        startScene(announcer);
    } else if (start == v) {
        Intent intent = new Intent(activity, DownloadService.class);
        intent.setAction(DownloadService.ACTION_START);
        intent.putExtra(DownloadService.KEY_GALLERY_INFO, list.get(index));
        activity.startService(intent);
    } else if (stop == v) {
        if (null != mDownloadManager) {
            mDownloadManager.stopDownload(list.get(index).gid);
        }
    }
}
 
Example 17
Source File: DownloadsScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    Context context = getContext2();
    Activity activity = getActivity2();
    EasyRecyclerView recyclerView = mRecyclerView;
    if (null == context || null == activity || null == recyclerView || recyclerView.isInCustomChoice()) {
        return;
    }
    List<DownloadInfo> list = mList;
    if (list == null) {
        return;
    }
    int size = list.size();
    int index = recyclerView.getChildAdapterPosition(itemView);
    if (index < 0 || index >= size) {
        return;
    }

    if (thumb == v) {
        Bundle args = new Bundle();
        args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO);
        args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, list.get(index));
        Announcer announcer = new Announcer(GalleryDetailScene.class).setArgs(args);
        announcer.setTranHelper(new EnterGalleryDetailTransaction(thumb));
        startScene(announcer);
    } else if (start == v) {
        Intent intent = new Intent(activity, DownloadService.class);
        intent.setAction(DownloadService.ACTION_START);
        intent.putExtra(DownloadService.KEY_GALLERY_INFO, list.get(index));
        activity.startService(intent);
    } else if (stop == v) {
        if (null != mDownloadManager) {
            mDownloadManager.stopDownload(list.get(index).gid);
        }
    }
}
 
Example 18
Source File: HttpsService.java    From Android with MIT License 4 votes vote down vote up
public static void startService(Activity activity) {
    Intent intent = new Intent(activity, HttpsService.class);
    activity.startService(intent);
}
 
Example 19
Source File: WebService.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public static void startThis(Activity activity) {
    Intent intent = new Intent(activity, WebService.class);
    intent.setAction(ActionStartService);
    activity.startService(intent);
}
 
Example 20
Source File: SyncService.java    From amiibo with GNU General Public License v2.0 4 votes vote down vote up
public static void start(Activity parent) {
    Intent service = new Intent(parent, SyncService.class);
    parent.startService(service);
}