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

The following are Jave code examples for showing how to use addFlags() 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: Android-Wear-Projects   File: WaterReminderReceiver.java   View Source Code Vote up 8 votes
@Override
public void onReceive(Context context, Intent intent) {
    Intent intent2 = new Intent(context, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

    NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
            .setAutoCancel(true)   //Automatically delete the notification
            .setSmallIcon(R.drawable.water_bottle_flat) //Notification icon
            .setContentIntent(pendingIntent)
            .setContentTitle("Time to hydrate")
            .setContentText("Drink a glass of water now")
            .setCategory(Notification.CATEGORY_REMINDER)
            .setPriority(Notification.PRIORITY_HIGH)
            .setSound(defaultSoundUri);


    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(0, notificationBuilder.build());

    Toast.makeText(context, "Repeating Alarm Received", Toast.LENGTH_SHORT).show();
}
 
Example 2
Project: NoticeDog   File: AppManager.java   View Source Code Vote up 7 votes
public void launchAppForMessage(Message message, AppLaunchMethod launchedFrom) {
    App app = getAppById(message.getAppId());

    PendingIntent pendingIntent = message.getPendingIntent();
    if (pendingIntent != null) {
        try {
            pendingIntent.send();
            return;
        } catch (CanceledException e) {
            Log.d(TAG, "Failed to launch pending intent because it was cancelled");
        }
    }
    Intent launchIntent = app.getLaunchIntentForMessage(message);
    if (launchIntent != null) {
        launchIntent.addFlags(268435456);
        safeStartActivity(launchIntent);
    }
}
 
Example 3
Project: text_converter   File: CodecFileFragment.java   View Source Code Vote up 7 votes
private void openResult() {
    String path = mEditOutPath.getText().toString();
    if (!path.isEmpty()) {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            File file = new File(path);
            Uri url = FileProvider.getUriForFile(getContext(),
                    getContext().getPackageName() + ".fileprovider", file);

            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setDataAndType(url, "text/plain");
            Intent chooser = Intent.createChooser(intent, "Choose an application to open with:");
            startActivity(chooser);
        } catch (Exception e) {
            Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
}
 
Example 4
Project: Nimbus   File: MainActivity.java   View Source Code Vote up 7 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_logout) {
        sharedPref.setUserId("");
        sharedPref.setLoginStatus(false);
        sharedPref.setUserRollno("");
        sharedPref.setUserEmail("");
        sharedPref.setUserPicUrl("");
        sharedPref.setUserName("");
        LoginManager.getInstance().logOut();
        Intent intent = new Intent(MainActivity.this,LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
        finish();
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 5
Project: EasyTodo   File: EventContentActivity.java   View Source Code Vote up 7 votes
private void startTake() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //判断是否有相机应用
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        //创建临时图片文件
        File photoFile = null;
        try {
            photoFile = PictureUtils.createPublicImageFile();
            mPublicPhotoPath = photoFile.getAbsolutePath();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //设置Action为拍照
        if (photoFile != null) {
            takePictureIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
            //这里加入flag
            takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri photoURI = FileProvider.getUriForFile(this, "applicationId.fileprovider", photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQ_GALLERY);
        }
    }
}
 
Example 6
Project: ConnectU   File: AppManager.java   View Source Code Vote up 7 votes
public static void addShortcutToWebmail(Context context) {
    //Adding shortcut for MainActivity
    //on Home screen
    Intent shortcutIntent = new Intent(context, WebmailActivity.class);
    shortcutIntent.putExtra(Common.WEBVIEW_EXTRA_COLOR, Color.parseColor("#607d8b"));
    shortcutIntent.putExtra(Common.WEBVIEW_EXTRA_NAME, context.getString(R.string.title_webapp_email));
    shortcutIntent.putExtra(Common.WEBVIEW_EXTRA_URL, WebApps.Webmail);
    shortcutIntent.putExtra(Common.WEBVIEW_EXTRA_NLOGIN, true);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent addIntent = new Intent();
    addIntent
            .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "eMailUA");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context,
                    R.drawable.ic_webmail));

    addIntent
            .setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    addIntent.putExtra("duplicate", false);  //may be already there so don't duplicate
    context.sendBroadcast(addIntent);
}
 
Example 7
Project: OpenCV_Android_Plus   File: AsyncServiceHelper.java   View Source Code Vote up 7 votes
protected static boolean InstallServiceQuiet(Context context)
{
    boolean result = true;
    try
    {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(OPEN_CV_SERVICE_URL));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
    catch(Exception e)
    {
        result = false;
    }

    return result;
}
 
Example 8
Project: AndroidOpen   File: FirUpdater.java   View Source Code Vote up 6 votes
@Override
public void onReceive(Context context, Intent intent) {
    long completeDownloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
    if (completeDownloadId == downloadId) {
        if (getStatusById(downloadManager, downloadId, DownloadManager.COLUMN_STATUS)
                == DownloadManager.STATUS_SUCCESSFUL) {
            Toast.makeText(context, "新版本已下载成功", Toast.LENGTH_SHORT).show();
            Uri downloadUri = downloadManager.getUriForDownloadedFile(downloadId);
            if (downloadUri != null) {
                Intent install = new Intent(Intent.ACTION_VIEW);
                install.setDataAndType(downloadUri, "application/vnd.android.package-archive");
                install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(install);
            } else {
                Toast.makeText(context, "下载失败", Toast.LENGTH_SHORT).show();
            }
        }
    }
}
 
Example 9
Project: UpdogFarmer   File: MainActivity.java   View Source Code Vote up 6 votes
/**
 * Send Logcat output via email
 */
private void sendLogcat() {
    final File cacheDir = getExternalCacheDir();
    if (cacheDir == null) {
        Log.i(TAG, "Unable to save Logcat. Shared storage is unavailable!");
        return;
    }
    final File file = new File(cacheDir, "idledaddy-logcat.txt");
    try {
        Utils.saveLogcat(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
    intent.putExtra(Intent.EXTRA_SUBJECT, "Idle Daddy Logcat");
    intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this,
            getApplicationContext().getPackageName() + ".provider", file));
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(intent);
}
 
Example 10
Project: Hitalk   File: BaseActivity.java   View Source Code Vote up 6 votes
public static <T extends BaseActivity> void start(Context ctx,Class<T> c){
    if (ctx == null) {
        return;
    }
    Intent intent = new Intent(ctx,c);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ctx.startActivity(intent);
}
 
Example 11
Project: lockit   File: LockService.java   View Source Code Vote up 6 votes
private void exit() {
    final Intent i = new Intent(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(i);

    hideLock();
}
 
Example 12
Project: MyBlogPost   File: BaseActivity.java   View Source Code Vote up 6 votes
public void goToActivityClearAllStack(Class c, Bundle bundle){
    Intent i = new Intent(this, c);
    if (bundle != null) {
        i.putExtras(bundle);
    }
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(i);
    finish();
}
 
Example 13
Project: BaseCore   File: ShareUtils.java   View Source Code Vote up 6 votes
/**
     * 分享9图到朋友圈
     *
     * @param context
     * @param Kdescription 9图上边输入框中的文案
     * @param paths        本地图片的路径
     */
    public static boolean share9PicsToWXCircle(Context context, String Kdescription, List<String> paths) {
        if (!isInstallWeChart(context)) {
            ToastUtils.showShortToast("您没有安装微信");
            return false;
        }
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(tencentPk, "com.tencent.mm.ui.tools.ShareToTimeLineUI"));
        intent.setAction(tencentAction);

        ArrayList<Uri> imageList = new ArrayList<>();
        for (String picPath : paths) {
            File f = new File(picPath);
            if (f.exists()) {

//                url = MediaStore.Images.Media.insertImage(context.getContentResolver(), picPath, "12312", "你对图片的描述");
                Uri imageUri;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

                    imageUri = Uri.parse(insertImageToSystem(context, picPath));
                } else {
                    imageUri = Uri.fromFile(f);
                }
                imageList.add(imageUri);
            }
        }
        if (imageList.size() == 0) {
            ToastUtils.showShortToast("文件不存在");
            return false;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //添加这一句表示对目标应用临时授权该Uri所代表的文件
        }
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_STREAM, imageList); //图片数据(支持本地图片的Uri形式)
        intent.putExtra("Kdescription", Kdescription); //微信分享页面,图片上边的描述、
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        context.startActivity(intent);
        return true;
    }
 
Example 14
Project: AndroidKeepLivePractice   File: CheckTopTask.java   View Source Code Vote up 6 votes
static void startForeground(Context context) {
    try {
        Intent intent = new Intent(context, OnePxActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    } catch (Exception e) {
        Log.e(TAG, "e:", e);
    }
}
 
Example 15
Project: MBEStyle   File: ApplyFragment.java   View Source Code Vote up 6 votes
private void NovaLauncher() {
    Intent intent = new Intent("com.teslacoilsw.launcher.APPLY_ICON_THEME");
    intent.setPackage("com.teslacoilsw.launcher");
    intent.putExtra("com.teslacoilsw.launcher.extra.ICON_THEME_TYPE", "GO");
    intent.putExtra("com.teslacoilsw.launcher.extra.ICON_THEME_PACKAGE", BuildConfig.APPLICATION_ID);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    openActivity(intent);
}
 
Example 16
Project: mobile-store   File: IntentIntegrator.java   View Source Code Vote up 6 votes
/**
 * Initiates a scan, using the specified camera, only for a certain set of barcode types, given as strings corresponding
 * to their names in ZXing's {@code BarcodeFormat} class like "UPC_A". You can supply constants
 * like {@link #PRODUCT_CODE_TYPES} for example.
 *
 * @param desiredBarcodeFormats names of {@code BarcodeFormat}s to scan for
 * @param cameraId camera ID of the camera to use. A negative value means "no preference".
 * @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 initiateScan(Collection<String> desiredBarcodeFormats, int cameraId) {
    Intent intentScan = new Intent(BS_PACKAGE + ".SCAN");
    intentScan.addCategory(Intent.CATEGORY_DEFAULT);

    // check which types of codes to scan for
    if (desiredBarcodeFormats != null) {
        // set the desired barcode types
        StringBuilder joinedByComma = new StringBuilder();
        for (String format : desiredBarcodeFormats) {
            if (joinedByComma.length() > 0) {
                joinedByComma.append(',');
            }
            joinedByComma.append(format);
        }
        intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
    }

    // check requested camera ID
    if (cameraId >= 0) {
        intentScan.putExtra("SCAN_CAMERA_ID", cameraId);
    }

    String targetAppPackage = findTargetAppPackage(intentScan);
    if (targetAppPackage == null) {
        return showDownloadDialog();
    }
    intentScan.setPackage(targetAppPackage);
    intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    attachMoreExtras(intentScan);
    startActivityForResult(intentScan, REQUEST_CODE);
    return null;
}
 
Example 17
Project: bigjpg-app   File: MainActivity.java   View Source Code Vote up 6 votes
public void onChooseImg(View view) {
    if (collapsePanel()) {
        return;
    }
    if (!checkPermissions()) {
        return;
    }
    if ("processing".equals(tvAction.getTag())) {
        return;
    }
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivityForResult(intent, 0);
}
 
Example 18
Project: RetroMusicPlayer   File: AbsTagEditorActivity.java   View Source Code Vote up 6 votes
protected void searchWebFor(String... keys) {
    StringBuilder stringBuilder = new StringBuilder();
    for (String key : keys) {
        stringBuilder.append(key);
        stringBuilder.append(" ");
    }
    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
    intent.putExtra(SearchManager.QUERY, stringBuilder.toString());
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    startActivity(intent);
}
 
Example 19
Project: AppFirCloud   File: ScanResultActivity.java   View Source Code Vote up 5 votes
public static void luncher(Context context, String content) {
    Intent intent = new Intent(context, ScanResultActivity.class);
    intent.putExtra(KEY_CONTENT, content);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
Example 20
Project: QQQAndroid   File: QQQApplication.java   View Source Code Vote up 5 votes
public void restartApp() {
    Intent intent = new Intent(instance,MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    instance.startActivity(intent);
    android.os.Process.killProcess(android.os.Process.myPid());
}