Example usage for android.content Intent setType

List of usage examples for android.content Intent setType

Introduction

In this page you can find the example usage for android.content Intent setType.

Prototype

public @NonNull Intent setType(@Nullable String type) 

Source Link

Document

Set an explicit MIME data type.

Usage

From source file:com.altcanvas.twitspeak.TwitSpeakActivity.java

public boolean checkStackTrace() {
    FileInputStream traceIn = null;
    try {/*from  ww  w .  ja v  a  2 s.  com*/
        traceIn = openFileInput("stack.trace");
        traceIn.close();
    } catch (FileNotFoundException fnfe) {
        // No stack trace available
        return false;
    } catch (IOException ioe) {
        return false;
    }

    AlertDialog alert = new AlertDialog.Builder(this).create();
    alert.setMessage(getResources().getString(R.string.crashreport_msg));

    alert.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.emailstr),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    String trace = "";
                    String line = null;
                    try {
                        BufferedReader reader = new BufferedReader(
                                new InputStreamReader(TwitSpeakActivity.this.openFileInput("stack.trace")));
                        while ((line = reader.readLine()) != null) {
                            trace += line + "\n";
                        }
                    } catch (FileNotFoundException fnfe) {
                        Log.logException(TAG, fnfe);
                    } catch (IOException ioe) {
                        Log.logException(TAG, ioe);
                    }

                    Intent sendIntent = new Intent(Intent.ACTION_SEND);
                    String subject = "Error report";
                    String body = getResources().getString(R.string.mailthisto_msg) + " jayesh@altcanvas.com: "
                            + "\n\n" + G.getPhoneInfo() + "\n\n" + "TwitSpeak [" + G.VERSION_STRING + "]"
                            + "\n\n" + trace + "\n\n";

                    sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "jayesh@altcanvas.com" });
                    sendIntent.putExtra(Intent.EXTRA_TEXT, body);
                    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                    sendIntent.setType("message/rfc822");

                    TwitSpeakActivity.this.startActivityForResult(
                            Intent.createChooser(sendIntent, getResources().getString(R.string.emailstr)),
                            G.REQCODE_EMAIL_STACK_TRACE);

                    TwitSpeakActivity.this.deleteFile("stack.trace");
                }
            });
    alert.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancelstr),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    TwitSpeakActivity.this.deleteFile("stack.trace");
                    TwitSpeakActivity.this.continueOnCreate();
                }
            });

    alert.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            TwitSpeakActivity.this.deleteFile("stack.trace");
            TwitSpeakActivity.this.continueOnCreate();
        }
    });

    alert.show();

    return true;
}

From source file:com.androidquery.simplefeed.activity.PostActivity.java

public void galleryClicked(View view) {

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, getString(R.string.photo)), Constants.ACTIVITY_GALLERY);

}

From source file:com.gelakinetic.mtgfam.fragments.TradeFragment.java

/**
 * Build a plaintext trade and share it.
 *//*from www  . ja  va2 s  .  c  o m*/
private void shareTrade() {

    StringBuilder sb = new StringBuilder();

    /* Add all the cards to the StringBuilder from the left, tallying the price */
    float totalPrice = 0;
    for (MtgCard card : mListLeft) {
        totalPrice += (card.toTradeShareString(sb, getString(R.string.wishlist_foil)) / 100.0f);
    }
    sb.append(String.format(Locale.US, PRICE_FORMAT + "%n", totalPrice));

    /* Simple divider */
    sb.append("--------\n");

    /* Add all the cards to the StringBuilder from the right, tallying the price */
    totalPrice = 0;
    for (MtgCard card : mListRight) {
        totalPrice += (card.toTradeShareString(sb, getString(R.string.wishlist_foil)) / 100.0f);
    }
    sb.append(String.format(Locale.US, PRICE_FORMAT, totalPrice));

    /* Send the Intent on it's merry way */
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, R.string.trade_share_title);
    sendIntent.putExtra(Intent.EXTRA_TEXT, sb.toString());
    sendIntent.setType("text/plain");

    try {
        startActivity(Intent.createChooser(sendIntent, getString(R.string.trader_share)));
    } catch (android.content.ActivityNotFoundException ex) {
        ToastWrapper.makeAndShowText(getActivity(), R.string.error_no_email_client, ToastWrapper.LENGTH_SHORT);
    }
}

