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);
Related
I have two apps one is android java app and other is unity app
Unity app recognize the object and shows some details. What i want to do is if user clicks the button which is shown when the object is identified, i want to send that information to the java android app so that the app can use that data to perform certain functions. How can i send the data and switch from unity to java android app after user clicks the button?
EDIT: For any one looking for the answer. I manage to do it by the code below
IN UNITY APP:
public void LaunchAppMessage()
{
string bundleId = "com.example.sidenavtest";
bool fail = false;
string message = "message";
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaObject launchIntent = null;
try
{
launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
launchIntent.Call<AndroidJavaObject>("putExtra", "arguments", message);
}
catch (System.Exception e)
{
fail = true;
}
if (fail)
{
Application.OpenURL("https://google.com");
}
else
{
ca.Call("startActivity", launchIntent);
}
up.Dispose();
ca.Dispose();
packageManager.Dispose();
launchIntent.Dispose();
}
IN ANDROID APP
#Override
protected void onStart() {
super.onStart();
Bundle extras = getIntent().getExtras();
String userName;
if (extras != null) {
userName = extras.getString("arguments");
}
}
If i understand you correctly you want to have both applications on the same device.
Simplest way would be to save the data ino a file in the unity application and read from that file in the android application. But i think you can even attach data on application calls so that you dont even need to save it temporarily.
Opening the Android app from Unity is possible aswell. Here someone asked the same question and got some working answer.
Edit: From what i can gather you can transfer your data via intents, it seem's like most people work with JAR-Plugin from where you can make a intent call.
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.
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);
I am just starting off with Google Web Toolkit, coming from programming in Android. Since it's all java(ish) I expected it to be similar. In my app I have an entrypoint where the user will upload an excel file and hit submit. After they hit submit they should be taken to a new page where I will be displaying some information from the excel that they just uploaded.
In Android it would look something like
myAndroidBTN.setOnClickListener (new OnClickListener() {
public void onClick(View v) {
try {
final Intent myIntent = new Intent(this, NextClass.class));
startActivity(myIntent);
} catch (Exception e) { }
}
In the GWT App I have
Button btnSubmit = new Button("Submit");
btnSubmit.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
}
});
Documentation for GWT is doesn't seem to be anywhere near what it is for android so I can't find the right way to open a new java file. How should this be done?
EDIT
Some of you have miss-interpreted my question. I don't want to imply that I can build the equivalent of an android app in a browser with GWT, I just wanted to see the equivalent of an OnClick event taking you to a new page/section.
Look at Activities and Places.
https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces
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.