Java Code Examples for android.content.Intent.setAction()

The following are Jave code examples for showing how to use setAction() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GxIconDIY   File: ExtraUtil.java   View Source Code Vote up 8 votes
public static boolean sendIcon2HomeScreen(Context context, int iconId, String appName,
                                          String pkgName, String launcherName) {
    if (context == null || iconId == 0 || TextUtils.isEmpty(appName)
            || TextUtils.isEmpty(pkgName) || TextUtils.isEmpty(launcherName)) {
        return false;
    }

    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
    shortcutIntent.setClassName(pkgName, launcherName);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    final String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";

    Intent addIntent = new Intent();
    addIntent.setAction(ACTION_ADD_SHORTCUT);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, iconId));
    addIntent.putExtra("duplicate", false);
    context.sendBroadcast(addIntent);

    return true;
}
 
Example 2
Project: mobile-store   File: IntentIntegrator.java   View Source Code Vote up 7 votes
/**
 * Shares the given text by encoding it as a barcode, such that another user can
 * scan the text off the screen of the device.
 *
 * @param text the text string to encode as a barcode
 * @param type type of data to encode. See {@code com.google.zxing.client.android.Contents.Type} constants.
 * @return the {@link AlertDialog} that was shown to the user prompting them to download the app
 *   if a prompt was needed, or null otherwise
 */
public final AlertDialog shareText(CharSequence text, CharSequence type) {
    Intent intent = new Intent();
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setAction(BS_PACKAGE + ".ENCODE");
    intent.putExtra("ENCODE_TYPE", type);
    intent.putExtra("ENCODE_DATA", text);
    String targetAppPackage = findTargetAppPackage(intent);
    if (targetAppPackage == null) {
        return showDownloadDialog();
    }
    intent.setPackage(targetAppPackage);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    attachMoreExtras(intent);
    if (fragment == null) {
        activity.startActivity(intent);
    } else {
        fragment.startActivity(intent);
    }
    return null;
}
 
Example 3
Project: Snach-Android   File: OnQueryAppsReceiver.java   View Source Code Vote up 7 votes
private void sendAppsQueryReply(Context context) {
    Intent mReply = new Intent();
    mReply.setAction(SnachExtras.INTENT_ACTION_SUPPORTED_APPS_REPLY);
    mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_NAME, context.getResources().getString(R.string.stnd_stopwatch_apptitle));
    mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_PACKAGE, context.getPackageName());
    mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_DESCRIPTION, context.getResources().getString(R.string.stnd_stopwatch_description));
    /*
        DEPRECATED, used when the app is selected:
        Usually the app itself should be started and show the user which features will be added to his Snach.
        This is useful to let the user select functions he needs and even to let him customize the layout,
        but its a safety lack.
        This feature can be easily implemented later, so for now if an app has two Snach Apps it has to send
        two of these BroadcastIntents back as a reply.
     */
    mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_INTENT_EXTRA, "myCustomIntentExtra");
    // Intents used on screen reauests and interactions:
    mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_BC_ACTION, "com.assembtec.snach.STND_STOPWATCH");
    mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_BC_EXTRA, "mCustomBroadcastExtra");
    context.sendBroadcast(mReply);
}
 
Example 4
Project: Neuronizer   File: ShareIntent.java   View Source Code Vote up 6 votes
public void send(Context context) {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, content.toString());
    sendIntent.setType("text/plain");
    context.startActivity(Intent.createChooser(sendIntent, context.getResources().getText(R.string.share)));
}
 
Example 5
Project: orgzly-android   File: Shelf.java   View Source Code Vote up 6 votes
private void autoSync() {
    if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG);

    /* Skip sync if there are no repos. */
    if (getAllRepos().size() == 0) {
        return;
    }

    Intent intent = new Intent(mContext, SyncService.class);
    intent.setAction(AppIntent.ACTION_SYNC_START);
    intent.putExtra(AppIntent.EXTRA_IS_AUTOMATIC, true);

    mContext.startService(intent);
}
 
Example 6
Project: treasure   File: PollingUtil.java   View Source Code Vote up 6 votes
/**
 * 开启轮询服务
 */
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void startPollingService(Context context, int mills, Class<?> cls, String action) {
    Intent intent = new Intent(context, cls);
    intent.setAction(action);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    startPolling(context, mills, pendingIntent);
}
 
