• Android从一个应用启动另一个主界面隐藏图标的应用


    用a.apk启动b.apk,并且b的图标是在手机主界面上看不到的。

    如何做才能达到既能被主程序启动,又能隐藏起来呢?

    其实很简单,实现的方法是:在manifest的入口activity里面intent-filter中设置<data></data>元素

    步骤如下:

    一、新建a,b两个android项目(新建helloworld项目相似),在a项目中增加点击事件(启动按钮来启动b应用)。

        

    二、在b应用中修改b manifest.xml中<intent-filter>...</intent-filter>的内容就可以隐藏b应用的图标了。

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.rainwii.message"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="18" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.rainwii.message.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <!--这句可以注释掉,也可以留着;注释后,图标可以隐藏但是安装软件后不直接启动本应用-->
                   <!--  <category android:name="android.intent.category.LAUNCHER" /> -->
                   <!--data是启动图标隐藏应用的关键;注释category了,android:scheme代码就可以注释掉。如果scheme的内容可以随便写,但是和要和a应用中的跳转信息一致-->
                    <data  android:host="MainActivity"  
                      android:scheme="abc"     
                      />
                </intent-filter>
            </activity>
          
        </application>
    
    </manifest>

    现在安装b应用的图标在手机上已经看不见了。

    三、a应用中button增加代码来启动b应用。

    package com.rainwii.main;
    
    import android.net.Uri;
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.ComponentName;
    import android.content.Intent;
    import android.content.pm.PackageManager;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;
    
    public class MainActivity extends Activity {
    Button startappbutton;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            startappbutton= (Button) findViewById(R.id.button1);
            startappbutton.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent intent = new Intent();
    //a应用启动b应用 ComponentName cn = new ComponentName("com.rainwii.message", "com.rainwii.message.MainActivity"); intent.setComponent(cn); Uri uri = Uri.parse("abc");// 此处应与B程序中Data中标签一致
    intent.setData(uri); startActivity(intent); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }

    注释:ComponentName(组件名称)是用来打开其他应用程序中的Activity或服务的。

    用法:

    Intent it=new Intent();
    it.setComponent(new ComponentName(String packageName,String activityName ));
    startActivity(it);

    好了,已经实现了从一个应用启动另一个主界面隐藏图标的应用了。

    ==================================================

    方法二:

     Android 一个app启动另一个app

    [支付宝钱包],可以从支付宝直接跳转到[去啊],如果没有按照还提醒用户是否安装,有点炫酷哦,去啊的用户量一下增多了


    第一个App中

    // 通过包名获取要跳转的app,创建intent对象
                    Intent intent = activity().getPackageManager()
                            .getLaunchIntentForPackage("com.zsl.download");
                    // 这里如果intent为空,就说名没有安装要跳转的应用嘛
                    if (intent != null) {
                        // 这里跟Activity传递参数一样的嘛,不要担心怎么传递参数,还有接收参数也是跟Activity和Activity传参数一样
                        intent.putExtra("name", "郑松岚");
                        startActivity(intent);
                    } else {
                        // 没有安装要跳转的app应用,提醒一下
                        ToastUtils.showLongToast(activity(), "没安装此APP");
                    }

    第二个App中

    Intent intent = getIntent();
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                String name = bundle.getString("name");
                if (name != null) {
                    Toast.makeText(getApplicationContext(), "name:" + name, Toast.LENGTH_SHORT).show();
                }
            }
                              作者:xubuhang                出处:http://www.cnblogs.com/xubuhang/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 

     
  • 相关阅读:
    gitblit.cmd运行自动关闭
    用SourceTree轻松Git项目图解
    GUI for git|SourceTree|入门基础
    SourceTree的简单使用
    Windows平台使用Gitblit搭建Git服务器图文教程
    使用Gitblit 搭建Windows Git服务器
    Git使用详细教程
    Kafka 设计与原理详解
    Kafka 客户端实现逻辑分析
    js判断只能输入数字或小数点
  • 原文地址:https://www.cnblogs.com/xubuhang/p/4133138.html
  • Copyright © 2020-2023  润新知