android.content.Intent#setAction ( )源码实例Demo

下面列出了android.content.Intent#setAction ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: InviZible   文件: MainActivity.java
private void checkUpdates() {

        if (appVersion.equals("gp") || appVersion.equals("fd")) {
            return;
        }

        Intent intent = getIntent();
        if (Objects.equals(intent.getAction(), "check_update")) {
            if (topFragment != null) {
                topFragment.checkNewVer();
                modernDialog = modernProgressDialog();
            }

            intent.setAction(null);
            setIntent(intent);
        }
    }
 
源代码2 项目: Rhythm   文件: RhythmNotificationService.java
private NotificationCompat.Builder makeCommonNotification(String text) {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.arl_rhythm)
            .setCategory(NotificationCompat.CATEGORY_SERVICE)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setAutoCancel(false)
            .setShowWhen(false)
            .setContentText(text)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(text));

    // Old androids throw an exception when the notification doesn't have content intent
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        Intent contentAction = new Intent(this, RhythmNotificationService.class);
        contentAction.setAction(ACTION_NEXT_OVERLAY);
        PendingIntent piContentAction = PendingIntent.getService(this, 0, contentAction, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(piContentAction);
    }

    return builder;
}
 
源代码3 项目: Bailan   文件: AppInfoUtils.java
public static void showInstalledAppDetails(Context context, String packageName) {
    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;
    if (apiLevel >= 9) { // 2.3(ApiLevel 9)以上,使用SDK提供的接口
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
        intent.setData(uri);
    } else { // 2.3以下,使用非公开的接口(查看InstalledAppDetails源码)
        // 2.2和2.1中,InstalledAppDetails使用的APP_PKG_NAME不同。
        final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
                : APP_PKG_NAME_21);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName(APP_DETAILS_PACKAGE_NAME,
                APP_DETAILS_CLASS_NAME);
        intent.putExtra(appPkgName, packageName);
    }
    context.startActivity(intent);
}
 
源代码4 项目: InviZible   文件: ModulesKiller.java
private static void sendStopIntent(Context context, String action) {
    Intent intent = new Intent(context, ModulesService.class);
    intent.setAction(action);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        intent.putExtra("showNotification", true);
        context.startForegroundService(intent);
    } else {
        intent.putExtra("showNotification", isShowNotification(context));
        context.startService(intent);
    }
}
 
源代码5 项目: gcm-android-client   文件: InstanceIDService.java
/**
 * Called if InstanceID token is updated. This may occur if the security of
 * the previous token had been compromised. This call is initiated by the
 * InstanceID provider.
 */
@Override
public void onTokenRefresh() {
  // Fetch updated Instance ID token and notify our app's server of any changes (if applicable).
  Intent intent = new Intent(this, RegistrationIntentService.class);
  intent.setAction(RegistrationIntentService.ACTION_REGISTER);
  startService(intent);
}
 
源代码6 项目: revolution-irc   文件: IRCService.java
public static void start(Context context) {
    Intent intent = new Intent(context, IRCService.class);
    intent.setAction(ACTION_START_FOREGROUND);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        context.startForegroundService(intent);
    else
        context.startService(intent);
}
 
private void launchDownloader() {
    try {
        Intent launchIntent = SampleDownloaderActivity.this
                .getIntent();
        Intent intentToLaunchThisActivityFromNotification = new Intent(
                SampleDownloaderActivity
                        .this, SampleDownloaderActivity.this.getClass());
        intentToLaunchThisActivityFromNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                |
                Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intentToLaunchThisActivityFromNotification.setAction(launchIntent.getAction());

        if (launchIntent.getCategories() != null) {
            for (String category : launchIntent.getCategories()) {
                intentToLaunchThisActivityFromNotification.addCategory(category);
            }
        }

        if (DownloaderClientMarshaller.startDownloadServiceIfRequired(this,
                PendingIntent.getActivity(SampleDownloaderActivity
                                .this,
                        0, intentToLaunchThisActivityFromNotification,
                        PendingIntent.FLAG_UPDATE_CURRENT),
                SampleDownloaderService.class) != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
            initializeDownloadUI();
            return;
        } // otherwise we fall through to starting the movie
    } catch (NameNotFoundException e) {
        Log.e(LOG_TAG, "Cannot find own package! MAYDAY!");
        e.printStackTrace();
    }
}
 
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
		int[] appWidgetIds) {
	// TODO 0 Make it possible to add the simple widget to the homescreen
	// via Android Manifest

	// TODO 1 Get the component name for MyWidgetProviderSimple.class
	// instead of Void.class
	ComponentName thisWidget = new ComponentName(context, Void.class);
	int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
	for (int widgetId : allWidgetIds) {
		// Create some random data
		int number = (new Random().nextInt(100));

		// TODO 2 Use widgetsimple_layout.xml as layout instead of -1
		RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
				-1);
		Log.w("WidgetExample", String.valueOf(number));
		// TODO 3 Set the text to the view with the id R.id.update
		// instead of -1
		remoteViews.setTextViewText(-1, String.valueOf(number));

		// Register an onClickListener
		Intent intent = new Intent(context, MyWidgetProviderSimple.class);

		intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
		intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

		PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
				0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
		// TODO 4 Add pending intent to the text view with the id
		// R.id.update
		// remoteViews.setOnClickPendingIntent();

		appWidgetManager.updateAppWidget(widgetId, remoteViews);
	}
}
 