Example 7
Project: android-project-gallery   File: TDevice.java   View Source Code Vote up 6 votes
public static Intent getInstallApkIntent(File file)
{
	Intent intent = new Intent();
	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	intent.setAction(Intent.ACTION_VIEW);
	intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
	return intent;
}
 
Example 8
Project: Open-Quran-Radio   File: PlayerActivityFragment.java   View Source Code Vote up 6 votes
private void stopPlayback() {
    // reset metadata
    mStationMetadata = null;

    // rotate_infinite playback button
    changeVisualState(mActivity);

    // stop player service using intent
    Intent intent = new Intent(mActivity, PlayerService.class);
    intent.setAction(TransistorKeys.ACTION_STOP);
    mActivity.startService(intent);
    LogHelper.v(LOG_TAG, "Stopping player service.");
}
 
Example 9
Project: q-mail   File: CoreReceiver.java   View Source Code Vote up 6 votes
public static void releaseWakeLock(Context context, int wakeLockId) {
    Timber.v("CoreReceiver Got request to release wakeLock %d", wakeLockId);

    Intent i = new Intent();
    i.setClass(context, CoreReceiver.class);
    i.setAction(WAKE_LOCK_RELEASE);
    i.putExtra(WAKE_LOCK_ID, wakeLockId);
    context.sendBroadcast(i);
}
 
Example 10
Project: eyeRS   File: ShareActivity.java   View Source Code Vote up 6 votes
/**
 * Callback method to be invoked when an item in this AdapterView has
 * been clicked.
 * <p>
 * Implementers can call getItemAtPosition(position) if they need
 * to access the data associated with the selected item.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this
 *                 will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 */
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ItemLabel item = (ItemLabel) listView.getItemAtPosition(position);

    Uri imageUri = getImageUri(item.getImage());
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_TEXT, String.format(
            "Hey, look at my %s", item.getName()));
    shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
    shareIntent.setType("image/jpeg");
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(Intent.createChooser(shareIntent, "Share"));
}
 
Example 11
Project: Phoenix-for-VK   File: NewPostPushMessage.java   View Source Code Vote up 6 votes
private void notifyImpl(Context context, OwnerInfo info){
    String ownerName = fromId > 0 ? (stringEmptyIfNull(firstName) + " " + stringEmptyIfNull(lastName)) : groupName;
    final NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (Utils.hasOreo()){
        nManager.createNotificationChannel(AppNotificationChannels.getNewPostChannel(context));
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, AppNotificationChannels.NEW_POST_CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notify_statusbar)
            .setLargeIcon(info.getAvatar())
            .setContentTitle(context.getString(R.string.new_post_title))
            .setContentText(context.getString(R.string.new_post_was_published_in, ownerName))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
            .setAutoCancel(true);

    builder.setPriority(NotificationCompat.PRIORITY_HIGH);

    Intent intent = new Intent(context, MainActivity.class);
    intent.putExtra(Extra.PLACE, PlaceFactory.getPostPreviewPlace(accountId, postId, fromId));

    intent.setAction(MainActivity.ACTION_OPEN_PLACE);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(context, fromId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(contentIntent);
    Notification notification = builder.build();

    configOtherPushNotification(notification);

    nManager.notify(String.valueOf(fromId), NotificationHelper.NOTIFICATION_NEW_POSTS_ID, notification);
}
 
Example 12
Project: justintrain-client-android   File: FavouriteJourneysActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_join:
            FavouriteJourneysActivity.this.startActivity(new Intent(FavouriteJourneysActivity.this, LicenseUpgradeActivity.class));
            return true;
        case R.id.action_settings:
            FavouriteJourneysActivity.this.startActivity(new Intent(FavouriteJourneysActivity.this, SettingsActivity.class));
            return true;
        case R.id.action_share:
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT,
                    "Dai un'occhiata a quest'app pensata appositamente per i pendolari Trenitalia!\nhttps://play.google.com/store/apps/details?id=com.jaus.albertogiunta.justintrain_oraritreni");
            sendIntent.setType("text/plain");
            startActivity(Intent.createChooser(sendIntent, "Consiglia l'app via..."));
            return true;
        case R.id.action_review:
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())));
            }
            return true;
        case R.id.action_legend:
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(FavouriteJourneysActivity.this);
            View view = LayoutInflater.from(FavouriteJourneysActivity.this).inflate(R.layout.dialog_legend, null);
            alertDialog.setView(view)
                    .setPositiveButton("OK", (dialogInterface, i) -> dialogInterface.dismiss())
                    .create()
                    .show();
            return true;
        case R.id.action_about:
            FavouriteJourneysActivity.this.startActivity(new Intent(FavouriteJourneysActivity.this, AboutActivity.class));
            return true;
        case R.id.label_pro:
            AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(FavouriteJourneysActivity.this);
            View view2 = LayoutInflater.from(FavouriteJourneysActivity.this).inflate(R.layout.dialog_pro_legend, null);
            alertDialog2.setView(view2)
                    .setPositiveButton("OK", (dialogInterface, i) -> dialogInterface.dismiss())
                    .create()
                    .show();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 13
