gpt4 book ai didi

Android 短信 Intent 过滤器

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:10:13 26 4
gpt4 key购买 nike

我在我的 android 应用程序中尝试了这段代码来获取 SMS 消息,但它不起作用,该应用程序没有出现在消息列表中。我应该添加一些东西来让它工作吗?

             <action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:mimeType="text/plain" />

</intent-filter>

最佳答案

我正在为您提供在不同情况下执行此操作的详细说明(包括联系人、文本共享等)。

消息 Activity 的 list 条目

<!-- Defines also the app name in the Android menu -->
<activity
android:name="it.rainbowbreeze.smsforfree.ui.ActSendSms"
android:label="@string/common_appName"
>
<!-- Sends sms for someone -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>

<!-- Sends text to someone .This will enable any Text Share functionality-->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

现在我们已经制作了一个processIntentData方法,如下所示,应用在Message Activity中:

private void processIntentData(Intent intent)
{
if (null == intent) return;

if (Intent.ACTION_SENDTO.equals(intent.getAction())) {
//in the data i'll find the number of the destination
String destionationNumber = intent.getDataString();
destionationNumber = URLDecoder.decode(destionationNumber);
//clear the string
destionationNumber = destionationNumber.replace("-", "")
.replace("smsto:", "")
.replace("sms:", "");
//and set fields
mTxtDestination.setText(destionationNumber);

} else if (Intent.ACTION_SEND.equals(intent.getAction()) && "text/plain".equals(intent.getType())) {
//in the data i'll find the content of the message
String message = intent.getStringExtra(Intent.EXTRA_TEXT);
//clear the string
mTxtBody.setText(message);
}
}

如消息 Activity 所示使用:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

...

mTxtDestination = (EditText) findViewById(R.id.actsendsms_txtDestination);
mTxtBody = (EditText) findViewById(R.id.actsendsms_txtMessage);

...

//executed when the application first runs
if (null == savedInstanceState) {
processIntentData(getIntent());
}
}

随附的结果截图: enter image description here

关于Android 短信 Intent 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8847876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com