Java Code Examples for android.content.Intent.addCategory()
The following are Jave code examples for showing how to use
addCategory() 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: MyRepository File: DownloadService.java View Source Code | 9 votes |
private void installAPK(Uri apk, Context context) { if (Build.VERSION.SDK_INT < 23) { Intent intents = new Intent(); intents.setAction("android.intent.action.VIEW"); intents.addCategory("android.intent.category.DEFAULT"); intents.setType("application/vnd.android.package-archive"); intents.setData(apk); intents.setDataAndType(apk, "application/vnd.android.package-archive"); intents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intents); } else { Log.e("6.0系统apk路径",apk.getPath()); if (destinationFile.exists()) { openFile(destinationFile, context); } } }
Example 2
Project: q-mail File: Accounts.java View Source Code | 8 votes |
private void performExport(final boolean includeGlobals, final Account account) { // TODO, prompt to allow a user to choose which accounts to export ArrayList<String> accountUuids = null; if (account != null) { accountUuids = new ArrayList<>(); accountUuids.add(account.getUuid()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { exportGlobalSettings = includeGlobals; exportAccountUuids = accountUuids; Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.setType("application/octet-stream"); intent.putExtra(Intent.EXTRA_TITLE, SettingsExporter.generateDatedExportFileName()); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent, ACTIVITY_REQUEST_SAVE_SETTINGS_FILE); } else { startExport(includeGlobals, accountUuids, null); } }
Example 3
Project: RNLearn_Project1 File: ShareModule.java View Source Code | 7 votes |
/** * Open a chooser dialog to send text content to other apps. * * Refer http://developer.android.com/intl/ko/training/sharing/send.html * * @param content the data to send * @param dialogTitle the title of the chooser dialog */ @ReactMethod public void share(ReadableMap content, String dialogTitle, Promise promise) { if (content == null) { promise.reject(ERROR_INVALID_CONTENT, "Content cannot be null"); return; } try { Intent intent = new Intent(Intent.ACTION_SEND); intent.setTypeAndNormalize("text/plain"); if (content.hasKey("title")) { intent.putExtra(Intent.EXTRA_SUBJECT, content.getString("title")); } if (content.hasKey("message")) { intent.putExtra(Intent.EXTRA_TEXT, content.getString("message")); } Intent chooser = Intent.createChooser(intent, dialogTitle); chooser.addCategory(Intent.CATEGORY_DEFAULT); Activity currentActivity = getCurrentActivity(); if (currentActivity != null) { currentActivity.startActivity(chooser); } else { getReactApplicationContext().startActivity(chooser); } WritableMap result = Arguments.createMap(); result.putString("action", ACTION_SHARED); promise.resolve(result); } catch (Exception e) { promise.reject(ERROR_UNABLE_TO_OPEN_DIALOG, "Failed to open share dialog"); } }
Example 4
Project: fitnotifications File: Func.java View Source Code | 7 votes |
public static List<ResolveInfo> getInstalledPackages(PackageManager pm, Context context) { DebugLog log = DebugLog.get(context); if (log.isEnabled()) { log.writeLog("Getting installed packages. Will try a few different methods to see if I receive a suitable app list."); } Intent startupIntent = new Intent(Intent.ACTION_MAIN); startupIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> resolveInfos = pm.queryIntentActivities(startupIntent, 0); if (log.isEnabled()) { log.writeLog("Got " + resolveInfos.size() + " apps via queryIntentActivities."); } List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_META_DATA); if (log.isEnabled()) { log.writeLog("Got " + appInfos.size() + " apps via getInstalledApplications with GET_META_DATA."); } appInfos = pm.getInstalledApplications(0); if (log.isEnabled()) { log.writeLog("Got " + appInfos.size() + " apps via getInstalledApplications with no flags"); } return resolveInfos; }
Example 5
Project: LauncherTV File: Utils.java View Source Code | 7 votes |
public static List<AppInfo> loadApplications(Context context) { PackageManager packageManager = context.getPackageManager(); Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> intentActivities = packageManager.queryIntentActivities(mainIntent, 0); List<AppInfo> entries = new ArrayList<>(); if (intentActivities != null) { for (ResolveInfo resolveInfo : intentActivities) { if (!context.getPackageName().equals(resolveInfo.activityInfo.packageName)) entries.add(new AppInfo(packageManager, resolveInfo)); } } Collections.sort(entries, new Comparator<AppInfo>() { @Override public int compare(AppInfo lhs, AppInfo rhs) { return lhs.getName().compareToIgnoreCase(rhs.getName()); } }); return entries; }
Example 6
Project: ucar-weex-core File: UWXEventModule.java View Source Code | 6 votes |
@JSMethod public void openURL(String url) { if (TextUtils.isEmpty(url)) { return; } Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse(url); String scheme = uri.getScheme(); if (TextUtils.equals("tel", scheme)) { } else if (TextUtils.equals("sms", scheme)) { } else if (TextUtils.equals("mailto", scheme)) { } else if (TextUtils.equals("http", scheme) || TextUtils.equals("https", scheme)) { intent.putExtra("isLocal", false); intent.addCategory(WEEX_CATEGORY); } else if (TextUtils.equals("file", scheme)) { intent.putExtra("isLocal", true); intent.addCategory(WEEX_CATEGORY); } else { intent.addCategory(WEEX_CATEGORY); uri = Uri.parse(new StringBuilder("http:").append(url).toString()); } intent.setData(uri); mWXSDKInstance.getContext().startActivity(intent); }
Example 7
Project: AndroidUiKit File: HomeActivity.java View Source Code | 6 votes |
@Override @SuppressWarnings("unchecked") protected void onListItemClick(ListView l, View v, int position, long id) { Map<String, Object> map = (Map<String, Object>)l.getItemAtPosition(position); Intent intent = new Intent((Intent) map.get("intent")); intent.addCategory(APP_CAGEGORY); startActivity(intent); }
Example 8
Project: AndroidBackendlessChat File: ExitHelper.java View Source Code | 6 votes |
@Override public Object call() throws Exception { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activity.startActivity(intent); return null; }
Example 9
Project: NoticeDog File: AppIds.java View Source Code | 6 votes |
@TargetApi(19) public static String getSMSAppPackageName(Context context) { if (VERSION.SDK_INT >= 19) { return Sms.getDefaultSmsPackage(context); } Intent intent = new Intent("android.intent.action.MAIN"); intent.addCategory("android.intent.category.DEFAULT"); intent.setType("vnd.android-dir/mms-sms"); ComponentName componentName = intent.resolveActivity(context.getPackageManager()); if (componentName != null) { return componentName.getPackageName(); } return null; }
Example 10
Project: MVPArmsTest1 File: DeviceUtils.java View Source Code | 6 votes |
public static boolean openAppActivity(Context context, String packageName, String activityName) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName(packageName, activityName); intent.setComponent(cn); try { context.startActivity(intent); return true; } catch (Exception e) { return false; } }
Example 11
Project: Tusky File: ComposeActivity.java View Source Code | 6 votes |
private void initiateMediaPicking() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { intent.setType("image/* video/*"); } else { String[] mimeTypes = new String[]{"image/*", "video/*"}; intent.setType("*/*"); intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes); } startActivityForResult(intent, MEDIA_PICK_RESULT); }
Example 12
Project: FastEc File: CameraHandler.java View Source Code | 6 votes |
private void pickPhoto() { final Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); DELEGATE.startActivityForResult (Intent.createChooser(intent, "选择获取图片的方式"), RequestCodes.PICK_PHOTO); }
Example 13
Project: RantApp File: LauncherActivity.java View Source Code | 6 votes |
@Override public void onBackPressed() { // super.onBackPressed(); Intent i = new Intent(Intent.ACTION_MAIN); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.addCategory(Intent.CATEGORY_HOME); startActivity(i); }
Example 14
Project: Simpler File: ActivityInvokeAPI.java View Source Code | 6 votes |
/** * 打开私信对话界面。 * * @param activity * @param uid 用户uid */ public static void openMessageListByUid(Activity activity,String uid){ if(activity==null){ return; } Intent intent=new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory("android.intent.category.DEFAULT"); intent.setData(Uri.parse("sinaweibo://messagelist?uid="+uid)); activity.startActivity(intent); }
Example 15
Project: Treebolic File: MainActivity.java View Source Code | 6 votes |
/** * Request Treebolic source */ private void requestTreebolicSource() { final String extensions = (String) this.pluginProvider.get(Providers.EXTENSIONS); final Intent intent = new Intent(this, org.treebolic.filechooser.FileChooserActivity.class); intent.setType((String) this.pluginProvider.get(Providers.MIMETYPE)); intent.putExtra(FileChooserActivity.ARG_FILECHOOSER_INITIAL_DIR, (String) this.pluginProvider.get(Providers.BASE)); intent.putExtra(FileChooserActivity.ARG_FILECHOOSER_EXTENSION_FILTER, extensions == null ? null : extensions.split(",")); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent, MainActivity.REQUEST_FILE_CODE); }
Example 16
Project: FlickLauncher File: LauncherAppsCompatV16.java View Source Code | 6 votes |
public void startActivityForProfile(ComponentName component, UserHandleCompat user, Rect sourceBounds, Bundle opts) { Intent launchIntent = new Intent(Intent.ACTION_MAIN); launchIntent.addCategory(Intent.CATEGORY_LAUNCHER); launchIntent.setComponent(component); launchIntent.setSourceBounds(sourceBounds); launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(launchIntent, opts); }
Example 17
Project: GxIconAndroid File: InstalledAppReader.java View Source Code | 6 votes |
private void init(@NonNull PackageManager packageManager) { try { Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> list = packageManager.queryIntentActivities(mainIntent, 0); for (ResolveInfo resolveInfo : list) { dataList.add(new Bean(resolveInfo.loadLabel(packageManager).toString(), resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name)); } } catch (Exception e) { e.printStackTrace(); } }
Example 18
Project: calendarview2 File: MainActivity.java View Source Code | 5 votes |
private List<ResolveInfo> getAllSampleActivities() { Intent filter = new Intent(); filter.setAction(Intent.ACTION_RUN); filter.addCategory(CATEGORY_SAMPLE); return getPackageManager().queryIntentActivities(filter, 0); }
Example 19
Project: sctalk File: PhotoHelper.java View Source Code | 5 votes |
public Intent getPhotoPickIntent() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); return intent; }
Example 20
Project: Simpler File: ActivityInvokeAPI.java View Source Code | 4 votes |
/** * 调起新浪微博客户端的发送微博界面,完成发送微博工作。 * * @param activity * @param content 微博内容 * @param xid 签到时 的地点id * @param poiId POI点ID * @param poiName POI点名称 * @param longitude 经度 * @param latitude 纬度 */ public static void openSendWeibo(Activity activity,String content,String xid,String poiId,String poiName,String longitude,String latitude){ if(activity==null){ return; } Intent intent=new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory("android.intent.category.DEFAULT"); intent.setData(Uri.parse("sinaweibo://sendweibo?content="+content+"&xid="+xid+"&poiid="+poiId+"&poiname="+poiName+"&longitude="+longitude+"&latitude="+latitude)); activity.startActivity(intent); }