I made the second page a menu. I want the second page to open when the apk opens. How can I do this with code? I only need a code
Inside your AndroidManifest.xml file you will have something like this:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And you something like this for other acitivities:
<activity
android:name=".SecondActivity" />
What you need to do is just copy/paste that <intent-filter></intent-filter> tags to the SecondActivity, and you get this:
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and
<activity
android:name=".MainActivity" />
Your code in AndroidManifest.xml file is like following:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"/>
You just have to set the second activity as the launcher of the app, i.e copy/paste <intent-filter> from .MainActivity to .SecondActivity. Like this:
<activity android:name=".MainActivity"/>
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And that's it! Now the second page opens the app.
Related
I've made an NFC application who can reads NFC tag. It works well. (With all types)
But since yesterday i'm trying to start automatically my app once a NFC tag is maintained against my device.
So i've updated my Manifest :
<activity android:name=".MainActivity" android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc_tech_filter" />
</activity>
Then, here is my nfc_tech_filter.xml
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.NfcB</tech>
<tech>android.nfc.tech.NfcF</tech>
<tech>android.nfc.tech.NfcV</tech>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NdefFormatable</tech>
<tech>android.nfc.tech.MifareClassic</tech>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
</resources>
And surprise, it works only when I hold a NFC Type 2 against my device.
I've try with my appartement key (Mifare Classic) and my bank card (IsoDep), and it doesn't launch my app...
I specify that it works when my app is already started.
Any idea?
EDIT :
This is my Manifest right now :
<activity android:name=".MainActivity" android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="#xml/nfc_tech_filter" />
</activity>
Now, when I pass my bank card, it opens the application but doesn't display any result.
Parcelable[] rawMessages =
intent.getParcelableArrayExtra(NfcAdapter.EXTRA_TAG);
rawMessages variable is NULL after that. Same if I put NfcAdapter.EXTRA_NDEF_MESSAGES
ACTION_TAG_DISCOVERED:
This intent is started if no activities handle the ACTION_NDEF_DISCOVERED or ACTION_TECH_DISCOVERED intents.
https://developer.android.com/guide/topics/connectivity/nfc/nfc
You get this Intent when no others has captured it, so there is something wrong in your setup.
You can capture it explicitly like:
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>
I'm new to Android app development so please be patient with me. I'm writing an app that gets the GPS location from Google Play services and then broadcasts the data over Bluetooth. I have a LocationActivity that gets the location, and an AdvertiseActivity that broadcasts the data.
My problem is that I'm having a hard time understanding the file structure in android apps, so I suspect my lack of understanding is why I'm getting the error.
Here is a snippet of LocationActivity where the error is:
#Override
public void onLocationReceived(Location location) {
Intent i = new Intent(LocationActivity.this, AdvertiseActivity.class) //problem is here
.putExtra("latitude", location.getLatitude());
startActivity(i);
}
Why can't the compiler find AdvertiseActivity.class? Is something wrong with my manifest below?
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name="com.android.app.LocationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.android.app.AdvertiseActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Please help. Thanks!
You are using two activities as MAIN .From manifest, Remove:
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.DEFAULT" />
From AdvertiseActivity's activity tag. Hope this helps.
Remove these lines from manifest
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
And keep only this line.
<activity android:name="com.android.app.AdvertiseActivity"/>
An Application can have only one android.intent.action.MAIN in Startup Activity. In your LocationActivity you already defined so remove intent-filter from AdvertiseActivity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
so its like
<activity android:name="com.android.app.AdvertiseActivity"/>
I am new to android so I want to change the starting of the application in android manifest but each time the application is stopped cs worked is that we must change the java codes aussie
here is the xml code:
<application
android:icon="#drawable/icon"
android:label="hello">
<activity
android:name=".activity.ServersActivity"
android:label="#string/app_name"
android:launchMode="standard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.AddServerActivity"
android:label="#string/add_server_label">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="irc"/>
</intent-filter>
</activity>
For setting the starting activity, you'll have to add the following Intent Filter to the activity in your AndroidManifest.xml:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Please note that you should only add this Intent Filter to one of your Activities. Otherwise, you might experience unexpected behaviours.
There is no way to change the starting activity by code.
Cut this line and paste it inside activity tag to whom you want as starting activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
For eg: Making AddServerActivity as stating activity
<activity
android:name=".activity.ServersActivity"
android:label="#string/app_name"
android:launchMode="standard">
</activity>
<activity
android:name=".activity.AddServerActivity"
android:label="#string/add_server_label">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="irc"/>
</intent-filter>
</activity>
I am just learning how to program apps for android, so please bear with me. My original starting activity was called Menu.Java. When I tested the app on my phone, a launcher icon would show up and I could launch the app from it. I decided to add a different Activity for my start up, which is called Login.java. I changed the intents to .MAIN and .LAUNCHER and now my icon won't show up at all. I tried switching it back to the Menu.Java and that worked for a bit (but clicking the icon would load the Menu Activity, and I was wanting the Login Activity loaded), but now that doesn't even work.
EDIT: I have also removed all of the activities from the manifest except the .Login Activity. Did not work.
Here is my Manifest:
`
<application
android:icon="#+drawable/ic_squirrel"
android:label="#string/app_name" >
<activity android:name="com.example.advanced.Login" >
<intent-filter>
<action android:name="com.example.advanced.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.advanced.Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.advanced.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.advanced.Settings"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.advanced.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.advanced.InternalStore"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.advanced.INTERNALSTORE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.advanced.Reading"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.advanced.READING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.advanced.Passing"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.advanced.PASSING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.advanced.Numbers"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.advanced.NUMBERS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
`
<activity android:name="com.example.advanced.Login" >
<intent-filter>
<action android:name="com.example.advanced.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Here change the <intent-filter> to
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
When I specify the .main class as the launcher, it crashes on launch. So I made a new activity called launch that will be used to open the .main class. When I specify .launch as the LAUNCHER, the console tells me that no launcher activity was found.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.homework"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<application android:label="#string/app_name"
android:theme="#style/AppTheme"
android:allowBackup="true">
<activity android:name=".launch"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.LAUNCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".menu"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".list"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.LIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Change
<intent-filter>
<action android:name="android.intent.action.LAUNCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
to
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Well, does the com.my.homework.launch class exist? Does it subclass Activity? Also, the action should still be <action android:name="android.intent.action.MAIN" />.