What I am attempting to do is to open "Items" when the ImageButton "ibItem1" is pressed. But, after setting up this:
ibItem1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent items = new Intent("android.intent.action.ITEMS");
startActivity(items);
}
});
And clicking the button does not do anything. I have the activity all set up in the manifest:
<activity
android:name="com.example.custombuilds.Items"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.ITEMS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The program has crashed before because of a ActivityNotFoundException, even though I declared it in the manifest.
Intent myIntent = new Intent(this, NextActivity.class);
startActivity(myIntent);
In this form, it should work..
Also make sure that the name of the class that implements the activity is the same in the manifest file at the android:name="atributevalue".The attribute value should be a fully qualified class name.
Related
I have that vulnerability according to google play console.
It's supposed that the solution is to add .setPackage() or .setClassName() to the intent but now the activity is not being recognized. How can I use this function?
The intent as it was with the vulnerability is this:
#Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent("independent.dev.ui.mainactivity");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
The solution that I tried adding the package name:
#Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent("independent.dev.ui.mainactivity");
intent.setPackage("independent.dev.ui.Activities");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
my AndroidManifest.xml is this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="independent.dev.ui.Activities">
.
.
.
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="Menu Principal"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="independent.dev.ui.mainactivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
How can I set the package so I can navigate and delete this vulnerability?
this the first part of the code with the splash screen code
public class MainActivity extends AppCompatActivity {
private static final int SPLASH_TIME_OUT = 1000;
private static final String FILE_NAME = "example.txt";
EditText mEditText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEditText = findViewById(R.id.edit_text);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent homeIntent = new Intent(MainActivity.this, HomeActivity.class);
startActivity(homeIntent);
finish();
}
},SPLASH_TIME_OUT);
the first thing that comes out after i run the app is the main activity and not the splash screen
You have to specify your activity Actions by using Intent Filter ,
Intent Filters specifies the types of intents that an activity, service, or broadcast receiver can respond to. An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.
As in For your Case, You have to specify that MainActivity/SplashActivity should be on Launcher Mode(Launcher mode is an instruction for Android OS which specifies how the activity should be launched), you have to use Intent filter and specify Activity Actions ,
*Must go through this Article App Manifest Overview
Add this in your Manifest file within <Application> Tag
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In your AndroidManifest file, SplashActivity must be set as Launcher activity. Check the name of the Splash screen activity file in your project.
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Can you share your manifest? Launch Activity should be Splash Activity.
Which Activity you want the application to start with, you need to add IntentFilter in that Activity in the Manifest file.
<activity android:name="SplashActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
please help , when i run the app, the app launch a Fatal Error im learning
just i create a instat with a call but not run, (sorry for my english)
.......................................................................
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.octa.appprueba3">
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.APP_CONTACTS" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"></activity>
</application>
</manifest>
my code:
public class SecondActivity extends AppCompatActivity {
private EditText editPhoneText;
private ImageButton imageCallButton;
private final int PHONE_CALL_CODE = 100;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
editPhoneText = (EditText) findViewById(R.id.editTextPhone);
imageCallButton = (ImageButton) findViewById(R.id.imageCallButton1);
imageCallButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
implicito();
}
});
}
public void implicito(){
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("Tel: 9999999" ));
startActivity(intent);
}
}
You may want to check whether your device can handle your intent by doing this:
PackageManager packageManager = getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent);
} else {
Log.d(TAG, "Cannot handle this intent");
}
What's more, if you are placing a call like so, there is NO need to declare the permission in your manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
Because you are not directly calling someone within your app. You are actually transferring the "duty" to other apps which can handle your intent to call. This doesn't need a permission.
To directly make a call within your app, the intent should be Intent.ACTION_CALL, which needs the permission you declared.
Hope this will help.
There is no activity on your device that handles ACTION_DIAL for a Tel: scheme. Try:
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:9999999" ));
Case and whitespace are important when assembling a Uri.
Also note that even my revised Intent will not work on all devices, such as on an Android tablet that lacks a dialer.
Hi everyone I'm studying now and developing a app in android studio. My problem is i can't proceed to my log in activity after splash screen. I already look in the net and stackoverflow and applied it, but still same error. I appreciate for the help and answer.
Here are some of my code
SplashScreen.java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
final Intent mainIntent = new Intent(SplashScreen.this, Login.class);
SplashScreen.this.startActivity(mainIntent);
SplashScreen.this.finish();
}
},3000);
}
Login.java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/logo"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreen"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".Login"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Login"/>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="com.ex.app.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
where did i go wrong ?
As you have written code to move to MainActivity on the method onCreate of Login.java
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
Comment this line or keep it on the click of SignIn button
Your login activity just directs you to the MainActivity on create
Look at these lines
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
It is redirecting to MainActivity directly as in your LoginActivity onCreate you have written
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
without any condition. Make it conditional by putting your login check conditions and criteria
if (<logged_in_your_condition_Check>){
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
}
why you require below lines in Login.class
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
if you are using finish() in onCreate() then it will immediately called onDestroy() and that dosen't make any sense.
remove above given code from onCreate your code will work
in manifest write:
<activity
android:name=".MySplashActivity"
android:noHistory="true"
..... >
....
</activity>
then in create() or somewhere different cal the method:
private static int SPLASH_TIME_OUT=2000;
private void nextScreen() {
new Handler().postDelayed(()-> {
Intent intent = new Intent(MySplashaActivity.this, NextActivity.class);
startActivity(intent);
finish();
}, SPLASH_TIME_OUT);
}
I want to start a new activity called Counter when a button is clicked, but I got an error that is the activity is not found...so where is the wrong in my code:
t = new Thread(){
public void run(){
try{
sleep(5000);
}
catch (InterruptedException e){
e.printStackTrace();
}
finally{
Intent counter = new Intent("com.example.test.Counter");
startActivity(counter);
}
}
};
test.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
t.run();
}
});
this is the manifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.test.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.test.Counter"
android:label="#string/title_activity_counter" >
</activity>
</application>
</manifest>
Intent intent = new Intent(MyActivity.this, OtherActivity.class);
startActivity(intent);
Change this
Intent counter = new Intent("com.example.test.Counter");
startActivity(counter);
This is called implicit intent and it needs intent filter
to
Intent counter = new Intent(MainActivity.this,Counter.class);
startActivity(counter);
This is called explicit intent and there is no need for intent filter
You should use explicit intent coz you have
<activity
android:name="com.example.test.Counter"
android:label="#string/title_activity_counter" >
</activity>
Quoting docs
Explicit intents specify the component to start by name (the
fully-qualified class name). You'll typically use an explicit intent
to start a component in your own app, because you know the class name
of the activity or service you want to start. For example, start a new
activity in response to a user action or start a service to download a
file in the background.
Note: An explicit intent is always delivered to its target, regardless of any intent filters the component declares.
Edit:
You should call start() on the thread not run
You can replace this
Intent counter = new Intent("com.example.test.Counter");
startActivity(counter);
with this, it would work ..
Intent counter = new Intent(MainActivity.this, Counter.class);
startActivity(counter);
Or to let your code work, you are missing intent-filter
<activity
android:name="com.example.test.Counter"
android:label="#string/title_activity_counter" >
<intent-filter>
<action android:name="android.intent.action.COUNTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
You should always provide an intent-filer if you want to start an activity with your way ..
you should have t.start();. That is the function that starts a thread.
You may also want to try running on the UI thread by replacing the contents of your finally block with this:
MyActivity.this.runOnUiThread(new Runnable() {
public void run() {
Intent counter = new Intent(MyActivity.this, Counter.class);
MyActivity.this.startActivity(counter);
}
};
And as others have said, use t.start() instead of t.run() as run() will block any further action until it completes.