From source file:com.krayzk9s.imgurholo.ui.ImagesFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // handle item selection
    final Activity activity = getActivity();
    switch (item.getItemId()) {
    case R.id.action_download:
        Toast.makeText(activity,//w w w  .java2 s.  co  m
                String.format(getActivity().getResources().getString(R.string.toast_downloading), urls.size()),
                Toast.LENGTH_SHORT).show();
        Intent serviceIntent = new Intent(activity, DownloadService.class);
        serviceIntent.putParcelableArrayListExtra("ids", ids);
        if (albumId != null)
            serviceIntent.putExtra("albumName", albumId);
        else
            serviceIntent.putExtra("albumName", imageCall);
        activity.startService(serviceIntent);
        return true;
    case R.id.action_refresh:
        urls = new ArrayList<String>();
        ids = new ArrayList<JSONParcelable>();
        page = 0;
        makeGallery();
        return true;
    case R.id.action_copy:
        ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("imgur Link", "http://imgur.com/a/" + albumId);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(activity, R.string.toast_copied, Toast.LENGTH_SHORT).show();
        return true;
    case R.id.action_share:
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        intent.putExtra(Intent.EXTRA_TEXT, "http://imgur.com/a/" + albumId);
        startActivity(intent);
        return true;
    case R.id.action_new:
        Intent i = new Intent(this.getActivity().getApplicationContext(), ImageSelectActivity.class);
        startActivityForResult(i, 1);
        //select image
        return true;
    case R.id.action_comments:
        if (galleryAlbumData != null) {
            CommentsAsync commentsAsync = new CommentsAsync(((ImgurHoloActivity) getActivity()),
                    galleryAlbumData);
            commentsAsync.execute();
            return true;
        } else
            return super.onOptionsItemSelected(item);
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.android.gallery3d.app.Gallery.java

private void initializeByIntent() {
    Intent intent = getIntent();
    String action = intent.getAction();

    if (Intent.ACTION_GET_CONTENT.equalsIgnoreCase(action)) {
        startGetContent(intent);//from   w w  w.ja va 2  s  .co m
    } else if (Intent.ACTION_PICK.equalsIgnoreCase(action)) {
        // We do NOT really support the PICK intent. Handle it as
        // the GET_CONTENT. However, we need to translate the type
        // in the intent here.
        Log.w(TAG, "action PICK is not supported");
        String type = Utils.ensureNotNull(intent.getType());
        if (type.startsWith("vnd.android.cursor.dir/")) {
            if (type.endsWith("/image"))
                intent.setType("image/*");
            if (type.endsWith("/video"))
                intent.setType("video/*");
        }
        startGetContent(intent);
    } else if (Intent.ACTION_VIEW.equalsIgnoreCase(action) || ACTION_REVIEW.equalsIgnoreCase(action)) {
        startViewAction(intent);
    } else {
        startDefaultPage();
    }
}

From source file:com.dvdprime.mobile.android.ui.DocumentViewActivity.java

private Response.Listener<JSONObject> createShortenerReqSuccessListener() {
    return new Response.Listener<JSONObject>() {
        public void onResponse(JSONObject result) {
            try {
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_SUBJECT, getSupportActionBar().getSubtitle());
                Object[] data = new Object[2];
                data[0] = getSupportActionBar().getSubtitle();
                data[1] = result.getString("id");
                intent.putExtra(Intent.EXTRA_TEXT, StringUtil.format("[DP]{0} - {1}", data));
                startActivity(Intent.createChooser(intent, getString(R.string.action_bar_share_with)));
                return;
            } catch (JSONException localJSONException) {
                LOGD(TAG, "Parse error");
            }//from   w  w  w  . j av a  2s . c  om
        }
    };
}

From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java

private void startDilog() {
    AlertDialog.Builder myAlertDilog = new AlertDialog.Builder(GetAllVehicalDetails.this);
    myAlertDilog.setTitle("Upload picture option..");
    myAlertDilog.setMessage("Take Photo");
    myAlertDilog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
        @Override//ww w . jav a 2 s. c o m
        public void onClick(DialogInterface dialog, int which) {
            Intent picIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
            picIntent.setType("image/*");
            picIntent.putExtra("return_data", true);
            startActivityForResult(picIntent, GALLERY_REQUEST);
        }
    });
    myAlertDilog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (checkPermission(Manifest.permission.CAMERA, GetAllVehicalDetails.this)) {
                    openCameraApplication();
                } else {
                    requestPermission(GetAllVehicalDetails.this, new String[] { Manifest.permission.CAMERA },
                            REQUEST_ACESS_CAMERA);
                }
            } else {
                openCameraApplication();
            }
        }
    });
    myAlertDilog.show();
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

