i wan currently developing an app for android, but.. There is an activity of mine, in which the user shall click on a button and it would open the Android Terminal EMulator which would have been installed on the user device, but right now, i have an issue, my codes are not working.. check it out
ClockWorkModFlash.java
package com.loadedgeek.myupgrade;
import android.os.Bundle; import android.app.Activity; import
android.os.Handler; import android.content.Intent; import
android.widget.Button; import android.view.View;
public class ClockWorkModFlash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.clockworkmod_activate);
Button bClock = (Button) findViewById(R.id.FlashClockWork);
bClock.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager managerclock = getPackageManager();
i = managerclock.getLaunchIntentForPackage(jackpal.androidterm);
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}
});
}}
The Eclipse is not allowing me compile the app, as that is the last activity, it says Packagemanager and OnClickListner could not be resolved... any ideas?
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(ComponentName.unflattenFromString("application Package name /application launcher activity name"));
intent.addCategory("android.intent.category.LAUNCHER");
startActivity(intent);
PackageManager managerclock = getPackageManager();
Intent i = managerclock.getLaunchIntentForPackage(jackpal.androidterm);
i.addAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
or
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(ComponentName.unflattenFromString("jackpal.androidterm");
intent.addCategory("android.intent.category.LAUNCHER");
startActivity(intent);
by the way,your error "Packagemanager and OnClickListner could not be resolved", I guess that you can change the code from:
bClock.setOnClickListener(new OnClickListener() {…}
to:
bClock.setOnClickListener(new View.OnClickListener() {…}
Related
My Application is a simple CSV Viewer and i want to read File path when someone opens a CSV file using my App.
I tried below code but it's giving me error as -----------------------------------------------------------------------------.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String _file = intent.getData().toString();
Log.d("INFO",_file);
}
}
Sending Activity:
Intent intent = new Intent(context, MyActivity.class);
intent.putExtra("imagePath", pathToImage);
startActivity(intent);
Receiving Activity:
String path = getIntent().getStringExtra("imagePath");
Intent intent = new Intent(context, SecondActivity.class);
intent.putExtra("filePath", file.getAbsolutePath());
startActivity(intent);
in MyActivity.class
String path = getIntent().getStringExtra("filePath");
File file=new File(path);
I am not sure what I have done but for a moment my code was working smoothly and after I added a new activity the error Attempted to finish an input event but the input event receiver has already been disposed.
I need help on how to fix this.
package proj.com.desperationfinals;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText editText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText);
}
public void validate (View view){
String word = editText.getText().toString();
if(word.contentEquals("Sir Zalameda")) {
AlertDialog.Builder Alert = new AlertDialog.Builder(this);
Alert.setMessage("Correct!")
.create();
Alert.show();
Intent i = new Intent(MainActivity.this, Main2Activity.class);
startActivity(i);
}else{
AlertDialog.Builder Alert = new AlertDialog.Builder(this);
Alert.setMessage("Mali!")
.create();
Alert.show();
}
}
}
The problem is in the following section:
AlertDialog.Builder Alert = new AlertDialog.Builder(this);
Alert.setMessage("Correct!")
.create();
Alert.show();
Intent i = new Intent(MainActivity.this, Main2Activity.class);
startActivity(i);
You are getting the error because you are trying to show an alert right before starting a new activity. Now, the 'receiver' for the dialog is the current activity and as soon as you start new activity that is switched. To tackle this problem you can try something like this:
Alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent i = new Intent(MainActivity.this, Main2Activity.class);
startActivity(i);
}
TL;DR: Can't show an alert right before starting a new activity.
I'm trying to make facebook for "someone" else opens on application, not on a browser, for example National Geography https://www.facebook.com/natgeo
Here is the code I have:
ddc.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/natgeo"));
startActivity(browserIntent);
}
});
I found one on stackoverflow and I tried it and it has errors, here is the code:
try {
//try to open page in facebook native app.
String uri = "fb://page/" + natgeo; //Custom URL
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}
catch (ActivityNotFoundException ex){
//facebook native app isn't available, use browser.
String uri = "https://www.facebook.com/natgeo" + natgeo; //Normal URL
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uriMobile));
startActivity(i);
}
the thing is I want, if someone didn't have facebook App, it will open in the browser.
Edited
package fa;
import com.f.fa.R;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
Button ddc;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_item);
addListenerOnButton();
}
public void addListenerOnButton() {
ddc = (Button) findViewById(R.id.ddc);
try {
//try to open page in facebook native app.
String uri = "fb://page/" + natgeo; //Custom URL
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}
catch (ActivityNotFoundException ex){
//facebook native app isn't available, use browser.
String uri = "https://www.facebook.com/natgeo" + natgeo; //Normal URL
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
}
}
}
You use a variable, which is not declared before (read compiler errors)..
Add String natgeo = "my content"; before your try-catch block to make your code compiling.
I am working on a app that when you swipe up on the home button the app opens. I have everything else done bet the code to accomplish the open on swipe up on home button part. How do I do this?
Any help would be amazing.
Here's my java code if needed:
package com.d4a.toolbelt;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class QuickLaunch extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quick_launch);
}
/** Called when the user clicks the music button */
public void music(View view) {
Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");
startActivity(intent);
}
/** Called when the user clicks the play button */
public void play(View view) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");
startActivity(launchIntent);
}
/** Called when the user clicks the web button */
public void web(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com/"));
startActivity(browserIntent);
}
/** Called when the user clicks the email button */
public void email(View view) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.email");
startActivity(intent);
}
/** Called when the user clicks the sms button */
public void chat(View view) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.d4a.sms","de.ub0r.android.smsdroid.ConversationListActivity"));
intent.putExtra("grace", "Hi");
startActivity(intent);
}
/** Called when the user clicks the settings button */
public void settings(View view) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.settings");
startActivity(intent);
}
/** Called when the user clicks the camara button */
public void cam(View view) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);
}
/** Called when the user clicks the video camara button */
public void video_cam(View view) {
Intent intent = new Intent("android.media.action.VIDEO_CAPTURE");
startActivityForResult(intent, 0);
}
}
Thanks a million in advance guys!
I figured it out you need this line of code in the manifest:
<intent-filter>
<action android:name="android.intent.action.ASSIST" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
Thanks to home launcher being open source I got my answer I hope this helps out anyone else who is in my shoes
My code:
package elf.app;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import elf.app.entity.ELFList;
import elf.app.entity.Entry;
import elf.app.test.FakeComm;
// TODO Kunna skicka att något är färdigt (ett rum är städat).
public class RoomListActivity extends ListActivity {
private ELFList eList;
// private FakeComm fakecomm;
private Bundle extras;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.extras = getIntent().getExtras();
eList = new ELFList();
// fakecomm = new FakeComm();
// eList.add(fakecomm.getData());
String[] strArr = {"asd","sdf","dfg"};
eList.add(strArr);
String[] str = eList.returnNames();
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, str));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Entry e = eList.getEntry(position);
String roominfo = e.toString();
Intent intent = new Intent(this, RoomInfoActivity.class);
intent.putExtra("entry",roominfo);
this.startActivity(intent);
// old stuff
// String message;
// message = eList.getEntryInfo(position);
// Toast.makeText(getApplicationContext(),
// message, Toast.LENGTH_SHORT).show();
}
});
}
}
I'm getting errors at the following lines:
Intent intent = new Intent(this, RoomInfoActivity.class);
and
this.startActivity(intent);
I don't have much of a clue why I get these errors, the exact output in the editor for these errors are:
"The constructor Intent(new AdapterView.OnItemClickListener(){}, Class ) is undefined"
"The method startActivity(Intent) is undefined for the type new AdapterView.OnItemClickListener(){}"
I'm an Android newbie so please take that into consideration, however I have studied Java for about a year.
Fix
Intent intent = new Intent(this, RoomInfoActivity.class);
to
Intent intent = new Intent(RoomListActivity.this, RoomInfoActivity.class);
The error is because by this you refer to OnClickListener. The problem is fixed, if you refer to the Activity's this. The second error is the same - wrong reference. Just remove this, and startActivity() method will be searched within the enclosing class too.
try this
Intent intent = new Intent(RoomListActivity.this, RoomInfoActivity.class);
intent.putExtra("entry",roominfo);
RoomListActivity.this.startActivity(intent);