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

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.

Related

opening sdcard gallery album directory

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

How to open a specific album or photo in facebook app using intent from your own Android App

How to open an album or photo in facebook app using intent from your own Android App?
I been searching for the specific answer for this one. Most question are about how to open a facebook page via intent.
I saw this one (regards to Sunny a Sr. Software engineer at iAppStreet) but it doesn't work.
public Intent getOpenFacebookIntent(String pId) {
try {
activity.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("facebook:/photos?album=0&photo=" + pId+"&user="+ownerId));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/"));
}
}
startActivity(getOpenFacebookIntent(pid));
thanks.
Actually i made this question to help those who have the same problem like me. As of today (28 March 2016) i just found out how to open an album using intent but i cannot open a photo using intent in the facebook app. I am a beginner in android programming so please bear with me.
I used a button to implement this. Here is the code:
Button buttonOpenALbum = (Button) findViewById(R.id.button);
buttonOpenALbum.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//It is a album from a facebook page # www.facebook.com/thinkingarmy
String albumID = "575146485903630";
String userID = "575145312570414";
String url = "facebook:/photos?album="+albumID+"&user="+userID;
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
If you want to get the albumID and userID of a facebook album try searching on google how or try this one if it helps, https://www.youtube.com/watch?v=sMEmlpmCHLc
Modifying the code to open a specific photo has not produce the expected result. Even though I included the photoID, you still end up in the album. Here is the code:
Button buttonOpenPhoto = (Button) findViewById(R.id.button);
buttonOpenPhoto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//It is a album from a facebook page # www.facebook.com/thinkingarmy
String albumID = "575146485903630";
String userID = "575145312570414";
String photoID = "803154029769540";
String url = "facebook:/photos?album="+albumID+"&photo="+photoID+"&user="+userID;
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
I can't be sure why. I tried looking but some say the urls of facebook is undocumented. If I may, I think you cannot open a specific photo because upon observation, facebook open a photo in full screen, meaning it is a different Activity than the Main Activity which handles the incoming Intent. The Main Activity of the facebook app only handles the intent up to opening a specific album.
I hope I can help other "new android coders" with my first post.
NB: I just learn coding using google and stackoverflow. It's my way of giving back. Thanks.
Launch a view intent with the following URL
https://www.facebook.com/photo.php?fbid={photo_id}
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
ctx.startActivity(browserIntent);
If the app is installed, it will prompt the user to open in app, otherwise it will use the browser
Some useful information at Open Facebook Page in Facebook App (if installed) on Android
In particular, new versions of facebook app work with
Uri.parse("fb://facewebmodal/f?href=" + FACEBOOKURL
I found this the simplest approach to acheive what was needed.
Note also that to get the URL you can go to the facebook album (on facebook desktop), click the three dots next to "Edit" and "Tag" and select "Get Link". I found this more reliable than simply copying the URL from the browser.

file chooser to choose folder (android)

i am using afilechooser for this purpose . and this is by default programmed to choose the items inside the folder and get you the path that is selected by the user.
but i want to use this as folder chooser where the user choose a location from internal memory of android device and then the app will save the file at that location.
so how do i do it.
the code i am using for this purpose is-
private void showChooser() {
// Use the GET_CONTENT intent from the utility class
Intent target = FileUtils.createGetContentIntent();
// Create the chooser Intent
Intent intent = Intent.createChooser(
target, getString(R.string.chooser_title));
try {
startActivityForResult(intent, REQUEST_CODE);
} catch (ActivityNotFoundException e) {
// The reason for the existence of aFileChooser
}
}
and i suspect the code can be changed to choose the folder instead of files. any suggestion can be helpful . please suggest if any other way to achieve what is want .
thank you
Looking at the github project in the url you posted, it doesn't look like this can be achieved. My claim is based on the following piece of code inside com.ipaulpro.afilechooser.FileChooserActivity class:
#Override
public void onFileSelected(File file) {
if (file != null) {
if (file.isDirectory()) {
replaceFragment(file);
} else {
finishWithResult(file);
}
} else {
Toast.makeText(FileChooserActivity.this, R.string.error_selecting_file,
Toast.LENGTH_SHORT).show();
}
}
just look at the if(file.isDirectory()) statement.

A link to vimeo application but

I have asked what is the code that sends a link from the application that I'm making to the vimeo application; it opens vimeo application but not the video specified in the link, does anybody knows how?
vimeo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
try{
Intent browserIntent = null;
PackageManager pmi = getPackageManager();
browserIntent = pmi.getLaunchIntentForPackage("com.vimeo.android.videoapp");
browserIntent.setAction(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("http://player.vimeo.com/video/83178705"));
startActivity(browserIntent);
}
catch(Exception e){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://player.vimeo.com/video/83178705"));
startActivity(browserIntent);
}
}
});
I answered your other question with this solution. But I believe it will fix this issue as well since our vimeo-deeplink library accommodates opening our specific application.
You could include it with gradle:
compile 'com.vimeo.android.deeplink:vimeo-deeplink:1.0.0'
And then deeplink to your video with this method:
boolean handled = VimeoDeeplink.showVideoWithUri(Context context, String videoUri)
Where videoUri is equal to /videos/83178705.
By doing this below, it will reset all your app preference
Go to Settings->Apps, choose from menu Reset app preferences and confirm Reset apps.
After that,
choose it in Settings->Apps and press Clear defaults button for vimeo app
Now try to open that video link(vimeo link) again. Now it'll ask you to select which app to use. Then select your vimeo app as default

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