Project: iSPY   File: Dashboard.java   View Source Code Vote up 5 votes
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.db) {
        startActivity(new Intent(getApplicationContext(), Dashboard.class));
        // Handle the camera action
    } else if (id == R.id.ml) {
        startActivity(new Intent(getApplicationContext(), MyLocation.class));

    }
    else if (id == R.id.atk) {
        startActivity(new Intent(getApplicationContext(), TrackerActivity.class));

    }else if (id == R.id.tk) {
        startActivity(new Intent(getApplicationContext(),trackedusers.class));

    } else if (id == R.id.sr) {
        startActivity(new Intent(getApplicationContext(),ShortestDistance.class));

    } else if (id == R.id.nt) {
        startActivity(new Intent(getApplicationContext(), MyNotes1.class));
    } else if (id == R.id.ec) {
        startActivity(new Intent(getApplicationContext(), Navigation.class));
    }
    else if (id == R.id.el) {


    }
    else if (id == R.id.lg) {
        AuthUI.getInstance()
                .signOut(Dashboard.this)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    public void onComplete(@NonNull Task<Void> task) {
                        // user is now signed out
                        startActivity(new Intent(Dashboard.this, Login.class));
                        finish();
                    }
                });        }
    else if (id == R.id.nav_share) {
        Intent sh=new Intent();
        sh.setAction(Intent.ACTION_SEND);
        sh.putExtra(Intent.EXTRA_TEXT,"Download iSPY from here -> www.iSPY.com");
        sh.setType("text/plain");
        startActivity(sh);
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 14
Project: KomaMusic   File: MusicUtils.java   View Source Code Vote up 5 votes
/**
 * Changes to the next track asynchronously
 */
public static void asyncNext(final Context context) {
    final Intent previous = new Intent(context, MusicService.class);
    previous.setAction(MusicServiceConstants.NEXT_ACTION);
    context.startService(previous);
}
 
Example 15
Project: PlusGram   File: CustomTabsHelper.java   View Source Code Vote up 5 votes
/**
 * Goes through all apps that handle VIEW intents and have a warmup service. Picks
 * the one chosen by the user if there is one, otherwise makes a best effort to return a
 * valid package name.
 *
 * This is <strong>not</strong> threadsafe.
 *
 * @param context {@link Context} to use for accessing {@link PackageManager}.
 * @return The package name recommended to use for connecting to custom tabs related components.
 */
public static String getPackageNameToUse(Context context) {
    if (sPackageNameToUse != null) return sPackageNameToUse;

    PackageManager pm = context.getPackageManager();
    // Get default VIEW intent handler.
    Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
    String defaultViewHandlerPackageName = null;
    if (defaultViewHandlerInfo != null) {
        defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
    }

    // Get all apps that can handle VIEW intents.
    List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
    List<String> packagesSupportingCustomTabs = new ArrayList<>();
    for (ResolveInfo info : resolvedActivityList) {
        Intent serviceIntent = new Intent();
        serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
        serviceIntent.setPackage(info.activityInfo.packageName);
        if (pm.resolveService(serviceIntent, 0) != null) {
            packagesSupportingCustomTabs.add(info.activityInfo.packageName);
        }
    }

    // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
    // and service calls.
    if (packagesSupportingCustomTabs.isEmpty()) {
        sPackageNameToUse = null;
    } else if (packagesSupportingCustomTabs.size() == 1) {
        sPackageNameToUse = packagesSupportingCustomTabs.get(0);
    } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
            && !hasSpecializedHandlerIntents(context, activityIntent)
            && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
        sPackageNameToUse = defaultViewHandlerPackageName;
    } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
        sPackageNameToUse = STABLE_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
        sPackageNameToUse = BETA_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
        sPackageNameToUse = DEV_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
        sPackageNameToUse = LOCAL_PACKAGE;
    }
    return sPackageNameToUse;
}
 
