I am trying to create an Android app to open a PDF file. The goal is to be able to email them and sign them digitally. I'm just looking to open the file by pressing a button.
The application starts but I get the following error:
The application "PdfSigner" has stopped unexpectedly. please try again
activitymain.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".PdfActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="168dp"
android:text="@string/Ouvrir" />
</RelativeLayout>
Activity.java :
package com.example.pdfsigner;
import ltm.test.R;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class PdfActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitymain);
//
Button b1 = (Button)findViewById( R.id.button1 );
b1.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View arg0) {
String surl = "/ENGLISH.pdf";
String apptype = "application/pdf";
if( openURLWithType( surl, apptype ) == false)
Toast.makeText( PdfActivity.this,
"Echec de Open URL", Toast.LENGTH_LONG ).show();
}});
}
public boolean openURLWithType( String url, String type ) {
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/R.raw.ENGLISH");
Intent intent = new Intent( Intent.ACTION_VIEW, uri );
intent.setDataAndType( uri, type );
intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP );
try {
PdfActivity.this.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
Log.e( "LTM" ,"Activity not found: " + url, e);
}
return false;
}
}
Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ltm.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity android:name=".PdfActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
any help or criticism will be welcome