Mohamad Amin Mohamad Amin - 2 months ago 6
Android Question

Using Android:tag() To locate file in asset

I want to use

android:tag
to locate file on asset how to do this? I cannot use double quotes.

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView9"
android:src="@drawable/sar90"
android:onClick="openpdf"
android:tag=""file:///android_asset/pdf/example.pdf""
android:layout_margin="20dp"
android:layout_gravity="center" />


To send path file to this method

public void openpdf(View v) {
String url2 = (String) v.getTag();
Intent i = new Intent(getApplicationContext(), PDF.class);
i.putExtra("key", url2);
startActivity(i);
}


and in
PDF.class
,

Bundle extras = getIntent().getExtras();
String url2 = extras.getString("key");
PDFView pdfView = (PDFView) findViewById(R.id.pdfView);
pdfView.fromAsset(url2).load();

Answer

Since URL is basically a string, you can put it into values/strings.xml file

<resources>
    <string name="myurl">http://something</string>
</resources>

 android:tag="@string/myurl"

That's it

Comments