源代码9 项目: PowerSwitch_Android   文件: UnknownErrorDialog.java
private void reportExceptionViaMail() throws Exception {
    Intent emailIntent = new Intent();
    emailIntent.setAction(Intent.ACTION_SENDTO);
    emailIntent.setType("*/*");
    emailIntent.setData(Uri.parse("mailto:")); // only email apps should handle this
    emailIntent.putExtra(Intent.EXTRA_EMAIL, DEFAULT_EMAILS);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Unknown Error - " + throwable.getClass().getSimpleName() +
            ": " + throwable.getMessage());
    emailIntent.putExtra(Intent.EXTRA_TEXT, getEmailContentText());
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(LogHandler.getLogsAsZip(this)));

    startActivity(Intent.createChooser(emailIntent, getString(R.string.send_to)));
}
 
源代码10 项目: android-utils   文件: Utils.java
/**
 * @param ctx
 * @param savingUri
 * @param durationInSeconds
 * @return
 * @deprecated Use {@link MediaUtils#createTakeVideoIntent(Activity, Uri, int)}
 * Creates an intent to take a video from camera or gallery or any other application that can
 * handle the intent.
 */
public static Intent createTakeVideoIntent(Activity ctx, Uri savingUri, int durationInSeconds) {

    if (savingUri == null) {
        throw new NullPointerException("Uri cannot be null");
    }

    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    final PackageManager packageManager = ctx.getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, savingUri);
        intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationInSeconds);
        cameraIntents.add(intent);
    }

    // Filesystem.
    final Intent galleryIntent = new Intent();
    galleryIntent.setType("video/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    // Chooser of filesystem options.
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");

    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));

    return chooserIntent;
}
 
源代码11 项目: XposedWechatHelper   文件: MainActivity.java
private void sendURLIntent(String url) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    Uri contentUrl = Uri.parse(url);
    intent.setData(contentUrl);
    startActivity(intent);
}
 
源代码12 项目: Simpler   文件: ActivityInvokeAPI.java
/**
 * 打开某条微博正文。
 * 
 * @param activity
 * @param blogId 某条微博id
 */
public static void openDetail(Activity activity,String blogId){
    if(activity==null){
        return;
    }
    Intent intent=new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setData(Uri.parse("sinaweibo://detail?mblogid="+blogId));
    activity.startActivity(intent);
}
 
源代码13 项目: container   文件: VAccountManagerService.java
void bind() {
	Log.v(TAG, "initiating bind to authenticator type " + mAuthenticatorInfo.desc.type);
	Intent intent = new Intent();
	intent.setAction(AccountManager.ACTION_AUTHENTICATOR_INTENT);
	intent.setClassName(mAuthenticatorInfo.serviceInfo.packageName, mAuthenticatorInfo.serviceInfo.name);
	intent.putExtra("_VA_|_user_id_", mUserId);

	if (!mContext.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
		Log.d(TAG, "bind attempt failed for " + toDebugString());
		onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "bind failure");
	}
}
 
源代码14 项目: product-emm   文件: AppListActivity.java
/**
 * Load device home screen.
 */
private void loadHomeScreen() {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    this.startActivity(i);
    super.onBackPressed();
}
 
源代码15 项目: ClassSchedule   文件: HomeFragment.java
/**
 * QQ反馈
 */
public void qqFeedback() {
    if (!QQIsAvailable()) {
        showMassage(getString(R.string.qq_not_installed));
        return;
    }
    String url1 = "mqqwpa://im/chat?chat_type=wpa&uin=" + getString(R.string.qq_number);
    Intent i1 = new Intent(Intent.ACTION_VIEW, Uri.parse(url1));
    i1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i1.setAction(Intent.ACTION_VIEW);
    if (getContext() != null && getContext().getApplicationContext() != null) {
        getContext().getApplicationContext().startActivity(i1);
    }
}
 
