List of usage examples for android.content Intent addCategory
public @NonNull Intent addCategory(String category)
From source file:net.bytten.comicviewer.ComicViewerActivity.java
public void launchWebsite() { Intent browser = new Intent(); browser.setAction(Intent.ACTION_VIEW); browser.addCategory(Intent.CATEGORY_BROWSABLE); browser.setData(Uri.parse(comicInfo.getUrl())); startActivity(browser);/* w w w . j a v a 2 s.c om*/ }
From source file:net.bytten.comicviewer.ComicViewerActivity.java
public void openComicLink() { Intent browser = new Intent(); browser.setAction(Intent.ACTION_VIEW); browser.addCategory(Intent.CATEGORY_BROWSABLE); browser.setData(comicInfo.getLink()); startActivity(browser);//w w w . j a va 2 s . c om }
From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java
/** * Starts the uploading experience//from ww w .ja v a2s. c om * @param requestCode The request code that will be used to choose simple/chunked uploading */ private void upload(final int requestCode) { final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setType(ACCEPTED_UPLOAD_MIME_TYPES); startActivityForResult(intent, requestCode); }
From source file:com.p2p.misc.DeviceUtility.java
public void toggleGPSOFF(boolean enable, Context mContext) { try {//from w w w . j ava 2 s .co m String provider = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if (provider.contains("gps")) { //if gps is disabled final Intent poke = new Intent(); poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); poke.addCategory(Intent.CATEGORY_ALTERNATIVE); poke.setData(Uri.parse("3")); mContext.sendBroadcast(poke); System.out.println("GPS is turn OFF"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.p2p.misc.DeviceUtility.java
public void toggleGPS(boolean enable, Context mContext) { try {//ww w . ja v a 2s.co m String provider = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); // Intent I = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); // mContext.startActivity(I); if (!provider.contains("gps")) { //if gps is disabled final Intent poke = new Intent(); poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); poke.addCategory(Intent.CATEGORY_ALTERNATIVE); poke.setData(Uri.parse("3")); mContext.sendBroadcast(poke); System.out.println("GPS is turn ON"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.company.millenium.iwannask.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //GPS//from ww w .j a v a2s . co m locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); locationListener = new LocationListener() { public void onLocationChanged(Location location) { if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Check Permissions Now final int REQUEST_LOCATION = 2; if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Display UI and wait for user interaction } else { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } } else { locationManager.removeUpdates(this); } } public void onStatusChanged(String string, int integer, Bundle bundle) { } public void onProviderEnabled(String string) { } public void onProviderDisabled(String string) { } }; if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Check Permissions Now final int REQUEST_LOCATION = 2; if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Display UI and wait for user interaction } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } } else { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1000, locationListener); } int delay = 30000; // delay for 30 sec. int period = 3000000; // repeat every 5.3min. Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Check Permissions Now final int REQUEST_LOCATION = 2; if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)) { // Display UI and wait for user interaction } else { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION); } } else { locationManager.removeUpdates(locationListener); } } }, delay, period); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); Intent mIntent = getIntent(); URL = Constants.SERVER_URL; if (mIntent.hasExtra("url")) { myWebView = null; startActivity(getIntent()); String url = mIntent.getStringExtra("url"); URL = Constants.SERVER_URL + url; } CookieSyncManager.createInstance(this); CookieSyncManager.getInstance().startSync(); myWebView = (WebView) findViewById(R.id.webview); myWebView.getSettings().setGeolocationDatabasePath(this.getFilesDir().getPath()); myWebView.getSettings().setGeolocationEnabled(true); WebSettings webSettings = myWebView.getSettings(); webSettings.setUseWideViewPort(false); if (!DetectConnection.checkInternetConnection(this)) { webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); showNoConnectionDialog(this); } else { webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); } webSettings.setJavaScriptEnabled(true); myWebView.addJavascriptInterface(new webappinterface(this), "android"); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); myWebView.setOverScrollMode(View.OVER_SCROLL_NEVER); //location test webSettings.setAppCacheEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); myWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { CookieSyncManager.getInstance().sync(); } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); // Ignore SSL certificate errors } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (Uri.parse(url).getHost().equals(Constants.HOST) || Uri.parse(url).getHost().equals(Constants.WWWHOST)) { // This is my web site, so do not override; let my WebView load // the page return false; } // Otherwise, the link is not for a page on my site, so launch // another Activity that handles URLs Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } }); myWebView.setWebChromeClient(new WebChromeClient() { public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); } @Override public void onPermissionRequest(final PermissionRequest request) { Log.d(TAG, "onPermissionRequest"); runOnUiThread(new Runnable() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void run() { if (request.getOrigin().toString().equals("https://apprtc-m.appspot.com/")) { request.grant(request.getResources()); } else { request.deny(); } } }); } public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { // Double check that we don't have any existing callbacks if (mFilePathCallback != null) { mFilePathCallback.onReceiveValue(null); } mFilePathCallback = filePathCallback; // Set up the take picture intent Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File Log.e(TAG, "Unable to create Image File", ex); } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } // Set up the intent to get an existing image Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); // Set up the intents for the Intent chooser Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } }); // setContentView(myWebView); // myWebView.loadUrl(URL); myWebView.loadUrl(URL); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); } }; //CookieManager mCookieManager = CookieManager.getInstance(); //Boolean hasCookies = mCookieManager.hasCookies(); //while(!hasCookies); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); //intent.putExtra("session", session); startService(intent); } Boolean isFirstRun = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("isFirstRun", true); if (isFirstRun) { //show start activity startActivity(new Intent(MainActivity.this, MyIntro.class)); } //if (!isOnline()) // showNoConnectionDialog(this); getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit().putBoolean("isFirstRun", false).commit(); //Pull-to-refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.container); mSwipeRefreshLayout.setOnRefreshListener(this); }
From source file:net.bytten.comicviewer.ComicViewerActivity.java
public void explain() { final IComicInfo comic = comicInfo; new AsyncTask<Object, Integer, Integer>() { @Override//ww w. ja va2 s. co m protected Integer doInBackground(Object... params) { try { URL url = new URL(provider.getExplainUrl(comic).toString()); HttpURLConnection http = (HttpURLConnection) url.openConnection(); return http.getResponseCode(); } catch (IOException e) { e.printStackTrace(); return null; } } @Override protected void onPostExecute(Integer result) { super.onPostExecute(result); if (result == null || result != 200) { toast("This comic has no user-supplied explanation."); } } }.execute(new Object[] {}); Intent browser = new Intent(); browser.setAction(Intent.ACTION_VIEW); browser.addCategory(Intent.CATEGORY_BROWSABLE); browser.setData(provider.getExplainUrl(comic)); startActivity(browser); }
From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java
/** * To savge a document by its path.<br/> * * @param path the file path to share// w ww.ja va 2 s. c o m */ private void saveDocument(String path) { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType( MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(path))); startActivityForResult(intent, ACTION_SAVE_DOCUMENT); }
From source file:com.androzic.location.LocationService.java
private Notification getNotification() { int msgId = R.string.notif_loc_started; int ntfId = R.drawable.ic_stat_locating; if (trackingEnabled) { msgId = R.string.notif_trk_started; ntfId = R.drawable.ic_stat_tracking; }//from w w w . j av a 2 s . com if (gpsStatus != LocationService.GPS_OK) { msgId = R.string.notif_loc_waiting; ntfId = R.drawable.ic_stat_waiting; } if (gpsStatus == LocationService.GPS_OFF) { ntfId = R.drawable.ic_stat_off; } if (errorTime > 0) { msgId = R.string.notif_trk_failure; ntfId = R.drawable.ic_stat_failure; } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setWhen(errorTime); builder.setSmallIcon(ntfId); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(new ComponentName(getApplicationContext(), Splash.class)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, intent, 0); builder.setContentIntent(contentIntent); builder.setContentTitle(getText(R.string.notif_loc_short)); if (errorTime > 0 && DEBUG_ERRORS) builder.setContentText(errorMsg); else builder.setContentText(getText(msgId)); builder.setOngoing(true); Notification notification = builder.getNotification(); return notification; }
From source file:org.sogrey.frame.utils.FileUtil.java
/** * app// w w w . j ava 2s .c o m * * @param context * * @author Sogrey * @date 2015-11-27?1:56:55 */ public static void openFolder(Context context, String path) { // Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // Uri uri = Uri.parse(path); // intent.setDataAndType(uri, "text/csv"); // try { // context.startActivity(Intent.createChooser(intent, "Open folder")); // } catch (Exception e) { // } // File root = new File(path); // Uri uri = Uri.fromFile(root); // Intent intent = new Intent(); // intent.setAction(android.content.Intent.ACTION_VIEW); // intent.setData(uri); // context.startActivity(intent); // Intent intent = new Intent(); // String videoPath = path;// // File file = new File(videoPath); // Uri uri = Uri.fromFile(file); // intent.setData(uri); // intent.setAction(android.content.Intent.ACTION_VIEW);// "com.xxx.xxx" // ??? // try { // context.startActivity(intent); // } catch (ActivityNotFoundException e) { // e.printStackTrace(); // } // Intent i = new Intent(Intent.ACTION_GET_CONTENT); // // i.setAction(android.content.Intent.ACTION_VIEW); // File file = new File(path); // i.setDataAndType(Uri.fromFile(file), "file/*"); // try { // context.startActivity(i); // } catch (Exception e) { // } // Intent intent = new Intent(); // File file = new File(path); // intent.setAction(android.content.Intent.ACTION_VIEW); // // intent.setData(Uri.fromFile(file)); // intent.setDataAndType(Uri.fromFile(file), "file/*"); // try { // context.startActivity(intent); // } catch (Exception e) { // } Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // intent.setType("*/*"); intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); File file = new File(path); intent.setData(Uri.fromFile(file)); // intent.setDataAndType(Uri.fromFile(file), "*/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); try { context.startActivity(intent); } catch (ActivityNotFoundException ex) { ToastUtil.showToast(context, "?"); } }