0
我有一些問題。我嘗試做一件事,當用戶按下按鈕時,PDF文件以PDF閱讀器打開。我把所有的東西寫在程序中,但它不起作用。問題是什麼?你能寫一個正確的代碼嗎?我竭盡全力。我的代碼:從PDF閱讀器中的原始文件夾打開pdf文件
package lt.sviesioji.kdainiviesiojigimnazija;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import java.io.File;
import java.io.InputStream;
/**
* A simple {@link Fragment} subclass.
*/
public class FormulynasFragment extends Fragment {
public FormulynasFragment() {
}
Button f;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
int backButtonCount = getFragmentManager().getBackStackEntryCount();
if (backButtonCount > 0) {
Fragment newFragment = new PagrindinisFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
transaction.commit();
}
final View rootView = inflater.inflate(R.layout.fragment_formulynas, container,
false);
f = (Button) rootView.findViewById(R.id.button69);
f.setOnClickListener(new View.OnClickListener() {
InputStream is = getResources().openRawResource(R.raw.matematika);
@Override
public void onClick(View v) {
startpdf();
}
private void startpdf() {
// TODO Auto-generated method stub
File file = new File("R.id.matematika");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
}
}
}
});
return rootView;
}
}
所以,我認爲將資源複製到實習生的文件al存儲更容易,也許你可以寫,我怎麼能在這個代碼上做到這一點? :) – iBoucher