List of usage examples for android.content Intent setData
public @NonNull Intent setData(@Nullable Uri data)
From source file:com.google.developers.actions.debugger.MainActivity.java
public void askCayley(final String query) { new AsyncTask<Void, Void, String>() { @Override/*from w w w. j a v a2s .c o m*/ protected String doInBackground(Void... voids) { try { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(Utils.CAYLEY_URL); String queryString = WordUtils.capitalize(query); String cayleyReq = "function getActionForArtists(artist) {\n" + " return artist.In(\"http://schema.org/sameAs\").Out(\"http://schema.org/potentialAction\").Has(\"a\", \"http://schema.org/ListenAction\").Out(\"http://schema.org/target\")\n" + "}\n" + "\n" + "function getIdFor(thing) {\n" + " return g.V(thing).In([\"http://rdf.freebase.com/ns/type.object.name\", \"http://schema.org/name\"]).ToValue()\n" + "}\n" + "\n" + "function getTypeFor(id) {\n" + " return g.V(id).Out(\"a\").ToValue()\n" + "}\n" + "\n" + "function getActionForName(name) {\n" + " var uri = getIdFor(name)\n" + " if (uri == null) {\n" + " return\n" + " }\n" + " var type = getTypeFor(uri)\n" + " var artist_query\n" + " if (type == \"http://rdf.freebase.com/ns/music.genre\") {\n" + " artist_query = g.V(uri).In(\"http://rdf.freebase.com/ns/music.artist.genre\")\n" + " } else {\n" + " artist_query = g.V(uri)\n" + " }\n" + " return getActionForArtists(artist_query)\n" + "}\n" + "\n" + "getActionForName(\"" + queryString + "\").All()"; httppost.setEntity(new StringEntity(cayleyReq)); // Execute HTTP Post Request HttpResponse httpResponse = httpclient.execute(httppost); String response = EntityUtils.toString(httpResponse.getEntity()); Gson gson = new Gson(); CayleyResult cayleyResult = gson.fromJson(response, CayleyResult.class); if (cayleyResult.isEmpty()) { Utils.showError(MainActivity.this, "No nodes found for " + queryString + " in Cayley."); return null; } return cayleyResult.getResult(0).getId(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return null; } @Override protected void onPostExecute(String appId) { setProgressBarIndeterminateVisibility(false); if (appId == null) { return; } Intent intent = new Intent(); intent.setAction("android.media.action.MEDIA_PLAY_FROM_SEARCH"); intent.setData(Uri.parse(Utils.convertGSAtoUri(appId))); try { startActivity(intent); } catch (ActivityNotFoundException e) { Utils.showError(MainActivity.this, appId + "Activity not found"); } } }.execute((Void) null); }
From source file:com.miz.functions.YoutubeTrailerSearch.java
@Override protected void onPostExecute(String result) { if (result != null) { if (YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(mActivity) .equals(YouTubeInitializationResult.SUCCESS)) { Intent intent = YouTubeStandalonePlayer.createVideoIntent(mActivity, MizLib.getYouTubeApiKey(mActivity), MizLib.getYouTubeId(result), 0, false, true); mActivity.startActivity(intent); } else {/*from www. jav a 2 s. c o m*/ Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(result)); } } else { Toast.makeText(mActivity, mActivity.getString(R.string.errorSomethingWentWrong), Toast.LENGTH_LONG) .show(); } }
From source file:de.ub0r.android.callmeter.ui.prefs.PreferencesPlain.java
@Override public boolean onPreferenceClick(final Preference preference) { final String k = preference.getKey(); if (k.equals("export_rules")) { Preferences.exportData(this, null, null, null, ExportProvider.EXPORT_RULESET_FILE, null); return true; } else if (k.equals("export_rules_sd")) { Preferences.exportData(this, null, null, null, ExportProvider.EXPORT_RULESET_FILE, "sdcard"); return true; } else if (k.equals("export_rules_dev")) { Preferences.exportData(this, null, null, null, ExportProvider.EXPORT_RULESET_FILE, "android@ub0r.de"); return true; } else if (k.equals("export_logs")) { Preferences.exportData(this, null, null, null, ExportProvider.EXPORT_LOGS_FILE, null); return true; } else if (k.equals("export_logs_csv")) { Preferences.exportLogsCsv(this); return true; } else if (k.equals("export_numgroups")) { Preferences.exportData(this, null, null, null, ExportProvider.EXPORT_NUMGROUPS_FILE, null); return true; } else if (k.equals("export_hourgroups")) { Preferences.exportData(this, null, null, null, ExportProvider.EXPORT_HOURGROUPS_FILE, null); return true; } else if (k.equals("import_rules_default")) { final Intent i = new Intent(this, Preferences.class); i.setData(Uri.parse("content://default")); startActivity(i);/*from w w w. java 2 s.c o m*/ return true; } return false; }
From source file:org.lol.reddit.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final Activity activity, final Action action) { switch (action) { case UPVOTE:// w w w. jav a 2 s . c o m post.action(activity, RedditAPI.RedditAction.UPVOTE); break; case DOWNVOTE: post.action(activity, RedditAPI.RedditAction.DOWNVOTE); break; case UNVOTE: post.action(activity, RedditAPI.RedditAction.UNVOTE); break; case SAVE: post.action(activity, RedditAPI.RedditAction.SAVE); break; case UNSAVE: post.action(activity, RedditAPI.RedditAction.UNSAVE); break; case HIDE: post.action(activity, RedditAPI.RedditAction.HIDE); break; case UNHIDE: post.action(activity, RedditAPI.RedditAction.UNHIDE); break; case REPORT: new AlertDialog.Builder(activity).setTitle(R.string.action_report) .setMessage(R.string.action_report_sure) .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.RedditAction.REPORT); // TODO update the view to show the result // TODO don't forget, this also hides } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case EXTERNAL: { final Intent intent = new Intent(Intent.ACTION_VIEW); String url = (activity instanceof WebViewActivity) ? ((WebViewActivity) activity).getCurrentUrl() : post.url; intent.setData(Uri.parse(url)); activity.startActivity(intent); break; } case SELFTEXT_LINKS: { final HashSet<String> linksInComment = LinkHandler .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.selftext)); if (linksInComment.isEmpty()) { General.quickToast(activity, R.string.error_toast_no_urls_in_self); } else { final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setItems(linksArr, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_selftext_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; } case SAVE_IMAGE: { final RedditAccount anon = RedditAccountManager.getAnon(); CacheManager.getInstance(activity) .makeRequest(new CacheRequest(General.uriFromString(post.imageUrl), anon, null, Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY, Constants.FileType.IMAGE, false, false, false, activity) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onDownloadNecessary() { General.quickToast(context, R.string.download_downloading); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status, url.toString()); General.showResultDialog(activity, error); } @Override protected void onProgress(long bytesRead, long totalBytes) { } @Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { File dst = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), General.uriFromString(post.imageUrl).getPath()); if (dst.exists()) { int count = 0; while (dst.exists()) { count++; dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), count + "_" + General.uriFromString(post.imageUrl).getPath().substring(1)); } } try { final InputStream cacheFileInputStream = cacheFile.getInputStream(); if (cacheFileInputStream == null) { notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image"); return; } General.copyFile(cacheFileInputStream, dst); } catch (IOException e) { notifyFailure(RequestFailureType.STORAGE, e, null, "Could not copy file"); return; } activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + dst.getAbsolutePath()))); General.quickToast(context, context.getString(R.string.action_save_image_success) + " " + dst.getAbsolutePath()); } }); break; } case SHARE: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, post.title); mailer.putExtra(Intent.EXTRA_TEXT, post.url); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; } case SHARE_COMMENTS: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.title); mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit.getUri(Constants.Reddit.PATH_COMMENTS + post.idAlone).toString()); activity.startActivity( Intent.createChooser(mailer, activity.getString(R.string.action_share_comments))); break; } case COPY: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(post.url); break; } case GOTO_SUBREDDIT: { try { final Intent intent = new Intent(activity, PostListingActivity.class); intent.setData(SubredditPostListURL.getSubreddit(post.src.subreddit).generateJsonUri()); activity.startActivityForResult(intent, 1); } catch (RedditSubreddit.InvalidSubredditNameException e) { Toast.makeText(activity, R.string.invalid_subreddit_name, Toast.LENGTH_LONG).show(); } break; } case USER_PROFILE: LinkHandler.onLinkClicked(activity, new UserProfileURL(post.src.author).toString()); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src).show(activity); break; case COMMENTS: ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK: ((RedditPostView.PostSelectionListener) activity).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) activity).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra("parentIdAndType", post.idAndType); activity.startActivity(intent); break; } }
From source file:ln.paign10.arduinopixel.MainActivity.java
public void openURL() { String url = "https://codebender.cc/sketch:31742"; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent);//from w w w . j a v a2 s .c om }
From source file:com.ryan.ryanreader.fragments.UserProfileDialog.java
@Override public final void prepare(final Context context, final LinearLayout items) { final LoadingView loadingView = new LoadingView(context, R.string.download_waiting, true, true); items.addView(loadingView);//from ww w.ja v a2 s.c om username = getArguments().getString("user"); final CacheManager cm = CacheManager.getInstance(context); RedditAPI.getUser(cm, username, new APIResponseHandler.UserResponseHandler(context) { @Override protected void onDownloadStarted() { if (!active) return; loadingView.setIndeterminate(R.string.download_connecting); } @Override protected void onSuccess(final RedditUser user, long timestamp) { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { if (!active) return; loadingView.setDone(R.string.download_done); final LinearLayout karmaLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.karma); items.addView(karmaLayout); final TextView linkKarma = (TextView) karmaLayout.findViewById(R.id.layout_karma_text_link); final TextView commentKarma = (TextView) karmaLayout .findViewById(R.id.layout_karma_text_comment); linkKarma.setText(String.valueOf(user.link_karma)); commentKarma.setText(String.valueOf(user.comment_karma)); items.addView(propView(context, R.string.userprofile_created, RRTime.formatDateTime(user.created_utc * 1000, context), false)); if (user.has_mail != null) { items.addView(propView(context, R.string.userprofile_hasmail, user.has_mail ? R.string.general_true : R.string.general_false, false)); } if (user.has_mod_mail != null) { items.addView(propView(context, R.string.userprofile_hasmodmail, user.has_mod_mail ? R.string.general_true : R.string.general_false, false)); } if (user.is_friend) { items.addView( propView(context, R.string.userprofile_isfriend, R.string.general_true, false)); } if (user.is_gold) { items.addView( propView(context, R.string.userprofile_isgold, R.string.general_true, false)); } if (user.is_mod) { items.addView(propView(context, R.string.userprofile_moderator, R.string.general_true, false)); } final Button commentsButton = new Button(context); commentsButton.setText(R.string.userprofile_viewcomments); commentsButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final Intent intent = new Intent(context, CommentListingActivity.class); intent.setData(Uri.parse(Constants.Reddit .getUri("/user/" + username + "/comments.json").toString())); startActivity(intent); dismiss(); } }); items.addView(commentsButton); // TODO use margin? or framelayout? scale padding dp // TODO change button color commentsButton.setPadding(20, 20, 20, 20); final Button postsButton = new Button(context); postsButton.setText(R.string.userprofile_viewposts); postsButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final Intent intent = new Intent(context, PostListingActivity.class); intent.putExtra("subreddit", new RedditSubreddit("/user/" + username + "/submitted", "Submitted by " + username, false)); startActivity(intent); dismiss(); } }); items.addView(postsButton); // TODO use margin? or framelayout? scale padding dp postsButton.setPadding(20, 20, 20, 20); } }); } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { if (!active) return; loadingView.setDone(R.string.download_failed); final RRError error = General.getGeneralErrorForFailure(context, type, t, status); items.addView(new ErrorView(getSupportActivity(), error)); } }); } @Override protected void onFailure(final APIFailureType type) { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { if (!active) return; loadingView.setDone(R.string.download_failed); final RRError error = General.getGeneralErrorForFailure(context, type); items.addView(new ErrorView(getSupportActivity(), error)); } }); } }, RedditAccountManager.getInstance(context).getDefaultAccount(), CacheRequest.DownloadType.FORCE, true, context); }
From source file:jp.co.conit.sss.sn.ex2.service.SendMessageIdIntentService.java
/** * SamuraiNotification????snUserdata??????? * /*from www. j av a2s .c om*/ * @param snUserdata */ private void startActivity4Userdata(String snUserdata) { Intent activityIntent = new Intent(); if (StringUtil.isEmpty(snUserdata) || snUserdata.equals("null")) { activityIntent.setClass(getApplicationContext(), MessagesActivity.class); } else { if (snUserdata.startsWith("http")) { activityIntent.setAction(Intent.ACTION_VIEW); activityIntent.setData(Uri.parse(snUserdata)); } else { activityIntent.setClass(getApplicationContext(), UserDataActivity.class); activityIntent.putExtra("option", snUserdata); } } activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(activityIntent); }
From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ESUP_NFC_TAG_SERVER_URL = getEsupNfcTagServerUrl(getApplicationContext()); //To keep session for desfire async requests CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); LocalStorage.getInstance(getApplicationContext()); Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(getApplicationContext())); setContentView(R.layout.activity_main); mAdapter = NfcAdapter.getDefaultAdapter(this); checkHardware(mAdapter);/*from w ww. j a v a2 s . c o m*/ localStorageDBHelper = LocalStorage.getInstance(this.getApplicationContext()); String numeroId = localStorageDBHelper.getValue("numeroId"); TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String imei = telephonyManager.getDeviceId(); url = ESUP_NFC_TAG_SERVER_URL + "/nfc-index?numeroId=" + numeroId + "&imei=" + imei + "&macAddress=" + getMacAddr() + "&apkVersion=" + getApkVersion(); view = (WebView) this.findViewById(R.id.webView); view.clearCache(true); view.addJavascriptInterface(new LocalStorageJavaScriptInterface(this.getApplicationContext()), "AndroidLocalStorage"); view.addJavascriptInterface(new AndroidJavaScriptInterface(this.getApplicationContext()), "Android"); view.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { if (progress == 100) { AUTH_TYPE = localStorageDBHelper.getValue("authType"); } } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { log.info("Webview console message : " + consoleMessage.message()); return false; } }); view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { view.reload(); return true; } }); view.getSettings().setAllowContentAccess(true); WebSettings webSettings = view.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setDatabasePath(this.getFilesDir().getParentFile().getPath() + "/databases/"); view.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } }); view.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { } }); view.loadUrl(url); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); }
From source file:uk.org.openseizuredetector.OsdUtil.java
/** * Start the SdServer service//from w w w . ja v a 2 s . c om */ public void startServer() { // Start the server Log.v(TAG, "startServer()"); writeToSysLogFile("startServer() - starting server"); Intent sdServerIntent; sdServerIntent = new Intent(mContext, SdServer.class); sdServerIntent.setData(Uri.parse("Start")); mContext.startService(sdServerIntent); }
From source file:uk.org.openseizuredetector.OsdUtil.java
/** * Stop the SdServer service/*from w w w . ja v a 2 s. c o m*/ */ public void stopServer() { Log.v(TAG, "stopping Server..."); writeToSysLogFile("stopserver() - stopping server"); // then send an Intent to stop the service. Intent sdServerIntent; sdServerIntent = new Intent(mContext, SdServer.class); sdServerIntent.setData(Uri.parse("Stop")); mContext.stopService(sdServerIntent); }