Is there a way to open a PDF file with the click of a button.
The code I am using below downloads a PDF file from the web, it would be much easier if the PDF file was already on the app when it was download from the play store so the user doesn't have to download anything else.
I've already looked at this question and answer but i cannot make sense of it https://stackoverflow.com/review/suggested-edits/6350919 .
If its possible could you post an example as i am new to programming and find it difficult to make sense of what people are saying sometimes.
Thank you very much!
Here's my Code:
public class GreekHl extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_greek_hl);
Button ge1 = (Button) findViewById(R.id.ge1);
ge1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View arg0) {
String url1 = "http://www.examinations.ie/archive/exampapers/2014/JC007ALP000EV.pdf";
Intent ge1 = new Intent(Intent.ACTION_VIEW);
ge1.setData(Uri.parse(url1));
startActivity(ge1);
}
});
Button gm1 = (Button) findViewById(R.id.gm1);
gm1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View arg0) {
String url1 = "http://examinations.ie/archive/markingschem/2014/JC007ALP000EV.pdf";
Intent ge1 = new Intent(Intent.ACTION_VIEW);
ge1.setData(Uri.parse(url1));
startActivity(ge1);
}
});
ps Im quite new to the whole coding thing so i may be a bit slow!
I think you'll also want to go:
ge1.setType("application/pdf");
So that when you start the activity, it'll redirect to PDF viewers.
Related
Hello I'm starting in Android Studio and I wanted to know how to pass from one activity to another. I've tried different methods which I've seen in youtube tutorials but all of them show me the same error:
Cannot resolve symbol 'activity_menu'.
Does anyone know how to solve it?
Here is my code:
public class Menu extends AppCompatActivity {
Button boton_start;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
boton_start=(Button) findViewById(R.id.boton_menu);
boton_start.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent in = new Intent(activity_menu.this,activity_dishes.class);
startActivity(in);
}
});
}
}
The same happens with the other activity, but I suppose that the solution is the same for both.
You've mentioned the layout file names instead of name of the activities
Your code:
Intent in = new Intent(activity_menu.this,activity_dishes.class);
It should be:
Intent in = new Intent(Menu.this,Dishes.class);
Mention the name of the activity, not layout files.
Try getting activity_menu like this: R.layout.activity_menu
I am new to Android development and still trying to get the grasp of some of the concepts. I find the best way to learn is to jump right into the deep end with a project. With that said, here is my question:
I have integrated ZXing Android Embedded into my application; however, I am having trouble understanding the way in which you use IntentIntegrator. All I am trying to do at the moment is call the QR scanner to the screen when the user taps a button. I have been trying to follow the instructions on their github link [here][1] but have been unsuccessful.
Here is what my function looks like so far:
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
IntentIntegrator integrator = new IntentIntegrator(this);
IntentIntegrator.forFragment(this).initiateScan();
}
});
I keep getting an error saying:
Error:(109, 25) error: constructor IntentIntegrator in class
IntentIntegrator cannot be applied to given types; required: Activity
found: Intent reason: actual argument Intent cannot be converted to
Activity by method invocation conversion
Also, as I put my mouse over '(this)' in Android Studio, it says:
anonymous android.view.View.onClickListener
Any help would be greatly appreciated, thanks! If you need any other information, please let me know.
An even easier solution than ChrisStillwell´s would be to make your activity-/fragment-class implement the OnClickListener, this way you do not need the reference variable:
public class SomeFragment extends Fragment implements View.OnClickListener {
// Rest of your code
#Override
public void onClick(View v) {
if (v.getId == button.getId) {
IntentIntegrator integrator = new IntentIntegrator(getActivity());
IntentIntegrator.forFragment(this).initiateScan();
}
}
}
If you are implementing a fragment-class, note that you have to call getActivity() when creating the IntentIntegrator.
You are referencing your OnClickListener and not your Fragment when you say this inside your onClick. You need to reference your Fragment, the easiest way to do that is setup a global variable and call it myFragment or something to your liking, then assign it this. For example:
Fragment myFragment = this;
public void myFunction(){
// Code and stuff //
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
IntentIntegrator integrator = new IntentIntegrator(this);
IntentIntegrator.forFragment(myFragment).initiateScan();
}
});
}
following can work:
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new IntentIntegrator(getActivity()).initiateScan();
popupWindow.dismiss();
}
});
I am looking to access my website database and add a user to it through an edit text and onClick. i have most of the app finished. to do this from the pc is very easy as i just add the user number in the appropriate place in the URL and they are added to the database.
this is the URl with a user added
http://something.com/user/426561?token=dYG8hW5TY4LBU8jfPb10D3IcsSx8RTo6
I want to insert a number value where the 426561 is by using edit text. this is what i have so far and my websitethrows an invalid user number error which it is supposed to do.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edttext= (EditText)findViewById(R.id.editText1);
Button tutorial2 = (Button) findViewById(R.id.button1);
tutorial2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("edttext", edttext.getText().toString());
intent.setData(Uri.parse("http://something.com/user/= edttext?token=dYG8hW5TY4LBU8jfPb10D3IcsSx8RTo6"));
startActivity(intent);
}
});
I have added to the URL but obviously I am not doing it correctly. Any thoughts?
Use this. Putting extras does not replace data in intent
intent.setData(Uri.parse("http://example.com/user/"+edttext.getText() +"?token=dYG8hW5TY4LBU8jfPb10D3IcsSx8RTo6"));
My app targets API level 11 (3.0) or above. I want to utilise the Copy button from the Action Bar so that when TEXT is copied to Clipboard it will be sent to EditText of another activity and starts this activity.
Below is what I have done:
wvContent = (WebView) findViewById(R.id.wvContent);
wvContent.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ClipboardManager clipboardManager = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
final String text = clipboardManager.getText().toString();
if(text!=null)
{
Intent intent=new Intent(CurrentActivity.this,NewActivity.class);
intent.putExtra(have_word, text);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
finish();
CurrentActivity.this.startActivity(intent);
}
}
});
I place this code under onCreate, but it does not work. The text is copied but the NewActivity is not started.
I wonder whether you guys can provide me a little help to solve this problem. Many thanks.
Use ClipboardManager.getPrimaryClip() instead as getText() is depecreated. here you can find a nice example to use this to get clibpoard data.
So my question is simple if I use the WebView.destroy() in my app can I restore WebView to it's original state when the app was first initialize with out closing my app and opening it again? and how can I do this? I just want to be able to press a button and have this button rebuild my WebView and load a new url. I need to destroy it no just set it GONE or INVISIBLE.
Thanks
UPDATE:
Button rbesatbtn = (Button) findViewById(R.id.btnrbesa);
rbesatbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
wvr.destroy()
}
});
Button resttbtn = (Button) findViewById(R.id.btnrrest);
rrestbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
WebView wvr = new WebView(this);
setContentView(wvr);
wvr = (WebView) findViewById(R.id.wVradios);
wvr.getSettings().setJavaScriptEnabled(true);
wvr.getSettings().setPluginsEnabled(true);
wvr.setWebViewClient(new WebViewClient());
wvr.setInitialScale(1);
wvr.getSettings().setBuiltInZoomControls(true);
wvr.getSettings().setUseWideViewPort(true);
});
The documentation says:
Destroy the internal state of the WebView. This method should be called after the WebView has been removed from the view system. No other methods may be called on a WebView after destroy.
So I guess that the answer is no. However, you can always initialize a new one...