android 获取默认短信,如何在android中获取默认的短信,图库,通话,联系人和浏览器应用程序和包名?...

您可以使用此代码来获取Intent这些事情。其中有一个是SMS。

短信:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(ctx);

Intent lunchIntent;

if (defaultSmsPackageName != null) {

launchIntent = pm.getLaunchIntentForPackage(defaultSmsPackageName);

} else {

String SMS_MIME_TYPE = "vnd.android-dir/mms-sms";

launchIntent = new Intent(Intent.ACTION_MAIN);

launchIntent.setType(SMS_MIME_TYPE);

}

} else {

String SMS_MIME_TYPE = "vnd.android-dir/mms-sms";

launchIntent = new Intent(Intent.ACTION_MAIN);

launchIntent.setType(SMS_MIME_TYPE);

}

对于呼叫:

Intent intent = new Intent(Intent.ACTION_DIAL);

对于浏览器:

Intent intent;

Intent queryIntent = new Intent(Intent.ACTION_VIEW,

Uri.parse("http://www.google.com"));

ActivityInfo af = queryIntent.resolveActivityInfo(pm, 0);

intent = new Intent(Intent.ACTION_MAIN);

intent.setClassName(af.packageName, af.name);

对于照片:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"));

try {

context.startActivity(intent);

} catch (ActivityNotFoundException eee){

try {

intent = new Intent(Intent.ACTION_VIEW);

intent.setType(android.provider.MediaStore.Images.Media.CONTENT_TYPE);

} catch (Exception err){

Toast.makeText(context, "This app not supported in your device", Toast.LENGTH_LONG).show();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
获取其他程序窗口,可以使用Java AWT或Java Swing的Robot类。Robot类提供了一些方法,例如createScreenCapture和getPixelColor,可以用来捕捉屏幕和像素颜色。使用这些方法,可以捕捉其他程序的窗口并从提取信息。 以下是使用Robot类捕捉屏幕的示例代码: ``` import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; public class ScreenCapture { public static void main(String[] args) throws Exception { Robot robot = new Robot(); Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage screenCapture = robot.createScreenCapture(screenRect); // 处理图像 } } ``` 要引用UI使用在Android的其他应用程序权限,可以使用AccessibilityService。AccessibilityService是一种服务,可以允许您访问其他应用程序的界面元素和事件。您可以使用它来模拟用户操作,如点击和滑动。以下是使用AccessibilityService获取TextView的示例代码: ``` public class MyAccessibilityService extends AccessibilityService { @Override public void onAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) { AccessibilityNodeInfo nodeInfo = event.getSource(); if (nodeInfo != null && "android.widget.TextView".equals(nodeInfo.getClassName())) { String text = (String) nodeInfo.getText(); // 处理文本 } } } @Override public void onInterrupt() { // 断 } } ``` 在AndroidManifest.xml文件声明MyAccessibilityService: ``` <service android:name=".MyAccessibilityService" android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"> <meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice" /> </service> ``` 在res/xml文件夹创建accessibilityservice.xml文件: ``` <accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" android:accessibilityEventTypes="typeViewTextChanged" android:accessibilityFeedbackType="feedbackSpoken" android:notificationTimeout="100" android:packageNames="com.example.otherapp" android:settingsActivity=".SettingsActivity" /> ``` 其android:packageNames指定要访问的应用程序包名

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值