I'm new at Android apps and I'm working on a project started by a friend of mine. The code below is from a class that loads a view that has a small image with some text around it.
I want the image to appear fullscreen (on the standard Android image viewer) when I click on the thumbnail.
I tried several different solutions, and none of them worked.
This example throws the following exception:
E/AndroidRuntime(13768): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.app.mid/2130837533 typ=image/png }
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_n1);
ImageView img = (ImageView) findViewById(imageResource);
img.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("android.resource://com.app.mid/" + R.drawable.p_page_11_image_0001), "image/png");
startActivity(intent);
}
});
}
The images are inside the drawable folder (..\res\drawable-xhdpi). I'm using Eclipse ADT and I configured it to run on my Galaxy Nexus.
Again, I tried several solutions with no luck. Any thoughts?
Thanks
Try to use Intent.ACTION_VIEW instead of android.content.Intent.ACTION_VIEW
Intent i = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(yourUri, "image/png");
startActivity(intent);
Related
I have reviewed and tried numerous versions of this issue to no avail. I have seen answers as far back as 2011 and as recent as mid-year 2014. Unfortunately, the many partial answers and poorly explained suggestions have created more questions than answers. I have an Apple App available in the iTunes App Store that performs all that I am trying to do with this Android App. In the Apple App world viewing a pdf file is relatively easy to perform but I am having a very difficult time accomplishing it in Android. I admit that I am very limited in my experience at creating Android Apps.
The problem is that I have an Android App with a main activity that has a ListView that lists the titles for about 35 diagrams in pdf format. Each of these is clickable for viewing in a full screen activity (view). Each pdf is half page width and anywhere from 1/2 a page to two pages in length. So the new activity (pdf view) will need to be scrollable. Since this is an app for phones or pads the new activity (pdf view) needs to be zoomable. After the user completes their view of the pdf they will need an option to return to the main activity. The user can then select another diagram for viewing.
The things I have already accomplished are:
- ListView of diagram titles on main activity
- Listener enabled for each entry in ListView
- New activity (pdf view) is accessed
- Using putExtras - getExtras for variable passing, is working
Some code (from main activity.java):
#Override
public void onClick(View v) {
String scroll_page = new String("CommonVehicleCodeViolations.pdf");
Intent intent = new Intent(this, scroll_view.class);
intent.putExtra("extra_scroll_page", scroll_page);
startActivity(intent);
}
The diagram title is hard coded for testing purposes. Now, some code from the new activity (pdf view) 'scroll_view.java':
public class scroll_view extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scroll_view);
Bundle extras = getIntent().getExtras();
String scroll_page = null;
if (extras != null) {
scroll_page = extras.getString("extra_scroll_page");
}
int currentPage = 1;
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Bitmap bitmap = Bitmap.createBitmap(500,500, Bitmap.Config.ARGB_4444);
try {
File file = new File(getFilesDir(), scroll_page);
PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(file,ParcelFileDescriptor.MODE_READ_ONLY));
if(currentPage < 0) {
currentPage = 0;
} else if (currentPage > renderer.getPageCount()) {
currentPage = renderer.getPageCount() - 1;
}
renderer.openPage(currentPage).render(bitmap, new Rect(0, 0, 500, 500), new Matrix(),PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
imageView.setImageBitmap(bitmap);
imageView.invalidate();
} catch (IOException e) {
e.printStackTrace();
}
This was an attempt to use one of the many already posted answers which suggested using PdfRenderer. What I get from this example is the new activity (pdf view) blank screen. I am hoping that 2015 will bring new answers. Please help.
Why not try using an intent and let the system show you a list of compatible apps:
File file = new File(getFilesDir(), scroll_page);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
I am trying to make it so a user can select a gif in my app and send it through a text message. From what I have, you can click on a gif, then the app allows you to choose a messaging platform and starts a new message, but gives the error "Unable to attach. File not supported." and won't attach the gif to the text message. How should I go about fixing this?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View imageView, int position, long id) {
Toast.makeText(getApplicationContext(), "Pick a messenger!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_SEND);
File f = new File("/res/drawable/broke.gif");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
intent.setType("image/gif");
startActivity(Intent.createChooser(intent, "Send"));
}
});
}
broke.gif is the gif I have been trying to send while testing my program.
You have two problems.
First, as Gabe notes, fewer apps than you might expect will support GIF.
However, you have a bigger problem:
File f = new File("/res/drawable/broke.gif");
There is no /res/drawable/broke.gif on the Android device.
Presumably, you mean "the drawable in my project named broke.gif". Resources are files on your development machine. They are not files on the device. They are entries in the ZIP archive that is the APK file.
Sharing a drawable resource is at least theoretically possible, such as using my StreamProvider.
In my Android app, I have a button with the background image of an Amazon.com product (let's say a shirt or something), and when clicked I would like it to open in the Amazon app (com.amazon.mShop.android) if is already installed rather than in the browser, and in the browser if the app is not installed.
I have been able to find how to add a deep link to a specific Amazon client app, but not how to link to a specific item that would open with open with the Amazon app.
Currently, my click listener opens in a browser by doing the following:
b3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(urlOfItemOnAmazonSite));
startActivity(intent);
}
})
The Amazon developer's home page is probably the best place for this answer. This may be a good start: https://developer.amazon.com/public/apis/earn/in-app-purchasing/docs/deeplink#Link%20Configuration. Here they explain how to construct the Uri you'll need to use to set the Intent data.
Of course, you may want to be careful and wrap startActivity in a try/catch in case Amazon isn't installed and it throws an ActivityNotFoundException
You can simply do the following:
b3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Uri uri=Uri.parse(productUrl);
Intent intent=new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
})
//Note extract url of product store in var productUrl(or any other var) and //parse it.
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);
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.