#Androdi training# interactions with activities or apps

本文详细介绍了 Android 中 Intent 的使用方法,包括显式 Intent 和隐式 Intent 的创建与启动方式,如何通过 Intent 发送电子邮件、创建日历事件等高级用法。此外还探讨了如何接收从其他 Activity 返回的数据,并解释了如何配置 Activity 以便其他应用可以调用。

一  to Other's Apps

explicit intent

Intent mIntent = new Intent();
mIntent.setClass(this,MainConversationActivity.class);
startActivity(mIntent);

implicit intent

call:

Uri number = Uri.parse("tel:5551234");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);

map:

// Map point based on address
Uri location = Uri.parse("geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+California");
// Or map point based on latitude/longitude
// Uri location = Uri.parse("geo:37.422219,-122.08364?z=14"); // z param is zoom level
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);


view a page

Uri webpage = Uri.parse("http://www.android.com");
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);


tips:

1.you can add more data through putExtra()

2.if you don't include a Uri in the intent, you should usually use setType() to specify the type of data

associated with the intent.

send an email with an attachment

Intent emailIntent = new Intent(Intent.ACTION_SEND);
// The intent does not have a URI, so declare the "text/plain" MIME type
emailIntent.setType(HTTP.PLAIN_TEXT_TYPE);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"jon@example.com"}); // recipients
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message text");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://path/to/email/attachment"));
// You can also attach multiple items by passing an ArrayList of Uris


create a calendar event

Intent calendarIntent = new Intent(Intent.ACTION_INSERT, Events.CONTENT_URI);
Calendar beginTime = Calendar.getInstance().set(2012, 0, 19, 7, 30);
Calendar endTime = Calendar.getInstance().set(2012, 0, 19, 10, 30);
calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis());
calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis());
calendarIntent.putExtra(Events.TITLE, "Ninja class");
calendarIntent.putExtra(Events.EVENT_LOCATION, "Secret dojo");

3.you may need to verify if there is an app to receive the intent

PackageManager packageManager = getPackageManager();
List activities = packageManager.queryIntentActivities(intent,
        PackageManager.MATCH_DEFAULT_ONLY);
boolean isIntentSafe = activities.size() > 0;
if(isIntentSafe){ startActivity(mapIntent);}


4. show the chooser

Intent intent = new Intent(Intent.ACTION_SEND);
...

// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show chooser
Intent chooser = Intent.createChooser(intent, title);

// Verify the intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(chooser);
}

二  getting a Result from an Activity

startActivityForResult()

onActivityResult()

static final int PICK_CONTACT_REQUEST = 1;  // The request code. Later, you app can properly identify the result and determine how to handle it.
...
private void pickContact() {
    Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
    pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
    startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == PICK_CONTACT_REQUEST) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            // The user picked a contact.
            // The Intent's data Uri identifies which contact was selected.

            // Do something with the contact here (bigger example below)
        }
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request it is that we're responding to
    if (requestCode == PICK_CONTACT_REQUEST) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            // Get the URI that points to the selected contact
            Uri contactUri = data.getData();
            // We only need the NUMBER column, because there will be only one row in the result
            String[] projection = {Phone.NUMBER};

            // Perform the query on the contact to get the NUMBER column
            // We don't need a selection or sort order (there's only one result for the given URI)
            // CAUTION: The query() method should be called from a separate thread to avoid blocking
            // your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
            // Consider using CursorLoader to perform the query.
            Cursor cursor = getContentResolver()
                    .query(contactUri, projection, null, null, null);
            cursor.moveToFirst();

            // Retrieve the phone number from the NUMBER column
            int column = cursor.getColumnIndex(Phone.NUMBER);
            String number = cursor.getString(column);

            // Do something with the phone number...
        }
    }
}

三 allwoing other apps to start your activity

<intent-filter>

Action:<action>

ACTION_SEND

ACTION_VIEW


Data:<data>

A description of the data associated with the intent.

you can specify the MIME type

Note: if you don't need to declare specifics about data Uri(such as when your activity handles to other kind of "extra")

 data, instead of a Uri), you should specify only the android:mimeType attribute to declare the type of data, such as text/plain or image/jpeg

