How to open and show phone's message inbox programmatically..?

江枫思渺然 提交于 2019-12-11 12:46:39

问题


When we click on messages we are showed with the inbox.

I want to show the same window when i clicked on my application's button.

So, I want to start message inbox activity.

How to achieve this...?

Thanks in advance...!


回答1:


Try this.. works perfectly..!

public void openInbox() {
String application_name = "com.android.mms";
try {
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");

intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
List<ResolveInfo> resolveinfo_list = this.getPackageManager()
.queryIntentActivities(intent, 0);

for (ResolveInfo info : resolveinfo_list) {
if (info.activityInfo.packageName
.equalsIgnoreCase(application_name)) {
launchComponent(info.activityInfo.packageName,
info.activityInfo.name);
break;
}
}
} catch (ActivityNotFoundException e) {
Toast.makeText(
this.getApplicationContext(),
"There was a problem loading the application: "
+ application_name, Toast.LENGTH_SHORT).show();
}
}

private void launchComponent(String packageName, String name) {
Intent launch_intent = new Intent("android.intent.action.MAIN");
launch_intent.addCategory("android.intent.category.LAUNCHER");
launch_intent.setComponent(new ComponentName(packageName, name));
launch_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(launch_intent);
}



回答2:


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

        Intent defineIntent = new Intent(Intent.ACTION_MAIN);                

        defineIntent.setType(SMS_MIME_TYPE);                

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 , defineIntent, 0);

Not sure whether it works or not




回答3:


SMS content provider will give you the all sms related data . the Screen you are talking about is implemented by manufacturer using that data . so you have two choices to achieve this :

1) Use cursor returned by related content provider and create your own screen with desired look and feel .

2) get Information about package name of message screen for diffrent manufacures (like suppose samsung have com.samsung.smsscreeen ) and lauch intent for this class name . write case statements for devices you want to add.




回答4:


I extended srinivasa's solution above to get the package name of the default SMS app currently being used on the device:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        application_name = Telephony.Sms.getDefaultSmsPackage(this);
    }

I found this worked well across Samsung and Nokia devices which both use a different app for SMS out of the box.



来源:https://stackoverflow.com/questions/8711940/how-to-open-and-show-phones-message-inbox-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!