public void shareComicImage() {
    if (comicInfo == null || comicInfo.getImage() == null) {
        toast("No image loaded.");
        return;/*from w w w  .j a  v  a 2 s  .co m*/
    }

    new Utility.CancellableAsyncTaskWithProgressDialog<Uri, File>(getStringAppName()) {
        Throwable e;

        @Override
        protected File doInBackground(Uri... params) {
            try {
                File file = new File(getApplicationContext().getExternalCacheDir(),
                        comicDef.getComicTitleAbbrev() + "-" + params[0].getLastPathSegment());
                Utility.blockingSaveFile(file, params[0]);
                return file;

            } catch (InterruptedException ex) {
                return null;
            } catch (Throwable ex) {
                e = ex;
                return null;
            }
        }

        @Override
        protected void onPostExecute(File result) {
            super.onPostExecute(result);
            if (result != null && e == null) {

                try {
                    Uri uri = Uri.fromFile(result);
                    Intent intent = new Intent(Intent.ACTION_SEND, null);
                    intent.setType(Utility.getContentType(uri));
                    intent.putExtra(Intent.EXTRA_STREAM, uri);
                    startActivity(Intent.createChooser(intent, "Share image..."));
                    return;
                } catch (MalformedURLException ex) {
                    e = ex;
                } catch (IOException ex) {
                    e = ex;
                }
            }
            e.printStackTrace();
            failed("Couldn't save attachment: " + e);
        }

    }.start(this, "Saving image...", new Uri[] { comicInfo.getImage() });
}

From source file:com.dvdprime.mobile.android.ui.DocumentViewActivity.java

@Override
public boolean onContextItemSelected(android.view.MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    default://from  www. j a va2s  . co  m
    case CONTEXT_MENU_COPY_URL:
        SystemUtil.copyToClipboard(mActivity, contextUrl);
        break;
    case CONTEXT_MENU_BROWSER:
        AndroidUtil.clickedLinkAction(mActivity, contextUrl);
        break;
    case CONTEXT_MENU_SHARE_LINK:
        Intent localIntent = new Intent("android.intent.action.SEND");
        localIntent.setType("text/plain");
        localIntent.putExtra("android.intent.extra.TEXT", contextUrl);
        startActivity(Intent.createChooser(localIntent, getString(R.string.action_bar_share_with)));
        break;
    case CONTEXT_MENU_SAVE_IMAGE:
        DownloadManager dm = (DownloadManager) getSystemService("download");
        DownloadManager.Request req = new DownloadManager.Request(Uri.parse(this.contextUrl));
        req.setTitle("DP Downloader");
        req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
                StringUtil.substringAfterLast(this.contextUrl, "/"));
        req.setAllowedNetworkTypes(DownloadManager.PAUSED_QUEUED_FOR_WIFI);
        req.setMimeType("image/" + StringUtil.substringAfterLast(contextUrl, "."));
        File localFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        if (!(localFile.exists()))
            localFile.mkdirs();
        dm.enqueue(req);
        break;
    }

    return false;
}

From source file:com.emergencyskills.doe.aed.UI.activity.TabsActivity.java

void init() {

    //        img=(ImageView)findViewById(R.id.logo);

    TextView build = (TextView) findViewById(R.id.checkfornew);
    build.setOnClickListener(new View.OnClickListener() {
        @Override/* w w w.j av a2 s.  c om*/
        public void onClick(View v) {
            if (android.os.Build.VERSION.SDK_INT > 9) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);
            }

            CommonUtilities.logMe("about to check for version ");
            try {
                WebServiceHandler wsb = new WebServiceHandler();
                ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                String result = wsb.getWebServiceData("http://doe.emergencyskills.com/api/version.php",
                        postParameters);
                JSONObject jsonObject = new JSONObject(result);
                String version = jsonObject.getString("version");
                String features = jsonObject.getString("features");
                System.err.println("version is : " + version);
                if (!LoginActivity.myversion.equals(version)) {
                    MyToast.popmessagelong(
                            "There is a new build available. Please download for these features: " + features,
                            TabsActivity.this);
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://vireo.org/esiapp"));
                    browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(browserIntent);
                } else {
                    MyToast.popmessagelong("You have the most current version!", TabsActivity.this);
                }
            } catch (Exception exc) {
                exc.printStackTrace();
            }

        }
    });

    TextView maillog = (TextView) findViewById(R.id.maillog);
    maillog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final Dialog dialog = new Dialog(TabsActivity.this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.dialog_logout);

            TextView question = (TextView) dialog.findViewById(R.id.question);
            question.setText("Are you sure you want to email the log?");
            TextView extra = (TextView) dialog.findViewById(R.id.extratext);
            extra.setText("");

            dialog.getWindow().setBackgroundDrawable(
                    new ColorDrawable(getResources().getColor(android.R.color.transparent)));
            Button yes = (Button) dialog.findViewById(R.id.yesbtn);
            yes.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Intent i = new Intent(Intent.ACTION_SEND);
                    i.setType("message/rfc822");
                    i.putExtra(Intent.EXTRA_EMAIL, new String[] { "rachelc@gmail.com" });
                    i.putExtra(Intent.EXTRA_SUBJECT, "Sending Log");
                    i.putExtra(Intent.EXTRA_TEXT, "body of email");
                    try {
                        startActivity(Intent.createChooser(i, "Send mail..."));
                    } catch (android.content.ActivityNotFoundException ex) {
                        Toast.makeText(TabsActivity.this, "There are no email clients installed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    finish();
                }
            });
            Button no = (Button) dialog.findViewById(R.id.nobtn);
            no.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
            ImageView close = (ImageView) dialog.findViewById(R.id.ivClose);
            close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            dialog.show();

        }
    });

    listops listops = new listops(TabsActivity.this);
    CommonUtilities.logMe("logging in as: " + listops.getString("firstname"));
    TextView name = (TextView) findViewById(R.id.welcome);
    name.setText("Welcome, " + listops.getString("firstname"));

    TextView logoutname = (TextView) findViewById(R.id.logoutname);
    logoutname.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(TabsActivity.this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.dialog_logout);
            dialog.getWindow().setBackgroundDrawable(
                    new ColorDrawable(getResources().getColor(android.R.color.transparent)));
            dialog.setContentView(R.layout.dialog_logout);
            Button yes = (Button) dialog.findViewById(R.id.yesbtn);
            yes.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MyToast.popmessagelong("Logging out... ", TabsActivity.this);
                    SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
                    SharedPreferences.Editor editor = prefs.edit();
                    editor.putString(Constants.loginkey, "");
                    editor.commit();
                    listops listops = new listops(TabsActivity.this);
                    //make sure to remove the downloaded schools

                    Intent intent = new Intent(TabsActivity.this, LoginActivity.class);
                    startActivity(intent);
                    ArrayList<Schoolinfomodel> ls = new ArrayList<Schoolinfomodel>();
                    listops.putdrilllist(ls);
                    listops.putservicelist(ls);
                    listops.putinstallllist(ls);
                    ArrayList<PendingUploadModel> l = new ArrayList<PendingUploadModel>();
                    listops.putpendinglist(l);

                    finish();
                }
            });
            Button no = (Button) dialog.findViewById(R.id.nobtn);
            no.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
            ImageView close = (ImageView) dialog.findViewById(R.id.ivClose);
            close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            dialog.show();
        }

    });

    ll1 = (LinearLayout) findViewById(R.id.ll1);
    ll2 = (LinearLayout) findViewById(R.id.ll2);
    ll3 = (LinearLayout) findViewById(R.id.ll3);
    ll4 = (LinearLayout) findViewById(R.id.ll4);
    ll5 = (LinearLayout) findViewById(R.id.ll5);
    ll6 = (LinearLayout) findViewById(R.id.ll6);
    ll1.setBackgroundColor(getResources().getColor(R.color.White));

    llPickSchools = (LinearLayout) findViewById(R.id.llPickSchool);
    llDrills = (LinearLayout) findViewById(R.id.llDrills);
    llServiceCalls = (LinearLayout) findViewById(R.id.llServiceCalls);
    llNewInstalls = (LinearLayout) findViewById(R.id.llNewInstalls);
    llPendingUploads = (LinearLayout) findViewById(R.id.llPendingUploads);

    frameLayout = (FrameLayout) findViewById(R.id.frame);

}