opening sdcard gallery album directory - android

Hi I am making the button which opens gallery(Default)album in sd card
putting following funtion to the button
But i don't understand why this funtion makes whole application stops...
public void goTopAlbum(View v){
Toast.makeText(MainActivity.this, "Let's open gallery!", Toast.LENGTH_SHORT).show();
Intent mIntent = new Intent(getIntent().ACTION_VIEW, Uri.parse("file:///sdcard/image/Album1"));
//dataType name = new dataType
startActivity(mIntent);
}

getIntent().ACTION_VIEW
Change to
Intent.ACTION_VIEW

Related

attach multiple as well as single file on button click in android

It might be a very simple question for some of you. I have a button, on click of which I can attach single or multiple file and I am accessing the file paths in OnActivityResult(). Using (Intent.EXTRA_ALLOW_MULTIPLE, true) has let me attach multiple files now. The issue is now I can't select a single file if I want to and have to always select multiple files for the opperation. I am not doing it for sending a mail. Its a simple process of selecting some files and based on the selection, get the corresponding data from the SD card and upload.
Below I am posting my code for opening the browser and attach files :
txtv_attach.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
chooseFile.putExtra(Intent.EXTRA_STREAM, uri);
chooseFile.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
chooseFile.setType("*/*");
chooseFile = Intent.createChooser(chooseFile, "Choose a file");
startActivityForResult(chooseFile, PICKFILE_RESULT_CODE);
}
});
Is there any way I can attach both single as well as multiple files? need your help. Thanks in advance.

startActivity does not work after passing data from current activity into new intent

public void DoneBtnClicked(View v) {
if (mCameraData != null) {
Intent intent = new Intent(this,ShowResultCamActivity.class);
intent.putExtra("jmxs.utrack.camera_data",mCameraData);
startActivity(intent);
} else {
Toast.makeText(CameraActivity.this, "No Camera Data.", Toast.LENGTH_SHORT)
.show();
setResult(RESULT_CANCELED);
finish();
}
}
Hi, Im creating a camera app and in the code above is a fuction that is called after an image is taken and I want to pass that image to a new activity to process it.
mCameraData is byte[].
Problem: startActivity(intent); doesnt work.
Tried: I can pass an INT and it works but when i tried to pass byteArray or bitmap it doesnt.
Is it because of the size?
Yes, there is a limit to the size of data that can be passed through an intent. The limit is roughly 500Kb - most photographs will be larger than this.
Consider saving your image to a file location, passing the URI to the receiving activity and loading it within there.

android show image in default gallery viewer

I am loading some images into my activity using an AsyncTask as clickable images. On click I need to open that image in the default image viewer of the android. I am new to android. Can any one please help. My code looks like
ImageView image = new ImageView(this);
String ed="http://www.domain.com/image.jpg";
image.setTag(ed);
DownloadImagesTask td=new DownloadImagesTask(this);
td.execute(image);
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.v("TAGG","sdsd");
}
});
Please help me.
Gallery application does not accept URL for an image as part of the Intent. You need to save the image first. Then you can launch the default image viewer with something like this:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);

PDF viewer in online(Internet conectivity) as well as offline mode

The PDF content can be of online as well as offline mode, I need to show pdf in my own customized layout so, Intent can't be used. Any suggestion will be appreciated. thank you.
Yes we are able to show pdf content onLine with the help of google doc api Here i am given code for using it. for ON Line Mode
public class ReaderActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webView=(WebView)this.findViewById(R.id.WebView01);
Intent intent = new Intent(Intent.ACTION_VIEW);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setPluginsEnabled(true);
webView.loadUrl("https://docs.google.com/viewer?url=http%3A%2F%2Fwww.eli.sdsu.edu%2Fcourses%2Ffall09%2Fcs696%2Fnotes%2FAndroid13Web.pdf");
//intent.setDataAndType(Uri.parse("https://docs.google.com/viewer?url=---------Your URL");
}}
for OFF Line Mode
File file = new File(mRealPath);
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, getString(R.string.application_type));
try
{
startActivity(intent);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(FirstTab.this,
getString(R.string.no_application_found),
Toast.LENGTH_SHORT).show();
}
Note-:In off line mode first you have download file form server to own local device in sd-card the get path of this document and put it on in the place of path variable then you get answer of your hole question.
In this code you should use your url in the place my url.
I hope this is help.
First of there is no support for pdf in Android so you need to open in some other app like adob or if you want to do it right way then need make the load lib like vudroid and apdfviewer .
apdfviewer is very good but there is no support how to compile source code, actually all lib work with c++ in backend so you need to install the ndk.
Vudroid is slow but you can compile easily.
I hope this will help you.
But
Some phones (like the Nexus One) come with a version of Quickoffice pre-installed so it may be as easy as sending the appropriate Intent once you've saved the file to the SD card.
public class OpenPdf extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.OpenPdfButton);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
File file = new File("/sdcard/example.pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(OpenPdf.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
}
});
}
}
I found that Internet connectivity mode :- through google doc we can open the pdf.
but in the Internet offline mode:- we need to use Intent and open the pdf file through any one of the pdf viewer application install in the device.
one things we can do in the offline mode is that, instead of opening the option of multiple pdf viewer reader in device and select one application to open pdf file we can open the pdf with the particular application.

Open PDF in android app

I am working on an application where need to open the pdf file in the device,
I have actually got the code on the web that is similar to most of the examples. But, the thing is that I am not able to open the file and the control goes to the "Exception" part directly.
Here is the code below:
public class MyPDFDemo extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button OpenPDF = (Button) findViewById(R.id.button);
OpenPDF.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
File pdfFile = new File("/sdcard/Determine_RGB_Codes_With_Powerpoint [PDF Library].pdf");
if(pdfFile.exists())
{
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(pdfIntent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(MyPDFDemo.this, "No Application available to view pdf", Toast.LENGTH_LONG).show();
}
}
}
});
}
When I run this code : i used to see " No Application available to view pdf ". Can anyone please me to view the pdf file.
Since your catch block has ActivityNotFoundException, it means that you don't have any activity/application that can read a 'application/pdf' filetype format. Install any pdf viewer from the Android Market (Adobe recently release theirs), or else use the above mentioned open source pdf viewer and your problem will most probably will be solved.
http://code.google.com/p/apv/downloads/list
https://market.android.com/details?id=cx.hell.android.pdfview&feature=search_result
When you start activity with your given params, it searches for all applications/Activities/Intents that are registered to open pdf format. Since you have none in your device, you are getting the ActivityNotFoundException
First install the pdf reader on device.
than use this code for reading pdf file from internal memory.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final TextView tv = (TextView)findViewById(R.id.tv);
Button bt=(Button)findViewById(R.id.openbtn);
bt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
File pdfFile = new File(Environment.getExternalStorageDirectory(),"Leave.pdf");
if(pdfFile.exists())
{
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try{
startActivity(pdfIntent);
}catch(ActivityNotFoundException e){
tv.setText("No Application available to view PDF");
}
}
else
{
tv.setText("File not found");
}
}
});
}
Your code is right, I have also used same code to open pdf file within a viewer.
As you don't have a viewer installed to your device so it can't open without any viewer.
You can install Adobe reader for Android.
I can't open pdf file within emulator, so I have to test using my device.

Categories

Resources