啊哈条子
2017-02-08 02:43
采纳率: 68.4%
浏览 5.5k

android studio打包APK后安装完成后打开按钮不可点,桌面也无图标,但应用里显示已安装

估计是代码问题,网上down的代码,是不是哪里错了?功能很简单,就一个webview控件,点开应用直接启动,代码如下,求大神查错修改,谢谢。

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
package="com.example.ricky.myapplication">

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name="com.example.ricky.myapplication.MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LUNCHER"/>
        </intent-filter>
    </activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
 App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

MainActivity.java

package com.example.ricky.myapplication;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;

public class MainActivity extends Activity {
private WebView webView;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);
    init();

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}


private void init() {
    webView = (WebView) findViewById(R.id.webView);
    //WebView加载web资源
    webView.loadUrl("http://baidu.com/");
    //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为,使网页用WebView打开
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub
            //返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器
            view.loadUrl(url);
            return true;
        }
    });
}

/**
 * ATTENTION: This was auto-generated to implement the App Indexing API.
 * See https://g.co/AppIndexing/AndroidStudio for more information.
 */
public Action getIndexApiAction() {
    Thing object = new Thing.Builder()
            .setName("Main Page") // TODO: Define a title for the content shown.
            // TODO: Make sure this auto-generated URL is correct.
            .setUrl(Uri.parse("http://baidu.com/"))
            .build();
    return new Action.Builder(Action.TYPE_VIEW)
            .setObject(object)
            .setActionStatus(Action.STATUS_TYPE_COMPLETED)
            .build();
}

@Override
public void onStart() {
    super.onStart();

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    client.connect();
    AppIndex.AppIndexApi.start(client, getIndexApiAction());
}

@Override
public void onStop() {
    super.onStop();

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    AppIndex.AppIndexApi.end(client, getIndexApiAction());
    client.disconnect();
}

}

layout下test.xml

<?xml version="1.0" encoding="utf-8"?>
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"
/>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 喵喵喵爱吃鱼 2017-02-09 03:52
    已采纳

    AndroidManifest中application元素属性设置问题

    属性设置错误

    设置图标为icon,而上面的icon资源文件不存在

    解决方法:添加icon资源文件

    AndroidManifest中 没有activity设置android.intent.category.LAUNCHER category或android.intent.action.MAIN action

    AndroidManifest没有任何activity设置了

    在运行时候你会发现如下提示信息,表示异步执行

    [2012-03-25 ……] No Launcher activity found!

    [2012-03-25 ……] The launch will only sync the application package on the device!

    而程序已经安装在列表中,但并没有图标而且也没有将android.intent.action.MAIN属性的activity执行显示在屏幕最前端。

    解决方法:在主activity中添加这两个属性

    3、main intent-filter同时配置了不同种类的action和data,配置如下:

    [xml] view plain copy














    有网友说这种方式无法启动,但经过自己测试能启动只是不会显示图标而已

    解决方法:分为两个intent-filter,如下

    [xml] view plain copy


















    原因为intent-filter表示activity接受怎样的intent,定义在一个intent-filter中的条件必须都满足才能按照该intent-filter启动,否则按照其他intent-filter启动。而以上明显是两类启动方式,所以必须分开。通过这个介绍可以知道其他的action、category、data冲突也有可能导致这个问题

    点赞 评论
  • devmiao 2017-02-08 20:57
    点赞 评论
  • 喵喵喵爱吃鱼 2017-02-09 03:52
    点赞 评论

相关推荐 更多相似问题