-2

i wrote code witch can to open pdf file in sdcard.but My question is there any possiblities to view Pdf files in own Layout using Xml files not static into Java files this is a my code

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button button = (Button) findViewById(R.id.button1);

    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            File pdfFile = new File(Environment
                    .getExternalStorageDirectory(), "test.pdf");

            try {
                if (pdfFile.exists()) {
                    Uri path = Uri.fromFile(pdfFile);
                    Intent objIntent = new Intent(Intent.ACTION_VIEW);
                    objIntent.setDataAndType(path, "application/pdf");
                    objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(objIntent);
                } else {
                    Toast.makeText(MainActivity.this, "File NotFound",
                            Toast.LENGTH_SHORT).show();
                }
            } catch (ActivityNotFoundException e) {
                Toast.makeText(MainActivity.this,
                        "No Viewer Application Found", Toast.LENGTH_SHORT)
                        .show();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

}

}

and also i have second question 2) when i run project on my device i have like this screen (

enter image description here) when i click menu button on my device then i can to show setting menu it is a possible to create my own menu.for example i want to create my button witch can to zoom same as a static menu's zoom button thanks

Sandeep R
  • 2,284
  • 3
  • 25
  • 51

1 Answers1

0
use webview in different layout in  our application like this::---->


webview.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/buttonUrl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Go to http://www.google.com" />

</LinearLayout>


mainactivity.java 

public class MainActivity extends Activity {

    private Button button;

    public void onCreate(Bundle savedInstanceState) {
        final Context context = this;

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        button = (Button) findViewById(R.id.buttonUrl);

        button.setOnClickListener(new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            Intent intent = new Intent(context, WebViewActivity.class);
                    intent.putExtra("url","www.google.com")
            startActivity(intent);
          }

        });

    }

}


webviewactivity.java

public class WebViewActivity extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        webView = (WebView) findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);
                if (getIntent().hasExtra("url")) {
                    webView.loadUrl("http://www.google.com");
                }


    }

}
Dakshesh Khatri
  • 639
  • 7
  • 12