源代码16 项目: Nimingban   文件: FeedActivity.java
@Override
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
    Intent intent = new Intent(this, PostActivity.class);
    intent.setAction(PostActivity.ACTION_POST);
    intent.putExtra(PostActivity.KEY_POST, mFeedHelper.getDataAt(position));
    startActivity(intent);
    return true;
}
 
源代码17 项目: OmniList   文件: WidgetProvider.java
private PendingIntent pendingIntentLaunchApp(Context context, int widgetId) {
    Intent intentLaunchApp = new Intent(context, MainActivity.class);
    intentLaunchApp.setAction(Constants.ACTION_WIDGET_LAUNCH_APP);
    intentLaunchApp.putExtra(Constants.INTENT_WIDGET, widgetId);
    return PendingIntent.getActivity(context, widgetId, intentLaunchApp, PendingIntent.FLAG_CANCEL_CURRENT);
}
 
源代码18 项目: Muzesto   文件: MusicService.java
@Override
public void onCreate() {
    if (D) Log.d(TAG, "Creating service");
    super.onCreate();

    mNotificationManager = NotificationManagerCompat.from(this);

    // gets a pointer to the playback state store
    mPlaybackStateStore = MusicPlaybackState.getInstance(this);
    mSongPlayCount = SongPlayCount.getInstance(this);
    mRecentStore = RecentStore.getInstance(this);


    mHandlerThread = new HandlerThread("MusicPlayerHandler",
            android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();


    mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());


    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mMediaButtonReceiverComponent = new ComponentName(getPackageName(),
            MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        setUpMediaSession();

    mPreferences = getSharedPreferences("Service", 0);
    mCardId = getCardId();

    registerExternalStorageListener();

    mPlayer = new MultiPlayer(this);
    mPlayer.setHandler(mPlayerHandler);

    // Initialize the intent filter and each action
    final IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICECMD);
    filter.addAction(TOGGLEPAUSE_ACTION);
    filter.addAction(PAUSE_ACTION);
    filter.addAction(STOP_ACTION);
    filter.addAction(NEXT_ACTION);
    filter.addAction(PREVIOUS_ACTION);
    filter.addAction(PREVIOUS_FORCE_ACTION);
    filter.addAction(REPEAT_ACTION);
    filter.addAction(SHUFFLE_ACTION);
    // Attach the broadcast listener
    registerReceiver(mIntentReceiver, filter);

    mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
    getContentResolver().registerContentObserver(
            MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver);
    getContentResolver().registerContentObserver(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver);

    // Initialize the wake lock
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.setReferenceCounted(false);


    final Intent shutdownIntent = new Intent(this, MusicService.class);
    shutdownIntent.setAction(SHUTDOWN);

    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);

    scheduleDelayedShutdown();

    reloadQueueAfterPermissionCheck();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);
}
 
源代码19 项目: Hentoid   文件: UnlockActivity.java
/**
 * Creates an intent that launches this activity before launching the given wrapped intent
 *
 * @param context           used for creating the return intent
 * @param destinationIntent intent that refers to the next activity
 * @return intent that launches this activity which leads to another activity referred to by
 * {@code destinationIntent}
 */
public static Intent wrapIntent(Context context, Intent destinationIntent) {
    Intent intent = new Intent(context, UnlockActivity.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.putExtra(EXTRA_INTENT, destinationIntent);
    return intent;
}
 
源代码20 项目: CrimeTalk-Reader   文件: ArticleContentActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    final ArticleListItem articleListItem = getIntent().getExtras().getParcelable(ArticleContentActivity.ARG_LIST_ITEM);

    switch (item.getItemId()) {

        case android.R.id.home:

            this.finish();

            return true;

        case R.id.action_share:

            final Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.check_out_article));
            shareIntent.putExtra(Intent.EXTRA_TEXT, articleListItem.getLink());
            shareIntent.setType("text/plain");
            startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_via)));

            return true;

        case R.id.action_browser:

            final Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(articleListItem.getLink()));
            startActivity(intent);

            return true;

        case R.id.action_clipboard:

            final ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            final ClipData clipData = ClipData.newPlainText("article", String.format(getResources()
                    .getString(R.string.clipboard_article), articleListItem.getTitle(), articleListItem.getAuthor(), articleListItem.getLink()));
            clipboard.setPrimaryClip(clipData);

            SuperActivityToast.create(this, getResources().getString(R.string.clipboard_toast),
                    SuperToast.Duration.SHORT, Style.getStyle(Style.RED)).show();

            return true;

    }

    return false;

}
 
 方法所在类
 同类方法