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

The following examples show how to use android.app.Activity#startService() . These examples are extracted from open source projects. 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
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
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
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
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 5
@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 6
Source Project: ti.goosh   File: TiGooshModule.java    License: 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 Project: Telecine   File: CaptureHelper.java    License: 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 8
Source Project: MHViewer   File: DownloadsScene.java    License: 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 Project: MHViewer   File: DownloadsScene.java    License: 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 10
Source Project: EhViewer   File: DownloadsScene.java    License: 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 11
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 12
public static void upServer(Activity activity) {
    if (isRunning) {
        Intent intent = new Intent(activity, ShareService.class);
        intent.setAction(ActionStartService);
        activity.startService(intent);
    }
}
 
Example 13
Source Project: LLApp   File: SensonListener.java    License: 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
@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 15
Source Project: AndroidPlugin   File: ActivityOverider.java    License: 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 16
/**
 * 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 17
Source Project: EhViewer   File: DownloadsScene.java    License: 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 18
public static void startThis(Activity activity) {
    Intent intent = new Intent(activity, WebService.class);
    intent.setAction(ActionStartService);
    activity.startService(intent);
}
 
Example 19
Source Project: Android   File: HttpsService.java    License: 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 20
Source Project: amiibo   File: SyncService.java    License: 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);
}