Example 16
Project: aos-MediaLib   File: NfoExportService.java   View Source Code Vote up 5 votes
public static void exportAll(Context context) {
    Intent serviceIntent = new Intent(context, NfoExportService.class);
    serviceIntent.setAction(INTENT_EXPORT_ALL);
    context.startService(serviceIntent);
}
 
Example 17
Project: Cable-Android   File: WebRtcCallActivity.java   View Source Code Vote up 5 votes
private void handleEndCall() {
  Log.w(TAG, "Hangup pressed, handling termination now...");
  Intent intent = new Intent(WebRtcCallActivity.this, WebRtcCallService.class);
  intent.setAction(WebRtcCallService.ACTION_LOCAL_HANGUP);
  startService(intent);
}
 
Example 18
Project: techstar-shop   File: ActivityCompanyAdd.java   View Source Code Vote up 5 votes
public void chooseFile() {
    Intent mIntent = new Intent();
    mIntent.setType("image/*");
    mIntent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(mIntent, "Choose an image..."), 2123);
}
 
Example 19
Project: letv   File: ServiceInterface.java   View Source Code Vote up 5 votes
public static void a(Context context, String str, String str2, b bVar) {
    if (!e(context)) {
        if (!(context instanceof Application)) {
            context = context.getApplicationContext();
        }
        if (e.a(context)) {
            boolean z;
            String B = a.B();
            String C = a.C();
            if (str2 == null && str == null) {
                z.e(z[7], z[21]);
                z = false;
            } else {
                int i;
                boolean z2;
                if (str2 != null && str != null) {
                    i = 1;
                    z2 = ((B == null || str.equals(B)) && (C == null || str2.equals(C))) ? false : true;
                } else if (str == null) {
                    i = 2;
                    z2 = (C == null || str2.equals(C)) ? false : true;
                } else {
                    i = 3;
                    z2 = (B == null || str.equals(B)) ? false : true;
                }
                long D = a.D();
                long E = a.E();
                long currentTimeMillis = System.currentTimeMillis();
                z = (z2 || ((i != 3 || currentTimeMillis - D < com.umeng.analytics.a.h) && ((i != 2 || currentTimeMillis - E < com.umeng.analytics.a.h) && (i != 1 || (currentTimeMillis - D < com.umeng.analytics.a.h && currentTimeMillis - E < com.umeng.analytics.a.h))))) ? z2 : true;
                if (!z) {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(z[17]);
                    z.d(z[7], new StringBuilder(z[18]).append(B).append(z[16]).append(str).append(z[23]).append(C).append(z[27]).append(str2).append(z[19]).append(simpleDateFormat.format(new Date(D))).append(z[15]).append(simpleDateFormat.format(new Date(E))).append(z[28]).append(simpleDateFormat.format(new Date(currentTimeMillis))).append(z[26]).append(z).toString());
                }
            }
            if (z) {
                long k = a.k();
                if (!(bVar == null || bVar.c == null)) {
                    TagAliasOperator.a().a(Long.valueOf(k), bVar);
                }
                new StringBuilder(z[25]).append(k);
                z.c();
                TagAliasOperator.a().a(context);
                Intent intent = new Intent(context, PushService.class);
                intent.setAction(z[29]);
                intent.putExtra(z[20], str);
                intent.putExtra(z[24], str2);
                intent.putExtra(z[14], k);
                context.startService(intent);
                return;
            }
            z.e(z[7], z[22]);
            if (bVar.c != null) {
                bVar.c.gotResult(0, bVar.a, bVar.b);
            }
        }
    }
}
 
Example 20
Project: letv   File: PageJumpUtil.java   View Source Code Vote up 5 votes
public static void jumpLeboxDownloadPage(Activity activity) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.letv.LeboxDownLoadPage");
    activity.startActivity(intent);
}