当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Did i include this in Manifest.xml correctly?

问题描述:

I'm trying to let a user press a button so it would vibrate. So i declared it in manifest and i made a new activity for it. Heres some code did i misplace the permissions?

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="android.app"

android:versionCode="1"

android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application

android:icon="@drawable/ic_launcher"

android:label="@string/app_name" >

<activity

android:name=".AndroidActivity"

android:label="@string/app_name"

android:screenOrientation="portrait">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity android:name=".activity2"

android:screenOrientation="portrait"

android:label="@string/app_name" >

</activity>

<activity android:name=".activity3"

android:screenOrientation="portrait"

android:label="@string/app_name" >

</activity>

<activity android:name=".next" >

</activity>

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

</application>

</manifest>

and heres the activity for the button:

package android.app;

import android.app.R;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class AndroidVibrator extends Activity {

protected void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R.layout.main3);

final Button button = (Button) findViewById(R.id.sound);

button.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

// Perform action on click

}

});

}

}

网友答案:

Try the following -:

?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.app"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.VIBRATE"/>

    <application>
     .
     .
     .
    </application
网友答案:

First of all if you are developing in Eclipse use, ctrl+A and then ctrl+I this should correctly manage indentation for you. Returning to your question I hope you do replace names of activity1 and activity2 etc. with what you really have like "AndroidVibrator". And lastly it should make no difference where you place the permissions although it is a better practice to have them at the top , between uses-sdk and application.

Also I see you are using android:screenOrientation="portrait", if you want your activity not to react to screen orientation changes then add that too: android:configChanges="orientation|keyboardHidden|keyboard"

And add that to your activity class:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: