Java Code Examples for android.support.v7.app.AppCompatActivity#startActivity()
The following examples show how to use
android.support.v7.app.AppCompatActivity#startActivity() .
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: IntentShareHelper.java From Learning-Resources with MIT License | 6 votes |
public static void shareOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_TEXT, !TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.startActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWarningDialog(appCompatActivity, "activity not found"); } }
Example 2
Source File: IntentShareHelper.java From Learning-Resources with MIT License | 6 votes |
public static void shareOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.whatsapp"); intent.putExtra(Intent.EXTRA_TEXT, !TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.startActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWarningDialog(appCompatActivity, "activity not found"); } }
Example 3
Source File: IntentShareHelper.java From Learning-Resources with MIT License | 6 votes |
public static void shareOnOther(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, !TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.startActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWarningDialog(appCompatActivity, "activity not found"); } }
Example 4
Source File: ShowDeleteListsOnClickListener.java From privacy-friendly-shopping-list with Apache License 2.0 | 6 votes |
@Override public boolean onMenuItemClick(MenuItem item) { AppCompatActivity activity = cache.getActivity(); Intent intent = new Intent(activity, DeleteListsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(intent); return true; }
Example 5
Source File: SqliteManagerUtils.java From SqliteManager with Apache License 2.0 | 5 votes |
private static void createTempFileAndShare(AppCompatActivity context, String fileShareAuthority, String csvString, String csvFileName, String type) { try { File fileDir = new File(context.getFilesDir(), "sqliteManager"); fileDir.mkdir(); File file = new File(fileDir, csvFileName); file.createNewFile(); FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(csvString.getBytes()); fileOutputStream.close(); // generate URI, defined authority as the application ID in the Manifest Uri uriToCSVFIle = FileProvider.getUriForFile(context, fileShareAuthority, file); Intent shareIntent = ShareCompat.IntentBuilder .from(context) .setStream(uriToCSVFIle) .setType(type) .getIntent(); // Provide read access shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // validate that the device can open your File! PackageManager pm = context.getPackageManager(); if (shareIntent.resolveActivity(pm) != null) { context.startActivity(shareIntent); } } catch (Exception e) { // e.printStackTrace(); } }
Example 6
Source File: IntentShareHelper.java From Learning-Resources with MIT License | 5 votes |
public static void shareOnFacebook(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, !TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } boolean facebookAppFound = false; List<ResolveInfo> matches = appCompatActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo info : matches) { if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana") || info.activityInfo.packageName.toLowerCase().startsWith("com.facebook.lite")) { intent.setPackage(info.activityInfo.packageName); facebookAppFound = true; break; } } if (facebookAppFound) { appCompatActivity.startActivity(intent); } else { showWarningDialog(appCompatActivity, "activity not found"); } }
Example 7
Source File: DeleteProductOnClickListener.java From privacy-friendly-shopping-list with Apache License 2.0 | 5 votes |
private Void deleteProductsSync() { // delete products List<ProductItem> productList = cache.getDeleteProductsAdapter().getList(); productService.deleteSelected(productList) .doOnError(Throwable::printStackTrace).subscribe(); // go to products overview AppCompatActivity activity = cache.getActivity(); Intent intent = new Intent(activity, ProductsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(MainActivity.LIST_ID_KEY, cache.getListId()); activity.startActivity(intent); return null; }
Example 8
Source File: CategoryActivity.java From NHentai-android with GNU General Public License v3.0 | 5 votes |
public static void launch(AppCompatActivity activity, String url, String title) { Intent intent = new Intent(activity, CategoryActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(EXTRA_URL, url); intent.putExtra(EXTRA_TITLE, title); activity.startActivity(intent); }
Example 9
Source File: Util.java From RetroMusicPlayer with GNU General Public License v3.0 | 4 votes |
public static void openUrl(AppCompatActivity context, String str) { Intent intent = new Intent("android.intent.action.VIEW"); intent.setData(Uri.parse(str)); intent.setFlags(268435456); context.startActivity(intent); }
Example 10
Source File: IntentShareHelper.java From Learning-Resources with MIT License | 4 votes |
public static void openImage(AppCompatActivity appCompatActivity, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_VIEW, fileUri); intent.setDataAndType(fileUri, "image/*"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); appCompatActivity.startActivity(Intent.createChooser(intent, "Choose your platform")); }
Example 11
Source File: SearchResultActivity.java From NHentai-android with GNU General Public License v3.0 | 4 votes |
public static void launch(AppCompatActivity activity, String keyword) { Intent intent = new Intent(activity, SearchResultActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(EXTRA_KEYWORD, keyword); activity.startActivity(intent); }
Example 12
Source File: PickServerActivity.java From Conversations with GNU General Public License v3.0 | 4 votes |
public static void launch(AppCompatActivity activity) { Intent intent = new Intent(activity, PickServerActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); activity.startActivity(intent); activity.overridePendingTransition(0, 0); }
Example 13
Source File: WelcomeActivity.java From Conversations with GNU General Public License v3.0 | 4 votes |
public static void launch(AppCompatActivity activity) { Intent intent = new Intent(activity, WelcomeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); activity.startActivity(intent); activity.overridePendingTransition(0, 0); }