Receiving No apps can perform this actions error - android

I am attempting to get my app to offer me a choice of what browser to use. I have assigned the URL to http://google.com. When I run it, I get a 'No apps can perform this actions' error. I'm missing something and i cant figure it out.
public class myClass{
static private final String URL = "http://www.google.com";
..
..
implicitActivationButton.setOnClickListener(new OnClickListener() {
// Call startImplicitActivation() when pressed
#Override
public void onClick(View v) {
startImplicitActivation();
}
});
private void startImplicitActivation() {
Log.i(TAG, "Entered startImplicitActivation()");
Intent baseIntent = new Intent(Intent.ACTION_SEND,Uri.parse(URL));
String title = "Choose Browser";
Intent chooserIntent = Intent.createChooser(baseIntent, title);
Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
startActivity(chooserIntent);
}
...
...
}

To view a Web page, use ACTION_VIEW, not ACTION_SEND.

Related

How to use correct intents for a WebView on vulnerable intent scheme hijacking

I have this WebView in which I open a page that has links to open whatsapp, messenger and phone call which would not open if it was not in a browser.
Google obviously did not like it and says I have to skip this part.
Is there any way to get rid of this?
The original code is the commented, on that my app is opened on a web navigator and I don't want it. so I used the intent scheme to open any link on the page.
public class MainActivity extends AppCompatActivity {
WebView wv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = findViewById(R.id.web);
wv.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
/* if (url.startsWith("tel:") || url.startsWith("whatsapp:") || url.startsWith("intent")){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
//view.reload();
return true;
}
view.loadUrl(url);
return true;*/
/* if (url.startsWith("http:") || url.startsWith("https:")) {
return false;
}
//agregar validacion para email, telefono y whatsapp
if(url.startsWith("tel://")|| url.startsWith("mailto://")|| url.startsWith("whatsapp://")){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}*/
if (url.startsWith("http")) return false;//open web links as usual
//try to find browse activity to handle uri
Uri parsedUri = Uri.parse(url);
PackageManager packageManager = getApplicationContext().getPackageManager();
Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri);
if (browseIntent.resolveActivity(packageManager) != null) {
getApplicationContext().startActivity(browseIntent);
return true;
}
//if not activity found, try to parse intent://
if (url.startsWith("intent:")) {
try {
Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
if (intent.resolveActivity(getApplicationContext().getPackageManager()) != null) {
getApplicationContext().startActivity(intent);
return true;
}
//try to find fallback url
String fallbackUrl = intent.getStringExtra("browser_fallback_url");
if (fallbackUrl != null) {
wv.loadUrl(fallbackUrl);
return true;
}
//invite to install
Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(
Uri.parse("market://details?id=" + intent.getPackage()));
if (marketIntent.resolveActivity(packageManager) != null) {
getApplicationContext().startActivity(marketIntent);
return true;
}
} catch (URISyntaxException e) {
//not an intent uri
}
}
return true;
}
});
wv.getSettings().setJavaScriptEnabled(true);
// wv.getSettings().setLoadWithOverviewMode(true);
wv.loadUrl("http://www.saborasonoyta.com");
}
protected void showAppExitDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("POR FAVOR, CONFIRME");
builder.setMessage("desea salir de la aplicación?");
builder.setCancelable(true);
builder.setPositiveButton("Si", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
// Do something when user want to exit the app
// Let allow the system to handle the event, such as exit the app
MainActivity.super.onBackPressed();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
// Do something when want to stay in the app
Toast.makeText(getApplicationContext(),"Gracias",Toast.LENGTH_LONG).show();
}
});
// Create the alert dialog using alert dialog builder
AlertDialog dialog = builder.create();
// Finally, display the dialog when user press back button
dialog.show();
}
#Override
public void onBackPressed(){
if(wv.canGoBack()){
// If web view have back history, then go to the web view back history
wv.goBack();
}else {
// Ask the user to exit the app or stay in here
showAppExitDialog();
}
}
}
try to add this.
Apps can constrain Intents constructed with Intent.parseUri to only be sent as Implicit Intents to components with BROWSABLE Intent Filters using the following code:
// convert Intent scheme URL to Intent object
Intent intent = Intent.parseUri(url);
// forbid launching activities without BROWSABLE category
intent.addCategory("android.intent.category.BROWSABLE");
// forbid explicit call
intent.setComponent(null);
// forbid Intent with selector Intent
intent.setSelector(null);
// start the activity by the Intent
view.getContext().startActivity(intent, -1);

How to implement email intent correctly

I searched stack overflow and the google documentation for email intents and found that code to be the go to code:
However, everytime I click "submit" in my activity I choose gmail. It opens a new email in gmail, but it only puts the receipient address. The subject and the text(name, email address and feedback text) are missing.
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
I implemented that as the following code. Everything after the else is to have a AlertDialog pop up if there is no app installed.
public class EmailActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acitvity_email);
final EditText nameField = (EditText) findViewById(R.id.editTextName);
final EditText addressField = (EditText) findViewById(R.id.editTextEmail);
final EditText subjectField = (EditText) findViewById(R.id.editTextSubject);
final EditText feedbackField = (EditText) findViewById(R.id.editTextFeedback);
final Button submitFeedback = (Button) findViewById(R.id.buttonSubmitFeedback);
final String name = nameField.getText().toString();
final String address = addressField.getText().toString();
final String subject = subjectField.getText().toString();
final String feedback = feedbackField.getText().toString().concat(name).concat(address);
submitFeedback.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
composeFeedback(subject, feedback);
}
});
}
public void composeFeedback(String subject, String feedback){
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:" + "mydeveloperemail#gmail.com"));
intent.putExtra(Intent.EXTRA_TEXT,feedback);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
final Drawable fail = getResources().getDrawable(R.drawable.ic_fail);
AlertDialog.Builder builder = new AlertDialog.Builder(EmailActivity.this);
builder.setTitle("Fehler");
builder.setIcon(fail);
builder.setMessage("Keine Email App verfügbar!");
builder.setCancelable(false);
builder.setNeutralButton("Okay", new DialogInterface.OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
Edit: deleted intent filter as #CommonsWare pointed out in his answer
ACTION_SENDTO is not required to use any extras. Put your data in the mailto: Uri, the way a Web page would.
In the android manifest i declared an intent filter to the activtiy
Unless you are writing an email app, like Gmail, this <intent-filter> is both unnecessary and damaging to users.

Using other app to send message to line app

I try the following code to send messages to line app. It works; however, before I send message,it will move to the line friends page and I have to choose friends whom I want to send the messages to. How could I modify the code that I could choose friends at code instead of choosing friends manually.
public class MainActivity extends AppCompatActivity {
static final int REQUEST_ACTION_PICK = 1;
public static final String PACKAGE_NAME = "jp.naver.line.android";
public static final String CLASS_NAME = "jp.naver.line.android.activity.selectchat.SelectChatActivity";
private List<ApplicationInfo> m_appList;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sendTextHandler(this);
}
public void sendTextHandler(MainActivity view) {
String sendText = ((TextView)findViewById(R.id.send_text)).getText().toString();
if(checkLineInstalled()){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName(PACKAGE_NAME, CLASS_NAME);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, sendText);
startActivity(intent);
}else{
Toast toast = Toast.makeText(this, "LINEがインストールされていません", Toast.LENGTH_SHORT);
toast.show();
}
}
private boolean checkLineInstalled(){
PackageManager pm = getPackageManager();
m_appList = pm.getInstalledApplications(0);
boolean lineInstallFlag = false;
for (ApplicationInfo ai : m_appList) {
if(ai.packageName.equals(PACKAGE_NAME)){
lineInstallFlag = true;
break;
}
}
return lineInstallFlag;
}
}
The code is from https://gist.github.com/ekos/3993270.
If you want to be able to open a specific user based on the ID you can do the following:
String userId = findUserId();
String sendText = "line://ti/p/~" + userId;
Intent intent = null;
try {
intent = Intent.parseUri(sendText, Intent.URI_INTENT_SCHEME);
} catch (URISyntaxException e) {
e.printStackTrace();
}
startActivity(intent);
If you want to make a message and then be able to choose who to send it to you can use the following:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("line://msg/text/" + getMessage()));
startActivity(intent);

