pdf 뷰어 앱을 하나 만들고 있습니다.
앱에서 pdf 파일을 찾아 여는 건 문제가 없는데, 반대로 pdf 파일을 눌러 "사용할 애플리케이션" 목록에서 제 앱을 실행하면 해당 파일이 열리도록 하는 것이 잘 되지 않네요.
아래는 sd카드에 저장된 pdf 파일을 목록으로 보여주는 MainActivity.java 파일의 일부입니다.
private void init() {
lv_pdf = (ListView)findViewById(R.id.lv_pdf);
dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
fn_permission();
lv_pdf.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(MainActivity.this, PdfActivity.class);
intent.putExtra("position", i);
startActivity(intent);
Log.e("Position", i + "");
}
});
}
init()의 setOnTimeClickListener() 메소드 내에서 pdf 파일 목록 중 하나를 클릭하면, 그 데이터가 PdfActivity.java 파일로 전송되도록 하였습니다.(position은 파일의 위치 값입니다)
아래는 클릭한 pdf 파일의 내용을 표시하는 PdfActivity.java 파일의 일부입니다.
private void init() {
Intent intent = getIntent();
pdfView = (PDFView)findViewById(R.id.pdfView);
position = intent.getIntExtra("position",-1);
displayFromSdcard();
}
위의 MainActivity.java 파일에서 전송한 데이터를 이곳의 getIntent()가 받습니다.
문제는 이게 앱에서 파일에 접근했을 때를 기준으로 만들다 보니 파일에서 앱으로 접근할 때는 어떻게 해야 할지 모르겠다는 점입니다. 인터넷을 찾아보니 "사용할 애플리케이션 목록"에 앱을 띄울 때는 보통
Intent intent = new Intent(Intent.ACTION_VIEW);
이렇게 선언한 다음 manifest 파일에서
action android:name="android.intent.action.VIEW"
로 처리하더라구요. 그런데 저는 ACTION_VIEW를 사용하지 않았기 때문에 어떻게 해야 할지 모르겠습니다.
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
PdfActivity.java가 받은 데이터를 가지고 pdf 파일 내용을 출력하는 xml 파일입니다. 제가 pdf 뷰어의 기본적인 기능은 외부 라이브러리에서 가져왔기 때문에 위와 같이 GitHub의 주소를 사용하고 있습니다.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pdffilefromsdcard">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".PdfActivity"
android:screenOrientation="portrait"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.pdffilefromsdcard.MainActivity" />
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
</activity>
</application>
</manifest>
이렇게 라이브러리 주소를 이용해 manifest 파일을 작성했는데 pdf 파일을 눌렀을 때 나오는 "사용할 애플리케이션" 목록에는 제 앱이 전혀 뜨지 않습니다.
해결 방법 좀 부탁드리겠습니다.