Category:<category>

rarely used.

<activity android:name="ShareActivity">
    <intent-filter>
        <action android:name="android.intent.action.SEND"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:mimeType="text/plain"/>
        <data android:mimeType="image/*"/>
    </intent-filter>
</activity>

<activity android:name="ShareActivity">
    <!-- filter for sending text; accepts SENDTO action with sms URI schemes -->
    <intent-filter>
        <action android:name="android.intent.action.SENDTO"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="sms" />
        <data android:scheme="smsto" />
    </intent-filter>
    <!-- filter for sending text or images; accepts SEND action and text or image data -->
    <intent-filter>
        <action android:name="android.intent.action.SEND"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:mimeType="image/*"/>
        <data android:mimeType="text/plain"/>
    </intent-filter>
</activity>


handle the Intent

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

    setContentView(R.layout.main);

    // Get the intent that started this activity
    Intent intent = getIntent();
    Uri data = intent.getData();

    // Figure out what to do based on the intent type
    if (intent.getType().indexOf("image/") != -1) {
        // Handle intents with image data ...
    } else if (intent.getType().equals("text/plain")) {
        // Handle intents with text ...
    }
}

return a result

when your operation is done and the user should returen original activity, call finish() to close (and destroy) your activity.

Intent result = new Intent("com.example.RESULT_ACTION", Uri.parse("content://result_uri"));
setResult(Activity.RESULT_OK, result);
finish();


the default is RESULT_CANCELED.

setResult(RESULT_COLOR_RED);
finish();

the intent is not necessary.



















AlphaFold 3(AF3)在生物分子相互作用结构预测中的应用,标志着深度学习技术在分子生物学领域的一次重大突破。AF3通过整合多种数据源和算法优化,在统一框架下实现了对广泛生物分子系统结构的精准预测,包括蛋白质-配体、蛋白质-抗体以及跨实体的复杂相互作用。 AF3模型的一个关键创新在于其能够在缺乏传统进化信息(如多序列比对MSA)的情况下,依然保持高精度的预测能力。这一特性表明,AlphaFold衍生的方法不仅能够模拟分子间相互作用的化学和物理特性,而且不受限于传统的依赖MSA的数据处理方式。这种能力对于理解生物系统中复杂的原子相互作用至关重要[^1]。 此外,AF3在蛋白质-配体结构预测方面的显著改进,进一步证明了其在药物发现领域的巨大潜力。准确预测蛋白质配体结构的能力,使得科学家能够更有效地识别和设计可能成为药物的新分子。这种改进不仅提高了预测的实用性,还拓宽了AlphaFold系列模型的应用范围,使其能够处理化学空间的广泛多样性[^2]。 为了进一步丰富AlphaFold数据库中的模型,AlphaFill项目应运而生。AlphaFill通过学习已知实验结构中小分子和离子的相关结合信息,并通过移植在同源蛋白质结构中实验观察到的小分子和离子的信息来增强AlphaFold数据库中的模型。基于2022年2月的AlphaFold数据库,AlphaFill成功地在995,411个AlphaFold预测模型中,为586,137个模型添加了至少一个可移植化合物,总共有12,029,789个化合物被移植到这些模型中。这一成果极大地丰富了AlphaFold数据库的内容,为研究者提供了更加详尽的生物分子互作信息[^3]。 ### 示例代码 以下是一个简化的示例,展示如何使用AlphaFold 3进行生物分子相互作用结构预测的基本步骤: ```python # 导入必要的库 from alphafold3 import AlphaFold3Predictor # 初始化AlphaFold3预测器 predictor = AlphaFold3Predictor() # 定义输入文件路径 input_protein_sequence = "path/to/protein_sequence.fasta" input_ligand_smiles = "path/to/ligand_smiles.smi" # 加载蛋白质序列和配体SMILES字符串 protein_sequence = predictor.load_sequence(input_protein_sequence) ligand_smiles = predictor.load_smiles(input_ligand_smiles) # 进行结构预测 predicted_structure = predictor.predict_structure(protein_sequence, ligand_smiles) # 保存预测结果 output_file = "path/to/predicted_structure.pdb" predictor.save_structure(predicted_structure, output_file) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值