List of usage examples for android.content Intent setData
public @NonNull Intent setData(@Nullable Uri data)
From source file:net.bytten.comicviewer.ComicViewerActivity.java
public void explain() { final IComicInfo comic = comicInfo; new AsyncTask<Object, Integer, Integer>() { @Override/*from www .j a va 2 s . c om*/ 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.example.scrumptious.SelectionFragment.java
private void startPickerActivity(Uri data, int requestCode) { Intent intent = new Intent(); intent.setData(data); intent.setClass(getActivity(), PickerActivity.class); startActivityForResult(intent, requestCode); }
From source file:com.mocap.MocapFragment.java
public void SaveOBJ(Context context, MyGLSurfaceView glview) { Log.i(TAG, "DIR: "); float sVertices[] = glview.getsVertices(); FileOutputStream fOut = null; OutputStreamWriter osw = null; File mFile;/*from ww w .ja v a 2s . co m*/ if (Environment.DIRECTORY_PICTURES != null) { try { mFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "mocap.obj"); Log.i(TAG, "Long Vertices: " + sVertices.length); fOut = new FileOutputStream(mFile); osw = new OutputStreamWriter(fOut); osw.write("# *.obj file (Generate by Mocap 3D)\n"); osw.flush(); for (int i = 0; i < sVertices.length - 4; i = i + 3) { try { String data = "v " + Float.toString(sVertices[i]) + " " + Float.toString(sVertices[i + 1]) + " " + Float.toString(sVertices[i + 2]) + "\n"; Log.i(TAG, i + ": " + data); osw.write(data); osw.flush(); } catch (Exception e) { Toast.makeText(context, "erreur d'criture: " + e, Toast.LENGTH_SHORT).show(); Log.i(TAG, "Erreur: " + e); } } osw.write("# lignes:\n"); osw.write("l "); osw.flush(); ; for (int i = 1; i < (-1 + sVertices.length / 3); i++) { osw.write(i + " "); osw.flush(); } //popup surgissant pour le rsultat Toast.makeText(getActivity(), "Save : " + Environment.DIRECTORY_PICTURES + "/mocap.obj ", Toast.LENGTH_SHORT).show(); //lancement d'un explorateur de fichiers vers le fichier crer //systeme des intend try { File root = new File(Environment.DIRECTORY_PICTURES); Uri uri = Uri.fromFile(mFile); Intent intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT); intent.setData(uri); // Verify that the intent will resolve to an activity if (intent.resolveActivity(getActivity().getPackageManager()) != null) { Log.i(TAG, "intent pk: "); getActivity().startActivityForResult(intent, 1); } } catch (Exception e) { Log.i(TAG, "Erreur intent: " + e); } } catch (Exception e) { Toast.makeText(context, "Settings not saved", Toast.LENGTH_SHORT).show(); } finally { try { osw.close(); fOut.close(); } catch (IOException e) { Toast.makeText(context, "Settings not saved", Toast.LENGTH_SHORT).show(); } } } else { Toast.makeText(context, "Pas de carte ext", Toast.LENGTH_SHORT).show(); } }
From source file:com.NotifyMe.GcmIntentService.java
private void sendNotificationWithExtras(Bundle extras) { String message = extras.getString("message"); String service = extras.getString("service"); String type = extras.getString("type"); String title = "NotifyMe [" + service + "]"; mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent;//from w w w . jav a 2 s.c o m if (service.equals("Reddit")) { Intent resultIntent = new Intent(Intent.ACTION_VIEW); String url = "http://reddit.com"; if (type.equals("reddit-front-page")) { if (Integer.parseInt(extras.getString("count")) == 1) { try { JSONArray posts = new JSONArray(extras.getString("links")); url = posts.getJSONObject(0).getString("url"); message = posts.getJSONObject(0).getString("title"); } catch (JSONException e) { url = "http://reddit.com"; } } else { url = "http://reddit.com"; } } else if (type.equals("user-comment") || type.equals("user-submission")) { url = extras.getString("link"); } resultIntent.setData(Uri.parse(url)); contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else if (service.equals("weather")) { Intent resultIntent; Intent weatherIntent = getWeatherAppIntent(); if (weatherIntent != null) { resultIntent = weatherIntent; } else { resultIntent = new Intent(Intent.ACTION_VIEW); String url = "http://weather.com/"; resultIntent.setData(Uri.parse(url)); } contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else if (service.equals("poly")) { Intent resultIntent = new Intent(Intent.ACTION_VIEW); String url = "https://www4.polymtl.ca/poly/poly.html"; resultIntent.setData(Uri.parse(url)); contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else if (service.equals("github")) { Intent resultIntent = new Intent(Intent.ACTION_VIEW); String url = extras.getString("link"); resultIntent.setData(Uri.parse(url)); contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else { contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(title).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setDefaults(Notification.DEFAULT_VIBRATE).setOnlyAlertOnce(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:nf.frex.android.FrexActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.zoom_all: view.zoomAll();// w w w.ja v a2 s. c om return true; case R.id.zoom_in: view.zoomRegion(2.0); return true; case R.id.zoom_out: view.zoomRegion(0.5); return true; case R.id.colors: showDialog(R.id.colors); return true; case R.id.decorations: showDialog(R.id.decorations); return true; case R.id.properties: showDialog(R.id.properties); return true; case R.id.manage_fractals: if (new FrexIO(this).hasFiles()) { startActivityForResult(new Intent(this, ManagerActivity.class), R.id.manage_fractals); } else { Toast.makeText(FrexActivity.this, getString(R.string.no_fractals_found), Toast.LENGTH_SHORT).show(); } return true; case R.id.save_fractal: saveFractal(); return true; case R.id.set_wallpaper: setWallpaper(); return true; case R.id.examples: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(EXAMPLES_URL)); startActivity(intent); return true; case R.id.settings: startActivityForResult(new Intent(this, SettingsActivity.class), R.id.settings); return true; } return super.onOptionsItemSelected(item); }
From source file:com.polyvi.xface.view.XWebViewClient.java
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { try {/*from www. j ava 2 s . co m*/ // ?exec()?. if (XNativeToJsMessageQueue.ENABLE_LOCATION_CHANGE_EXEC_MODE && url.startsWith(XFACE_EXEC_URL_PREFIX)) { handleExecUrl(url); } XWhiteList whiteList = mWebAppView.getOwnerApp().getAppInfo().getWhiteList(); if (url.startsWith("tel") && !XConfiguration.getInstance().isTelLinkEnabled()) { return true; } // TODO:??phonegap?url???? else if (url.startsWith(XConstant.FILE_SCHEME) || url.startsWith("data:") || ((url.startsWith(XConstant.HTTP_SCHEME) || url.startsWith(XConstant.HTTPS_SCHEME)) && (null != whiteList && whiteList.isUrlWhiteListed(url)))) { /** * I9003??url? url??? */ return handleUrl(url); } else if (url.startsWith(XConstant.SCHEME_SMS)) { Intent intent = new Intent(Intent.ACTION_VIEW); // ?? String address = null; int parmIndex = url.indexOf('?'); if (-1 == parmIndex) { address = url.substring(XConstant.SCHEME_SMS.length()); } else { address = url.substring(XConstant.SCHEME_SMS.length(), parmIndex); Uri uri = Uri.parse(url); String query = uri.getQuery(); if (null != query) { if (query.startsWith(SMS_BODY)) { intent.putExtra("sms_body", query.substring(SMS_BODY.length())); } } } intent.setData(Uri.parse(XConstant.SCHEME_SMS + address)); intent.putExtra("address", address); intent.setType("vnd.android-dir/mms-sms"); mSystemContext.getContext().startActivity(intent); return true; } else { // ????? return startSysApplication(url); } } catch (ActivityNotFoundException e) { XLog.e(CLASS_NAME, e.toString()); } return false; }
From source file:heartware.com.heartware_master.FriendsFragment.java
private void startPickerActivity(Uri data, int requestCode) { Intent intent = new Intent(); intent.setData(data); intent.setClass(getActivity(), FB_PickerActivity.class); startActivityForResult(intent, requestCode); }
From source file:in.shick.diode.mail.InboxListActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case Constants.DIALOG_COMMENT_CLICK: Intent i = new Intent(getApplicationContext(), CommentsListActivity.class); i.setData(Util.createCommentUri(mVoteTargetThingInfo, 0)); i.putExtra(Constants.EXTRA_SUBREDDIT, mVoteTargetThingInfo.getSubreddit()); i.putExtra(Constants.EXTRA_TITLE, mVoteTargetThingInfo.getTitle()); startActivity(i);/*from www . ja v a 2 s.co m*/ return true; case Constants.DIALOG_MESSAGE_CLICK: showDialog(Constants.DIALOG_REPLY); return true; case Constants.DIALOG_LINKS: Common.showLinksDialog(InboxListActivity.this, mSettings, mVoteTargetThingInfo); return true; default: return super.onContextItemSelected(item); } }
From source file:com.likemag.cordova.inappbrowsercustom.InAppBrowser.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *///from w w w . j av a 2 s . c om public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { if (action.equals("open")) { this.callbackContext = callbackContext; final String url = args.getString(0); String t = args.optString(1); if (t == null || t.equals("") || t.equals(NULL)) { t = SELF; } final String target = t; //PDC TEAM //Set close button caption and return option string String featureString = parseCloseButtonCaption(args.optString(2)); //PDC TEAM //past to parseFeature function string without close button caption final HashMap<String, Boolean> features = parseFeature(featureString); Log.d(LOG_TAG, "target = " + target); this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { String result = ""; // SELF if (SELF.equals(target)) { Log.d(LOG_TAG, "in self"); /* This code exists for compatibility between 3.x and 4.x versions of Cordova. * Previously the Config class had a static method, isUrlWhitelisted(). That * responsibility has been moved to the plugins, with an aggregating method in * PluginManager. */ Boolean shouldAllowNavigation = null; if (url.startsWith("javascript:")) { shouldAllowNavigation = true; } if (shouldAllowNavigation == null) { try { Method iuw = Config.class.getMethod("isUrlWhiteListed", String.class); shouldAllowNavigation = (Boolean) iuw.invoke(null, url); } catch (NoSuchMethodException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } if (shouldAllowNavigation == null) { try { Method gpm = webView.getClass().getMethod("getPluginManager"); PluginManager pm = (PluginManager) gpm.invoke(webView); Method san = pm.getClass().getMethod("shouldAllowNavigation", String.class); shouldAllowNavigation = (Boolean) san.invoke(pm, url); } catch (NoSuchMethodException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } // load in webview if (Boolean.TRUE.equals(shouldAllowNavigation)) { Log.d(LOG_TAG, "loading in webview"); webView.loadUrl(url); } //Load the dialer else if (url.startsWith(WebView.SCHEME_TEL)) { try { Log.d(LOG_TAG, "loading in dialer"); Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse(url)); cordova.getActivity().startActivity(intent); } catch (android.content.ActivityNotFoundException e) { LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); } } // load in InAppBrowser else { Log.d(LOG_TAG, "loading in InAppBrowser"); result = showWebPage(url, features); } } // SYSTEM else if (SYSTEM.equals(target)) { Log.d(LOG_TAG, "in system"); result = openExternal(url); } // BLANK - or anything else else { Log.d(LOG_TAG, "in blank"); result = showWebPage(url, features); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } }); } else if (action.equals("close")) { closeDialog(); } else if (action.equals("injectScriptCode")) { String jsWrapper = null; if (args.getBoolean(1)) { jsWrapper = String.format("prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')", callbackContext.getCallbackId()); } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectScriptFile")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectStyleCode")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectStyleFile")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("show")) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { dialog.show(); } }); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); } else { return false; } return true; }
From source file:com.jamiealtizer.cordova.inappbrowser.InAppBrowser.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *//*from w ww . jav a 2s . c o m*/ public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { if (action.equals("open")) { this.callbackContext = callbackContext; final String url = args.getString(0); String t = args.optString(1); if (t == null || t.equals("") || t.equals(NULL)) { t = SELF; } final String target = t; final HashMap<String, Boolean> features = parseFeature(args.optString(2)); Log.d(LOG_TAG, "target = " + target); this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { String result = ""; // SELF if (SELF.equals(target)) { Log.d(LOG_TAG, "in self"); /* This code exists for compatibility between 3.x and 4.x versions of Cordova. * Previously the Config class had a static method, isUrlWhitelisted(). That * responsibility has been moved to the plugins, with an aggregating method in * PluginManager. */ Boolean shouldAllowNavigation = null; if (url.startsWith("javascript:")) { shouldAllowNavigation = true; } if (shouldAllowNavigation == null) { try { Method iuw = Config.class.getMethod("isUrlWhiteListed", String.class); shouldAllowNavigation = (Boolean) iuw.invoke(null, url); } catch (NoSuchMethodException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } if (shouldAllowNavigation == null) { try { Method gpm = webView.getClass().getMethod("getPluginManager"); PluginManager pm = (PluginManager) gpm.invoke(webView); Method san = pm.getClass().getMethod("shouldAllowNavigation", String.class); shouldAllowNavigation = (Boolean) san.invoke(pm, url); } catch (NoSuchMethodException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } // load in webview if (Boolean.TRUE.equals(shouldAllowNavigation)) { Log.d(LOG_TAG, "loading in webview"); webView.loadUrl(url); } //Load the dialer else if (url.startsWith(WebView.SCHEME_TEL)) { try { Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse(url)); cordova.getActivity().startActivity(intent); } catch (android.content.ActivityNotFoundException e) { LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); } } // load in InAppBrowser else { result = showWebPage(url, features); } } // SYSTEM else if (SYSTEM.equals(target)) { Log.d(LOG_TAG, "in system"); result = openExternal(url); } // BLANK - or anything else else { Log.d(LOG_TAG, "in blank"); result = showWebPage(url, features); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } }); } else if (action.equals("close")) { closeDialog(); } else if (action.equals("injectScriptCode")) { String jsWrapper = null; if (args.getBoolean(1)) { jsWrapper = String.format("prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')", callbackContext.getCallbackId()); } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectScriptFile")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectStyleCode")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectStyleFile")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("show")) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { dialog.show(); } }); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); } else { return false; } return true; }