Upload Image on Flickr with android

i need to integrate Flickr with android. I am done with authentication.i need to upload image to flickr but i am unaware how to do same.
i refer document : http://www.flickr.com/services/api/upload.api.html for the same.
Can anybody help me
//change your key and secreat key
private static final String API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //$NON-NLS-1$
public static final String API_SEC = "xxxxxxxxxxxxx"; //$NON-NLS-1$
View.OnClickListener mFlickrClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
if (fileUri == null) {
Toast.makeText(getApplicationContext(), "Please pick photo",
Toast.LENGTH_SHORT).show();
return;
}
Intent intent = new Intent(getApplicationContext(),
FlickrjActivity.class);
intent.putExtra("flickImagePath", fileUri.getAbsolutePath());
startActivity(intent);
}
};

Launch SMS using data from a scanned QR Code

I'm trying to start the SMS activity with the phone number from a scanned QR Code filled in. So far I've been able to get the activity to launch but the number and message fields are blank. Here's what I have, currently this is crashing the app:
else if(resultType.getParsedResultType() == ParsedResultType.SMS){
Button smsButton = (Button)findViewById(R.id.btn_send_sms);
smsButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v){
String smsUri = ResultsActivity.this.item.getContent();
Uri uri = Uri.parse(smsUri);
Intent i = new Intent(Intent.ACTION_VIEW);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setType("vnd.android-dir/mms-sms");
i.setData(uri);
startActivity(i);
}
});
smsButton.setVisibility(View.VISIBLE);
}
The String smsUri contains the scanned string from the QR Code, "SMSTO:666-666-1234:hello". How can I get the SMS Activity to launch with the phone number and the message already entered into the number and body fields?
I saw this post:
Sending SMS using Intent does not add recipients on some devices
Would I need to parse the QR Code result myself and break it into the phone number and message, then add those as Extras like that example?
Got it!
Since I can't answer my own question yet here it is:
Okay, got it to work. I made a class to break the QR result into separate elements:
public class Sms {
public static String[] breakString(String s) {
String[] smsElements = s.split(":");
return smsElements;
}
}
Then changed the method I have above to:
else if(resultType.getParsedResultType() == ParsedResultType.SMS){
Button smsButton = (Button)findViewById(R.id.btn_send_sms);
smsButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v){
String smsUri = ResultsActivity.this.item.getContent();
String[] smsElements = Sms.breakString(smsUri);
Intent i = new Intent(Intent.ACTION_VIEW);
i.putExtra("address", smsElements[1]);
i.putExtra("sms_body", smsElements[2]);
i.setData(Uri.parse("smsto:" + smsElements[1]));
startActivity(i);
}
});
smsButton.setVisibility(View.VISIBLE);
}
Okay, got it to work. I made a class to break the QR result into separate elements:
public class Sms {
public static String[] breakString(String s) {
String[] smsElements = s.split(":");
return smsElements;
}
}
Then changed the method I have above to:
else if(resultType.getParsedResultType() == ParsedResultType.SMS){
Button smsButton = (Button)findViewById(R.id.btn_send_sms);
smsButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v){
String smsUri = ResultsActivity.this.item.getContent();
String[] smsElements = Sms.breakString(smsUri);
Intent i = new Intent(Intent.ACTION_VIEW);
i.putExtra("address", smsElements[1]);
i.putExtra("sms_body", smsElements[2]);
i.setData(Uri.parse("smsto:" + smsElements[1]));
startActivity(i);
}
});
smsButton.setVisibility(View.VISIBLE);
}

Categories

Resources