选择java的应用程序_java – 如何让我的应用程序出现在app chooser中?

我想宣传我的应用程序能够查看pdf文件,以便在从文件管理器中选择pdf文件时它将显示在应用程序选择器中.

这是我的意图过滤器的样子

android:name=".MainActivity"

android:label="@string/app_name">

每当我从文件管理器打开pdf时,它会自动选择另一个名为Polaris Viewer的pdf应用程序.

我在应用程序设置下检查以确保Polaris不是默认应用程序.它说没有设置默认值.

此外,我下载了一个名为Intent Intercept的第三方应用程序.如果我从文件管理器中选择一个pdf文件,则会出现一个应用程序选择器,显示Polaris和Intent Intercept.如果我选择Intent Intercept,它会告诉我Polaris和我的app(Rollout PdfEditor)都符合意图.这是Intent Interceptor的输出:

ACTION: android.intent.action.VIEW

DATA: file:///storage/sdcard0/Download/download.pdf

TYPE: application/pdf

FLAGS:

FLAG_ACTIVITY_FORWARD_RESULT

FLAG_ACTIVITY_PREVIOUS_IS_TOP

EXTRAS:

EXTRA 1:

Class: java.lang.Boolean

Key: preview

Value: false

EXTRA 2:

Class: java.lang.String

Key: key_filename

Value: /storage/sdcard0/Download/download.pdf

EXTRA 3:

Class: android.net.Uri$HierarchicalUri

Key: android.intent.extra.STREAM

EXTRA 4:

Class: java.lang.Integer

Key: sort_order

Value: 0

2 ACTIVITIES MATCH THIS INTENT:

Polaris Viewer 4.1 (com.infraware.polarisviewer4 – com.infraware.polarisoffice4.OfficeLauncherActivity)

Rollout PdfEditor (com.example.rolloutpdfeditor – com.example.rolloutpdfeditor.MainActivity) >

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用以下代码实现在Java Swing弹出窗口并在TextArea显示文件内容的功能: ```java import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; public class FileViewer extends JFrame implements ActionListener { private JButton openButton; private JTextArea textArea; public FileViewer() { super("File Viewer"); // Create components openButton = new JButton("Open"); openButton.addActionListener(this); textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); // Add components to content pane Container contentPane = getContentPane(); contentPane.add(openButton, BorderLayout.NORTH); contentPane.add(scrollPane, BorderLayout.CENTER); // Set window properties setSize(400, 300); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[] args) { // Create and show window FileViewer fileViewer = new FileViewer(); fileViewer.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == openButton) { // Create file chooser dialog JFileChooser fileChooser = new JFileChooser(); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { // Get selected file File file = fileChooser.getSelectedFile(); try { // Read file contents BufferedReader reader = new BufferedReader(new FileReader(file)); String line; StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line); sb.append(System.lineSeparator()); } reader.close(); // Set text area contents textArea.setText(sb.toString()); } catch (Exception ex) { ex.printStackTrace(); } } } } } ``` 这段代码会创建一个名为 "File Viewer" 的窗口,其包含一个 "Open" 按钮和一个文本区域。当用户点击 "Open" 按钮时,会弹出一个文件选择器对话框,用户可以选择要读取的文件。然后,程序会读取文件内容并将其显示在文本区域

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值